pub struct TernaryOptimizerWrapper { /* private fields */ }Expand description
Optimizer wrapper with ternary gradient accumulation.
Combines ternary accumulation with gradient management for memory-efficient training. Useful for large batch training where gradient accumulation is necessary.
§Example
ⓘ
use vsa_optim_rs::ternary::TernaryOptimizerWrapper;
use vsa_optim_rs::TernaryConfig;
let mut wrapper = TernaryOptimizerWrapper::new(param_shapes, TernaryConfig::default(), &device)?;
for (i, batch) in batches.iter().enumerate() {
// Compute gradients...
let should_update = wrapper.step(&gradients)?;
if should_update {
let accumulated = wrapper.get_gradients_for_update()?;
// Apply to optimizer...
}
}Implementations§
Source§impl TernaryOptimizerWrapper
impl TernaryOptimizerWrapper
Sourcepub fn new(
param_shapes: &[(String, Vec<usize>)],
config: TernaryConfig,
device: &Device,
) -> Result<TernaryOptimizerWrapper, OptimError>
pub fn new( param_shapes: &[(String, Vec<usize>)], config: TernaryConfig, device: &Device, ) -> Result<TernaryOptimizerWrapper, OptimError>
Sourcepub fn get_gradients_for_update(
&mut self,
) -> Result<HashMap<String, Tensor>, OptimError>
pub fn get_gradients_for_update( &mut self, ) -> Result<HashMap<String, Tensor>, OptimError>
Sourcepub fn get_stats(&self) -> OptimizerStats
pub fn get_stats(&self) -> OptimizerStats
Get optimization statistics.
Sourcepub const fn step_count(&self) -> usize
pub const fn step_count(&self) -> usize
Get the step count.
Sourcepub const fn update_count(&self) -> usize
pub const fn update_count(&self) -> usize
Get the update count.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Reset state for checkpointing.
Sourcepub fn load_state(&mut self, step_count: usize, update_count: usize)
pub fn load_state(&mut self, step_count: usize, update_count: usize)
Load state from checkpoint.
Auto Trait Implementations§
impl Freeze for TernaryOptimizerWrapper
impl !RefUnwindSafe for TernaryOptimizerWrapper
impl Send for TernaryOptimizerWrapper
impl Sync for TernaryOptimizerWrapper
impl Unpin for TernaryOptimizerWrapper
impl !UnwindSafe for TernaryOptimizerWrapper
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> 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>
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