Struct candle_nn::var_map::VarMap

source ·
pub struct VarMap { /* private fields */ }
Expand description

A VarMap is a store that holds named variables. Variables can be retrieved from the stores and new variables can be added by providing some initialization config in case they are missing. VarMap structures can be serialized in the safetensors format.

Implementations§

source§

impl VarMap

source

pub fn new() -> Self

Create a new empty VarMap.

source

pub fn all_vars(&self) -> Vec<Var>

Retrieve all the variables currently stored in the map.

source

pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save the map in the safetensors format.

source

pub fn load<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Load some values from a safetensors file and modify the existing variables to have these values.

Note that values for variables that are currently not in the map are not kept.

source

pub fn set_one<K: AsRef<str>, V: AsRef<Tensor>>( &mut self, name: K, value: V ) -> Result<()>

Set a named variable to some value.

source

pub fn set<I: Iterator<Item = (K, V)>, K: AsRef<str>, V: AsRef<Tensor>>( &mut self, iter: I ) -> Result<()>

Set some named variables to some values.

If an error is returned, some of the variables might have already been set to their new values.

source

pub fn get<S: Into<Shape>>( &self, shape: S, path: &str, init: Init, dtype: DType, device: &Device ) -> Result<Tensor>

Retrieve or add a new variable.

source

pub fn data(&self) -> &Mutex<HashMap<String, Var>>

Trait Implementations§

source§

impl Clone for VarMap

source§

fn clone(&self) -> VarMap

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 SimpleBackend for VarMap

source§

fn get( &self, s: Shape, name: &str, h: Init, dtype: DType, dev: &Device ) -> Result<Tensor>

Retrieve a tensor based on a target name and shape.
source§

fn contains_tensor(&self, name: &str) -> bool

Auto Trait Implementations§

§

impl Freeze for VarMap

§

impl RefUnwindSafe for VarMap

§

impl Send for VarMap

§

impl Sync for VarMap

§

impl Unpin for VarMap

§

impl UnwindSafe for VarMap

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> 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> 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> 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,