pub struct PyTorchCheckpoint {
pub state_dict: StateDict,
pub optimizer_state: Option<OptimizerState>,
pub epoch: Option<usize>,
pub loss_history: Option<Vec<f32>>,
pub metadata: HashMap<String, String>,
}Expand description
PyTorch checkpoint structure.
Contains the model state_dict and optional optimizer state, epoch information, and other training metadata commonly saved in PyTorch checkpoints.
Fields§
§state_dict: StateDictModel state dictionary
optimizer_state: Option<OptimizerState>Optimizer state (if saved)
epoch: Option<usize>Training epoch (if saved)
loss_history: Option<Vec<f32>>Training loss history (if saved)
metadata: HashMap<String, String>Custom metadata
Implementations§
Source§impl PyTorchCheckpoint
impl PyTorchCheckpoint
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
Load a PyTorch checkpoint from a file.
§Security Note
This uses pickle deserialization which can be unsafe with untrusted files. Only load checkpoints from trusted sources.
Sourcepub fn metadata(&self) -> CheckpointMetadata
pub fn metadata(&self) -> CheckpointMetadata
Get checkpoint metadata.
Sourcepub fn state_dict(&self) -> &StateDict
pub fn state_dict(&self) -> &StateDict
Get reference to state dict.
Sourcepub fn to_safetensors(&self) -> Result<Vec<u8>>
pub fn to_safetensors(&self) -> Result<Vec<u8>>
Convert checkpoint to Safetensors format.
This provides a safe, efficient format for storing model weights.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save checkpoint in PyTorch format.
Note: This creates a simplified pickle format compatible with PyTorch.
Sourcepub fn add_tensor(&mut self, name: String, tensor: TensorData)
pub fn add_tensor(&mut self, name: String, tensor: TensorData)
Add a tensor to the state dict.
Sourcepub fn add_metadata(&mut self, key: String, value: String)
pub fn add_metadata(&mut self, key: String, value: String)
Add metadata entry.
Trait Implementations§
Source§impl Clone for PyTorchCheckpoint
impl Clone for PyTorchCheckpoint
Source§fn clone(&self) -> PyTorchCheckpoint
fn clone(&self) -> PyTorchCheckpoint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PyTorchCheckpoint
impl Debug for PyTorchCheckpoint
Source§impl Default for PyTorchCheckpoint
impl Default for PyTorchCheckpoint
Source§impl<'de> Deserialize<'de> for PyTorchCheckpoint
impl<'de> Deserialize<'de> for PyTorchCheckpoint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for PyTorchCheckpoint
impl RefUnwindSafe for PyTorchCheckpoint
impl Send for PyTorchCheckpoint
impl Sync for PyTorchCheckpoint
impl Unpin for PyTorchCheckpoint
impl UnsafeUnpin for PyTorchCheckpoint
impl UnwindSafe for PyTorchCheckpoint
Blanket Implementations§
impl<T> Allocation for T
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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