pub struct AllReduceAggregator { /* private fields */ }Expand description
All-reduce aggregator: averages gradients across all workers via ring reduce.
Each worker independently computes local gradients and then calls
GradientAggregator::aggregate. Internally the aggregator serialises the
gradient tensors, performs a ring all-reduce (scatter-reduce followed by
all-gather) over the configured Transport, and returns the element-wise
average. This is the most common strategy for synchronous data-parallel
training because every worker ends up with the same averaged gradients
without a central bottleneck.
§Example
ⓘ
let transports = InProcessTransport::create_group(2);
let cfg = DistributedConfig { world_size: 2, rank: 0, coordinator_addr: String::new() };
let mut agg = AllReduceAggregator::new(cfg, Box::new(transports.into_iter().next().unwrap()));
let averaged = agg.aggregate(&local_grads).unwrap();Implementations§
Source§impl AllReduceAggregator
impl AllReduceAggregator
pub fn new(config: DistributedConfig, transport: Box<dyn Transport>) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AllReduceAggregator
impl !RefUnwindSafe for AllReduceAggregator
impl Send for AllReduceAggregator
impl !Sync for AllReduceAggregator
impl Unpin for AllReduceAggregator
impl UnsafeUnpin for AllReduceAggregator
impl !UnwindSafe for AllReduceAggregator
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> 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