pub struct ThreadedGradientSync { /* private fields */ }Expand description
All-reduce gradient synchronizer backed by Arc<Mutex<>> for multi-threaded
training simulation within a single process.
All workers that share the same underlying SharedState barrier must call
GradientSync::sync_gradients with arrays of the same length, otherwise an
error is returned. The synchronization algorithm is:
- Worker adds its gradients into the shared accumulator.
- The last arriving worker computes the element-wise mean, stores it as the result, and signals all waiters.
- All workers copy the averaged result back into their local gradient buffer.
- The last departing worker resets state for the next round.
Implementations§
Trait Implementations§
Source§impl Clone for ThreadedGradientSync
impl Clone for ThreadedGradientSync
Source§fn clone(&self) -> ThreadedGradientSync
fn clone(&self) -> ThreadedGradientSync
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 moreSource§impl Debug for ThreadedGradientSync
impl Debug for ThreadedGradientSync
Source§impl GradientSync for ThreadedGradientSync
impl GradientSync for ThreadedGradientSync
Source§fn sync_gradients(&self, gradients: &mut Array1<f32>) -> ModelResult<()>
fn sync_gradients(&self, gradients: &mut Array1<f32>) -> ModelResult<()>
Synchronize (aggregate) gradients across all workers. Read more
Source§fn is_distributed(&self) -> bool
fn is_distributed(&self) -> bool
Returns
true if this sync implementation involves multiple workers.Source§fn num_workers(&self) -> usize
fn num_workers(&self) -> usize
Number of workers participating in synchronization.
Auto Trait Implementations§
impl Freeze for ThreadedGradientSync
impl RefUnwindSafe for ThreadedGradientSync
impl Send for ThreadedGradientSync
impl Sync for ThreadedGradientSync
impl Unpin for ThreadedGradientSync
impl UnsafeUnpin for ThreadedGradientSync
impl UnwindSafe for ThreadedGradientSync
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