pub struct OptimizerState {
pub optimizer_type: String,
pub scalars: HashMap<String, f64>,
pub buffers: HashMap<String, Vec<f64>>,
}Expand description
A serializable snapshot of an optimizer’s internal state.
Contains named scalar values (e.g., step count, learning rate) and named f64 buffers (e.g., momentum vectors, second moment estimates).
This follows the PyTorch state_dict() / load_state_dict() pattern
but is Rust-native and format-agnostic.
Fields§
§optimizer_type: StringOptimizer type name (e.g., “Adam”, “SGD”) for validation on load.
scalars: HashMap<String, f64>Named scalar values (step count, hyperparameters, etc.)
buffers: HashMap<String, Vec<f64>>Named f64 buffers (momentum vectors, second moment estimates, etc.)
Each buffer is flattened to a single Vec
Implementations§
Source§impl OptimizerState
impl OptimizerState
Sourcepub fn new(optimizer_type: impl Into<String>) -> OptimizerState
pub fn new(optimizer_type: impl Into<String>) -> OptimizerState
Create an empty state dict for the given optimizer type.
Sourcepub fn set_scalar(&mut self, key: impl Into<String>, value: f64)
pub fn set_scalar(&mut self, key: impl Into<String>, value: f64)
Insert a scalar value.
Sourcepub fn get_scalar(&self, key: &str) -> Option<f64>
pub fn get_scalar(&self, key: &str) -> Option<f64>
Get a scalar value.
Trait Implementations§
Source§impl Clone for OptimizerState
impl Clone for OptimizerState
Source§fn clone(&self) -> OptimizerState
fn clone(&self) -> OptimizerState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for OptimizerState
impl RefUnwindSafe for OptimizerState
impl Send for OptimizerState
impl Sync for OptimizerState
impl Unpin for OptimizerState
impl UnwindSafe for OptimizerState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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