Struct tch::nn::VarStore

source · []
pub struct VarStore {
    pub variables_: Arc<Mutex<Variables>>,
    /* private fields */
}
Expand description

A VarStore is used to store variables used by one or multiple layers. It specifies a single device where all variables are stored.

Fields

variables_: Arc<Mutex<Variables>>

Implementations

Creates a new var-store located on the specified device.

Gets the device for this var-store.

Returns the number of tensors currently stored on this var-store.

Returns true if no tensors are currently stored on this var-store.

Returns all the trainable variables for this var-store.

Returns all variables along with their names.

Gets the root path for this variable store.

Variables are named and organized using paths. This function returns the top level path for the var store and can be combined with ‘/’ to create sub-paths.

Saves the var-store variable values to a file.

Weight values for all the tensors currently stored in the var-store are saved in the given file.

Saves the var-store variable values to a stream.

Weight values for all the tensors currently stored in the var-store gets saved in the given stream.

Loads the var-store variable values from a file.

Weight values for all the tensors currently stored in the var-store are loaded from the given file. Note that the set of variables stored in the var-store is not changed, only the values for these tensors are modified.

Loads the var-store variable values from a stream.

Weight values for all the tensors currently stored in the var-store gets loaded from the given stream. Note that the set of variables stored in the var-store is not changed, only the values for these tensors are modified.

Loads the var-store variable values from a file if it exists.

Weight values for the tensors currently stored in the var-store and the given file get loaded from the given file. If a variable in the var store is not present in the given file, it is skipped and its values are not updated. This method should be used if pre-trained weight for only parts of the model are available. Note that the set of variables stored in the var-store is not changed, only the values for these tensors are modified.

Returns a String Vector containing the names of missing variables.

Freezes a var store.

Gradients for the variables in this store are not tracked anymore.

Unfreezes a var store.

Gradients for the variables in this store are tracked again.

Casts all variables in a var store to the target kind .

For floating-point conversion, methods half, bfloat16, float and double should be preferred as they ensure only float-like variables will be converted to the target type.

Casts all float-like variable of a var store to half-precision (Half kind).

Casts all float-like variable of a var store to bfloat16-precision (BFloat16 kind).

Casts all float-like variable of a var store to single-precision (Float kind).

Casts all float-like variable of a var store to single-precision (Double kind).

Migrates a var store and all its tensor to a target device.

Copies variable values from a source var store to this var store.

All the variables in this var store have to exist with the same name in the source var store, otherwise an error is returned.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.