pub struct OptimizerState {
pub step: usize,
pub momentum: HashMap<String, Vec<f32>>,
pub variance: HashMap<String, Vec<f32>>,
pub third_moment: HashMap<String, Vec<f32>>,
pub param_steps: HashMap<String, usize>,
pub velocity: HashMap<String, Vec<f32>>,
}Expand description
Unified state management for optimizer parameters.
This struct provides a consistent interface for tracking optimizer state across different algorithms, reducing code duplication and memory overhead.
Fields§
§step: usizeCurrent step counter for bias correction and scheduling
momentum: HashMap<String, Vec<f32>>First moment estimates (momentum buffers)
variance: HashMap<String, Vec<f32>>Second moment estimates (squared gradient buffers)
third_moment: HashMap<String, Vec<f32>>Optional third moment estimates (for higher-order methods)
param_steps: HashMap<String, usize>Per-parameter step counts (for adaptive methods)
velocity: HashMap<String, Vec<f32>>Velocity buffers for optimization methods like SGD with momentum
Implementations§
Source§impl OptimizerState
impl OptimizerState
Sourcepub fn get_or_create_momentum(
&mut self,
param_id: String,
size: usize,
) -> &mut Vec<f32>
pub fn get_or_create_momentum( &mut self, param_id: String, size: usize, ) -> &mut Vec<f32>
Gets or creates momentum buffer for a parameter.
Sourcepub fn get_or_create_variance(
&mut self,
param_id: String,
size: usize,
) -> &mut Vec<f32>
pub fn get_or_create_variance( &mut self, param_id: String, size: usize, ) -> &mut Vec<f32>
Gets or creates variance buffer for a parameter.
Sourcepub fn get_or_create_third_moment(
&mut self,
param_id: String,
size: usize,
) -> &mut Vec<f32>
pub fn get_or_create_third_moment( &mut self, param_id: String, size: usize, ) -> &mut Vec<f32>
Gets or creates third moment buffer for a parameter.
Sourcepub fn step_param(&mut self, param_id: String)
pub fn step_param(&mut self, param_id: String)
Increments the step counter for a specific parameter.
Sourcepub fn get_param_step(&self, param_id: &str) -> usize
pub fn get_param_step(&self, param_id: &str) -> usize
Gets the step count for a specific parameter.
Sourcepub fn memory_usage(&self) -> StateMemoryStats
pub fn memory_usage(&self) -> StateMemoryStats
Gets memory usage statistics.
Trait Implementations§
Source§impl Clone for OptimizerState
impl Clone for OptimizerState
Source§fn clone(&self) -> OptimizerState
fn clone(&self) -> OptimizerState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OptimizerState
impl Debug for OptimizerState
Source§impl Default for OptimizerState
impl Default for OptimizerState
Source§impl<'de> Deserialize<'de> for OptimizerState
impl<'de> Deserialize<'de> for OptimizerState
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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
Source§fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
Source§fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
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