Skip to main content

GradientsAccumulator

Struct GradientsAccumulator 

Source
pub struct GradientsAccumulator<M> { /* private fields */ }
Expand description

Accumulate gradients into a single Gradients object.

Implementations§

Source§

impl<M> GradientsAccumulator<M>

Source

pub fn new() -> Self

Create a new gradients accumulator.

Source§

impl<M> GradientsAccumulator<M>

Source

pub fn try_to_record<B: AutodiffBackend>( &self, ) -> Result<GradientsParamsRecord, RecorderError>
where M: AutodiffModule<B>,

Snapshot pending gradients without resetting the accumulation window.

Source

pub async fn to_record_async<B: AutodiffBackend>( &self, ) -> Result<GradientsParamsRecord, RecorderError>
where M: AutodiffModule<B>,

Asynchronously snapshot pending gradients without resetting the accumulator.

Source

pub fn load_record<B: AutodiffBackend>( &mut self, record: GradientsParamsRecord, device: &B::Device, ) -> Result<(), RecorderError>
where M: AutodiffModule<B>,

Replace pending gradients with checkpoint state on the given device.

The model IDs and the caller’s accumulation count must be restored from the same checkpoint. A rejected record leaves the accumulator unchanged.

Source

pub fn accumulate<B: AutodiffBackend>( &mut self, module: &M, grads: GradientsParams, )
where M: AutodiffModule<B>,

Accumulate the given gradients for each parameter in the given module.

Source

pub fn grads(&mut self) -> GradientsParams

Return the accumulated gradients and reset the accumulator state.

Trait Implementations§

Source§

impl<M> Default for GradientsAccumulator<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.