pub struct CompressedAllReduce { /* private fields */ }Expand description
Distributed gradient aggregator with compression support
Implementations§
Source§impl CompressedAllReduce
impl CompressedAllReduce
pub fn new(compression_method: CompressionMethod, world_size: usize) -> Self
Sourcepub fn all_reduce(
&mut self,
gradients: &HashMap<String, Tensor>,
) -> Result<HashMap<String, Tensor>>
pub fn all_reduce( &mut self, gradients: &HashMap<String, Tensor>, ) -> Result<HashMap<String, Tensor>>
Compresses, aggregates and averages gradients across the process group.
§Aggregation semantics
No transport is wired up in this crate, so there is exactly one honest thing this can do:
world_size == 1— the local rank is the group. The gradient is compressed and decompressed (so the caller sees the real compression error) and returned.world_size > 1with peer contributions supplied — seeCompressedAllReduce::all_reduce_with_peers, which performs the real sum.world_size > 1with no peers — an error. Scaling the local gradient byworld_size(what this used to do) is not an approximation of a sum across workers; it is numerically worse than doing nothing.
§Errors
Returns an error when world_size > 1, because no communicator is configured.
Sourcepub fn all_reduce_with_peers(
&mut self,
gradients: &HashMap<String, Tensor>,
peers: &[HashMap<String, CompressedGradient>],
) -> Result<HashMap<String, Tensor>>
pub fn all_reduce_with_peers( &mut self, gradients: &HashMap<String, Tensor>, peers: &[HashMap<String, CompressedGradient>], ) -> Result<HashMap<String, Tensor>>
Performs a genuine compressed all-reduce given the peers’ compressed gradients.
peers holds one map per other rank. Each parameter’s contributions are
summed in the dense domain and divided by the number of contributing ranks, so
the result is the true average of the compressed gradients — not a rescaling of
the local one.
§Errors
Returns an error when a peer supplies a gradient of a different length, or when
the number of contributions does not match world_size.
Sourcepub fn compress_for_transmission(
&mut self,
gradients: &HashMap<String, Tensor>,
) -> Result<HashMap<String, CompressedGradient>>
pub fn compress_for_transmission( &mut self, gradients: &HashMap<String, Tensor>, ) -> Result<HashMap<String, CompressedGradient>>
Compresses gradients for transmission to the other ranks.
§Errors
Returns an error when a gradient cannot be read.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CompressedAllReduce
impl RefUnwindSafe for CompressedAllReduce
impl Send for CompressedAllReduce
impl Sync for CompressedAllReduce
impl Unpin for CompressedAllReduce
impl UnsafeUnpin for CompressedAllReduce
impl UnwindSafe for CompressedAllReduce
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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