pub struct GradientAggregator;Expand description
Aggregates gradients from distributed workers.
Implementations§
Source§impl GradientAggregator
impl GradientAggregator
Sourcepub fn aggregate_gradients(
&self,
local_grad: &[f64],
strategy: &AllReduceStrategy,
) -> Vec<f64>
pub fn aggregate_gradients( &self, local_grad: &[f64], strategy: &AllReduceStrategy, ) -> Vec<f64>
Aggregate local_grad from this worker together with gradients that have
already been reduced on other workers, using the given strategy.
For the single-worker case the function simply returns a normalised copy of
local_grad. In a real multi-node scenario the caller would pass the
collected per-worker slices through ring_all_reduce or the tree variant.
Sourcepub fn ring_all_reduce(&self, gradients: Vec<Vec<f64>>) -> Vec<f64>
pub fn ring_all_reduce(&self, gradients: Vec<Vec<f64>>) -> Vec<f64>
Simulate ring all-reduce over a set of per-worker gradient vectors.
Ring all-reduce arranges n workers in a ring. It runs in two phases:
-
Scatter-reduce (
n−1steps): at steps, each workerwpasses the accumulated data for chunk(w − s) mod nto its right neighbour(w + 1) mod n, which adds it to its own copy. Aftern−1steps, workerwholds the fully-reduced sum for chunk(w + 1) mod n. -
All-gather: collect the fully-reduced chunk from each owning worker and divide by
nto obtain the mean.
The mathematical result equals the element-wise mean of all input vectors. This simulation runs synchronously on the calling thread with no I/O.
Trait Implementations§
Source§impl Clone for GradientAggregator
impl Clone for GradientAggregator
Source§fn clone(&self) -> GradientAggregator
fn clone(&self) -> GradientAggregator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GradientAggregator
impl Debug for GradientAggregator
Source§impl Default for GradientAggregator
impl Default for GradientAggregator
Source§fn default() -> GradientAggregator
fn default() -> GradientAggregator
Auto Trait Implementations§
impl Freeze for GradientAggregator
impl RefUnwindSafe for GradientAggregator
impl Send for GradientAggregator
impl Sync for GradientAggregator
impl Unpin for GradientAggregator
impl UnsafeUnpin for GradientAggregator
impl UnwindSafe for GradientAggregator
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> 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.