pub struct GradientsAccumulator<M> { /* private fields */ }Expand description
Accumulate gradients into a single Gradients object.
Implementations§
Source§impl<M> GradientsAccumulator<M>
impl<M> GradientsAccumulator<M>
Source§impl<M> GradientsAccumulator<M>
impl<M> GradientsAccumulator<M>
Sourcepub fn try_to_record<B: AutodiffBackend>(
&self,
) -> Result<GradientsParamsRecord, RecorderError>where
M: AutodiffModule<B>,
pub fn try_to_record<B: AutodiffBackend>(
&self,
) -> Result<GradientsParamsRecord, RecorderError>where
M: AutodiffModule<B>,
Snapshot pending gradients without resetting the accumulation window.
Sourcepub async fn to_record_async<B: AutodiffBackend>(
&self,
) -> Result<GradientsParamsRecord, RecorderError>where
M: AutodiffModule<B>,
pub async fn to_record_async<B: AutodiffBackend>(
&self,
) -> Result<GradientsParamsRecord, RecorderError>where
M: AutodiffModule<B>,
Asynchronously snapshot pending gradients without resetting the accumulator.
Sourcepub fn load_record<B: AutodiffBackend>(
&mut self,
record: GradientsParamsRecord,
device: &B::Device,
) -> Result<(), RecorderError>where
M: AutodiffModule<B>,
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.
Sourcepub fn accumulate<B: AutodiffBackend>(
&mut self,
module: &M,
grads: GradientsParams,
)where
M: AutodiffModule<B>,
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.
Sourcepub fn accumulate_with_dtype<B: AutodiffBackend>(
&mut self,
module: &M,
grads: GradientsParams,
dtype: FloatDType,
)where
M: AutodiffModule<B>,
pub fn accumulate_with_dtype<B: AutodiffBackend>(
&mut self,
module: &M,
grads: GradientsParams,
dtype: FloatDType,
)where
M: AutodiffModule<B>,
Accumulate after converting incoming and pending gradients to the given dtype.
FP32 accumulation can retain small additions to half-precision gradients. Parameter storage, loss normalization and accumulation counts are unchanged. Checkpoints preserve the pending gradient dtype; select the same dtype on subsequent calls after restoring. No accumulator reset is performed.
Sourcepub fn grads(&mut self) -> GradientsParams
pub fn grads(&mut self) -> GradientsParams
Return the accumulated gradients and reset the accumulator state.