pub struct SharedGradientStore { /* private fields */ }Expand description
Thread-safe gradient store that simulates AllReduce across world_size ranks.
Each rank pushes its local gradients via SharedGradientStore::push.
Once all ranks have pushed, any rank can call SharedGradientStore::all_reduce_mean
to obtain the element-wise average. Call SharedGradientStore::clear after
each optimiser step to reset state for the next iteration.
Implementations§
Sourcepub fn push(&self, rank: usize, grads: Vec<GradientBuffer>) -> ModelResult<()>
pub fn push(&self, rank: usize, grads: Vec<GradientBuffer>) -> ModelResult<()>
Submit gradient buffers from rank.
§Errors
Returns an error if the mutex is poisoned or rank >= world_size.
Sourcepub fn all_reduce_mean(&self, _rank: usize) -> ModelResult<Vec<GradientBuffer>>
pub fn all_reduce_mean(&self, _rank: usize) -> ModelResult<Vec<GradientBuffer>>
Wait until all ranks have pushed, then return the element-wise mean.
In tests all ranks run in the same process/thread, so all buffers will already be filled before this is called.
§Errors
Returns an error if not all ranks have submitted yet, or on lock failure.
Sourcepub fn clear(&self) -> ModelResult<()>
pub fn clear(&self) -> ModelResult<()>
Clear all gradient buffers — call after each optimiser step.
§Errors
Returns an error on lock failure.
Auto Trait Implementations§
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
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>
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>
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