Skip to main content

Stateful

Trait Stateful 

Source
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§

Source

fn state_dict(&self) -> OptimizerState

Export the optimizer’s internal state as a serializable dictionary.

Source

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).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<B> Stateful for Adam<B>
where B: Backend,

Source§

impl<B> Stateful for AdamW<B>
where B: Backend,

Source§

impl<B> Stateful for RAdam<B>
where B: Backend,

Source§

impl<B> Stateful for RMSProp<B>
where B: Backend,

Source§

impl<B> Stateful for SGD<B>
where B: Backend,