Struct burn_import::pytorch::LoadArgs

source ·
pub struct LoadArgs {
    pub file: PathBuf,
    pub key_remap: Vec<(Regex, String)>,
    pub top_level_key: Option<String>,
    pub debug: bool,
}
Expand description

Arguments for loading a PyTorch file.

§Fields

  • file - The path to the file to load.
  • key_remap - A vector of tuples containing a regular expression and a replacement string. See regex::Regex::replace for more information.

§Notes

Use Netron to inspect the keys of the PyTorch file (.pt extension).

§Examples

use burn_import::pytorch::{LoadArgs, PyTorchFileRecorder};
use burn::record::FullPrecisionSettings;
use burn::record::Recorder;

let args = LoadArgs::new("tests/key_remap/key_remap.pt".into())
   .with_key_remap("conv\\.(.*)", "$1"); // // Remove "conv" prefix, e.g. "conv.conv1" -> "conv1"

let record = PyTorchFileRecorder::<FullPrecisionSettings>::default()
  .load(args)
  .expect("Should decode state successfully");

Fields§

§file: PathBuf

The path to the file to load.

§key_remap: Vec<(Regex, String)>

A list of key remappings.

§top_level_key: Option<String>

Top-level key to load state_dict from the file. Sometimes the state_dict is nested under a top-level key in a dict.

§debug: bool

Whether to print debug information.

Implementations§

source§

impl LoadArgs

source

pub fn new(file: PathBuf) -> Self

Creates a new LoadArgs instance.

§Arguments
  • file - The path to the file to load.
source

pub fn with_key_remap(self, pattern: &str, replacement: &str) -> Self

Sets key remapping.

§Arguments
  • pattern - The Regex pattern to be replaced.
  • replacement - The pattern to replace with.

See Regex for the pattern syntax and Replacement for the replacement syntax.

source

pub fn with_top_level_key(self, key: &str) -> Self

Sets the top-level key to load state_dict from the file. Sometimes the state_dict is nested under a top-level key in a dict.

§Arguments
  • key - The top-level key to load state_dict from the file.
source

pub fn with_debug_print(self) -> Self

Sets printing debug information on.

Trait Implementations§

source§

impl Clone for LoadArgs

source§

fn clone(&self) -> LoadArgs

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LoadArgs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&str> for LoadArgs

source§

fn from(val: &str) -> Self

Converts to this type from the input type.
source§

impl From<PathBuf> for LoadArgs

source§

fn from(val: PathBuf) -> Self

Converts to this type from the input type.
source§

impl From<String> for LoadArgs

source§

fn from(val: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> ErasedDestructor for T
where T: 'static,