pub struct GradientBuffer {
pub name: String,
pub local_gradient: Tensor,
pub accumulated_gradient: Option<Tensor>,
pub accumulation_steps: usize,
pub partition_info: PartitionInfo,
}Expand description
Gradient buffer for ZeRO Stage 2+
Fields§
§name: StringBuffer name
local_gradient: TensorLocal gradient shard
accumulated_gradient: Option<Tensor>Accumulated gradients
accumulation_steps: usizeNumber of accumulated steps
partition_info: PartitionInfoPartition metadata
Implementations§
Source§impl GradientBuffer
impl GradientBuffer
pub fn new( name: String, local_gradient: Tensor, partition_info: PartitionInfo, ) -> Self
Sourcepub fn accumulate(&mut self, gradient: &Tensor) -> Result<()>
pub fn accumulate(&mut self, gradient: &Tensor) -> Result<()>
Accumulate gradient
Sourcepub fn get_accumulated(&self) -> Option<Tensor>
pub fn get_accumulated(&self) -> Option<Tensor>
Get the accumulated gradient (averaged if needed)
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Get memory usage of this buffer
Trait Implementations§
Source§impl Clone for GradientBuffer
impl Clone for GradientBuffer
Source§fn clone(&self) -> GradientBuffer
fn clone(&self) -> GradientBuffer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for GradientBuffer
impl RefUnwindSafe for GradientBuffer
impl Send for GradientBuffer
impl Sync for GradientBuffer
impl Unpin for GradientBuffer
impl UnwindSafe for GradientBuffer
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> 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