pub struct Checkpoint {
pub version: u32,
pub metadata: CheckpointMetadata,
pub tensors: Vec<CheckpointTensor>,
}Expand description
A serialized model checkpoint containing metadata and named tensors.
Fields§
§version: u32Format version (always 1 for new checkpoints).
metadata: CheckpointMetadataArbitrary key-value metadata (e.g. step, loss, lr).
tensors: Vec<CheckpointTensor>Ordered list of tensor entries.
Implementations§
Source§impl Checkpoint
impl Checkpoint
Sourcepub fn add_tensor(&mut self, tensor: CheckpointTensor)
pub fn add_tensor(&mut self, tensor: CheckpointTensor)
Append a tensor to the checkpoint.
Sourcepub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)
Insert or replace a metadata key-value pair.
Sourcepub fn get_metadata(&self, key: &str) -> Option<&str>
pub fn get_metadata(&self, key: &str) -> Option<&str>
Look up a metadata value by key.
Sourcepub fn get_tensor(&self, name: &str) -> Option<&CheckpointTensor>
pub fn get_tensor(&self, name: &str) -> Option<&CheckpointTensor>
Find a tensor by name (linear scan; checkpoints are small).
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Total bytes occupied by all tensor data (sum of size_bytes()).
Sourcepub fn num_params(&self) -> u64
pub fn num_params(&self) -> u64
Total number of f32 parameters across all tensors.
Sourcepub fn save(&self, path: &Path) -> Result<(), CheckpointError>
pub fn save(&self, path: &Path) -> Result<(), CheckpointError>
Save the checkpoint to path, creating or truncating the file.
Sourcepub fn load(path: &Path) -> Result<Self, CheckpointError>
pub fn load(path: &Path) -> Result<Self, CheckpointError>
Load a checkpoint from path.
Trait Implementations§
Source§impl Debug for Checkpoint
impl Debug for Checkpoint
Auto Trait Implementations§
impl Freeze for Checkpoint
impl RefUnwindSafe for Checkpoint
impl Send for Checkpoint
impl Sync for Checkpoint
impl Unpin for Checkpoint
impl UnsafeUnpin for Checkpoint
impl UnwindSafe for Checkpoint
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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