Struct ModuleRecord
pub struct ModuleRecord { /* private fields */ }Expand description
A non-generic record holding a module’s parameters.
Obtain one from a module with Module::into_record, then either save it
(save with std enabled / into_bytes) or apply it back with
Module::load_record. Load-time behavior is
configured with the builder methods; they are ignored when saving.
The save-side dtype is intentionally not configurable: use module.cast(dtype) before
taking the record. The record stores whatever dtype the module currently holds.
Implementations§
§impl ModuleRecord
impl ModuleRecord
pub fn with_dtype_policy(self, policy: DTypePolicy) -> ModuleRecord
pub fn with_dtype_policy(self, policy: DTypePolicy) -> ModuleRecord
Set the dtype policy used when loading into a module.
pub fn cast_to_module_dtype(self) -> ModuleRecord
pub fn cast_to_module_dtype(self) -> ModuleRecord
Cast the record’s data to the module parameter dtypes on load.
Sugar for with_dtype_policy(DTypePolicy::CastToModule).
pub fn allow_partial(self, allow: bool) -> ModuleRecord
pub fn allow_partial(self, allow: bool) -> ModuleRecord
Allow loading even when some module parameters are absent from the record.
What a record of a part of a module needs — one taken with
into_record_group, say — since it holds
nothing for the parameters outside that part.
pub fn allow_unused(self, allow: bool) -> ModuleRecord
pub fn allow_unused(self, allow: bool) -> ModuleRecord
Allow loading even when the record holds tensors no module parameter matches.
The mirror of allow_partial, and refused by default: a record
entry that lands nowhere means the module is not the one the record was taken from, and
the load that looks like it succeeded has quietly done less than it was asked — or, at
allow_partial(true), nothing at all. Allow it for the deliberate case, loading a
checkpoint into a part of the module it came from.
pub fn validate(self, validate: bool) -> ModuleRecord
pub fn validate(self, validate: bool) -> ModuleRecord
Enable or disable validation while loading.
pub fn into_bytes(self) -> Result<Bytes, RecordError>
pub fn into_bytes(self) -> Result<Bytes, RecordError>
Serialize the record to an in-memory burnpack byte buffer.
pub fn from_bytes(bytes: Bytes) -> Result<ModuleRecord, RecordError>
pub fn from_bytes(bytes: Bytes) -> Result<ModuleRecord, RecordError>
Reconstruct a record from an in-memory burnpack byte buffer.
pub fn save<P>(self, path: P) -> Result<(), RecordError>
pub fn save<P>(self, path: P) -> Result<(), RecordError>
Save the record to a burnpack file on disk.
pub fn load<P>(path: P) -> Result<ModuleRecord, RecordError>
pub fn load<P>(path: P) -> Result<ModuleRecord, RecordError>
Load a record from a burnpack file on disk.
Trait Implementations§
§impl Checkpoint for ModuleRecord
impl Checkpoint for ModuleRecord
§fn load(path: PathBuf) -> Result<ModuleRecord, CheckpointerError>
fn load(path: PathBuf) -> Result<ModuleRecord, CheckpointerError>
path.§fn checkpoint_into_bytes(self) -> Result<Bytes, RecordError>
fn checkpoint_into_bytes(self) -> Result<Bytes, RecordError>
§fn checkpoint_from_bytes(bytes: Bytes) -> Result<ModuleRecord, RecordError>
fn checkpoint_from_bytes(bytes: Bytes) -> Result<ModuleRecord, RecordError>
§impl Clone for ModuleRecord
impl Clone for ModuleRecord
§fn clone(&self) -> ModuleRecord
fn clone(&self) -> ModuleRecord
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ModuleRecord
impl !UnwindSafe for ModuleRecord
impl Freeze for ModuleRecord
impl Send for ModuleRecord
impl Sync for ModuleRecord
impl Unpin for ModuleRecord
impl UnsafeUnpin for ModuleRecord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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