pub struct CompressedGradient {
pub indices: Vec<usize>,
pub values: Vec<f32>,
pub original_size: usize,
pub compression_ratio: f32,
pub value_bits: u8,
}Expand description
One gradient after compression, in the form it would be put on the wire.
indices is empty for dense methods (quantization, SignSGD): those transmit a
value for every coordinate, so an explicit 0..n index list would be pure
overhead. Sparse methods (top-k, random-k, threshold) list the coordinates they
kept.
values always holds the dequantized f32 values so callers can do arithmetic
with them directly; value_bits records how many bits each value actually needs on
the wire, which is what CompressedGradient::payload_bytes uses.
Fields§
§indices: Vec<usize>Kept coordinates, or empty for a dense positional payload.
values: Vec<f32>Dequantized values, in indices order (or coordinate order when dense).
original_size: usizeNumber of elements in the uncompressed gradient.
compression_ratio: f32Fraction of the original payload this representation occupies.
value_bits: u8Bits each value needs on the wire (32 for an untransformed f32, 8 for
8-bit quantization, 1 for a sign).
Implementations§
Source§impl CompressedGradient
impl CompressedGradient
Sourcepub fn payload_bytes(&self) -> usize
pub fn payload_bytes(&self) -> usize
Bytes this representation would put on the wire.
Indices cost size_of::<usize>() each; values cost value_bits bits each,
rounded up to whole bytes.
Sourcepub fn dense_bytes(&self) -> usize
pub fn dense_bytes(&self) -> usize
Bytes the uncompressed f32 gradient would occupy.
Trait Implementations§
Source§impl Clone for CompressedGradient
impl Clone for CompressedGradient
Source§fn clone(&self) -> CompressedGradient
fn clone(&self) -> CompressedGradient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CompressedGradient
impl RefUnwindSafe for CompressedGradient
impl Send for CompressedGradient
impl Sync for CompressedGradient
impl Unpin for CompressedGradient
impl UnsafeUnpin for CompressedGradient
impl UnwindSafe for CompressedGradient
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> 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 more