pub trait Stateful {
// Required methods
fn state_dict(&self) -> OptimizerState;
fn load_state_dict(&mut self, state: &OptimizerState) -> Result<(), Error>;
}Expand description
Trait for optimizers that can save and restore their internal state.
This enables training checkpoint save/load — not just model weights, but also the optimizer’s momentum buffers, step counters, etc., allowing training to resume exactly where it left off.
Required Methods§
Sourcefn state_dict(&self) -> OptimizerState
fn state_dict(&self) -> OptimizerState
Export the optimizer’s internal state as a serializable dictionary.
Sourcefn load_state_dict(&mut self, state: &OptimizerState) -> Result<(), Error>
fn load_state_dict(&mut self, state: &OptimizerState) -> Result<(), Error>
Restore the optimizer’s internal state from a previously saved dictionary.
Returns an error if the state dict is incompatible (wrong optimizer type, missing keys, wrong buffer sizes).