pub struct GradientAccumulator<A: Float, D: Dimension> { /* private fields */ }
Expand description
Gradient accumulation utility
Implementations§
Source§impl<A: Float + ScalarOperand + Debug, D: Dimension> GradientAccumulator<A, D>
impl<A: Float + ScalarOperand + Debug, D: Dimension> GradientAccumulator<A, D>
Sourcepub fn new(accumulation_steps: usize, average_gradients: bool) -> Self
pub fn new(accumulation_steps: usize, average_gradients: bool) -> Self
Create a new gradient accumulator
§Arguments
accumulation_steps
- Number of micro-batches to accumulate before steppingaverage_gradients
- Whether to average gradients (true) or sum them (false)
Sourcepub fn accumulate(&mut self, gradients: &Array<A, D>) -> bool
pub fn accumulate(&mut self, gradients: &Array<A, D>) -> bool
Sourcepub fn get_and_reset(&mut self) -> Option<Array<A, D>>
pub fn get_and_reset(&mut self) -> Option<Array<A, D>>
Get the accumulated gradients and reset the accumulator
§Returns
The accumulated gradients, ready for optimization step
Sourcepub fn set_accumulation_steps(&mut self, steps: usize)
pub fn set_accumulation_steps(&mut self, steps: usize)
Change accumulation steps
Trait Implementations§
Auto Trait Implementations§
impl<A, D> Freeze for GradientAccumulator<A, D>where
D: Freeze,
impl<A, D> RefUnwindSafe for GradientAccumulator<A, D>where
D: RefUnwindSafe,
A: RefUnwindSafe,
impl<A, D> Send for GradientAccumulator<A, D>where
A: Send,
impl<A, D> Sync for GradientAccumulator<A, D>where
A: Sync,
impl<A, D> Unpin for GradientAccumulator<A, D>where
D: Unpin,
impl<A, D> UnwindSafe for GradientAccumulator<A, D>where
D: UnwindSafe,
A: RefUnwindSafe,
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