pub struct GradientAccumulator { /* private fields */ }Expand description
Gradient accumulation
Accumulates gradients over multiple micro-batches before updating. Useful for training with large effective batch sizes on limited memory.
Implementations§
Source§impl GradientAccumulator
impl GradientAccumulator
pub fn new(accumulation_steps: usize) -> Self
Sourcepub fn accumulate(&mut self, gradients: &HashMap<String, Tensor>)
pub fn accumulate(&mut self, gradients: &HashMap<String, Tensor>)
Accumulate gradients from a micro-batch
Sourcepub fn should_update(&self) -> bool
pub fn should_update(&self) -> bool
Check if ready to update (accumulated enough steps)
Sourcepub fn get_and_reset(&mut self) -> HashMap<String, Tensor>
pub fn get_and_reset(&mut self) -> HashMap<String, Tensor>
Get accumulated gradients and reset
Auto Trait Implementations§
impl Freeze for GradientAccumulator
impl !RefUnwindSafe for GradientAccumulator
impl Send for GradientAccumulator
impl Sync for GradientAccumulator
impl Unpin for GradientAccumulator
impl !UnwindSafe for GradientAccumulator
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> 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