pub struct DeltaEncoder {
pub previous: Option<Vec<f32>>,
pub stats: DeltaStats,
/* private fields */
}Expand description
Stateful encoder that computes element-wise deltas between successive gradient rounds.
On the first call (or after DeltaEncoder::reset), the full gradient is
returned. Subsequent calls return the element-wise difference from the
previously stored gradient.
Fields§
§previous: Option<Vec<f32>>The gradient that was sent in the previous round.
stats: DeltaStatsCumulative statistics.
Implementations§
Source§impl DeltaEncoder
impl DeltaEncoder
Sourcepub fn encode_delta(&mut self, current: &[f32]) -> GradientDelta
pub fn encode_delta(&mut self, current: &[f32]) -> GradientDelta
Encode current as either a full gradient or a delta.
- If no previous gradient is stored, the full gradient is returned and
is_fullis set totrue. - Otherwise, the element-wise delta
current[i] - previous[i]is returned.
The internal round counter is incremented on every call. If the length
of current differs from the stored previous gradient, the previous
state is discarded and a full send is performed.
Sourcepub fn decode_delta(&self, base: &[f32], delta: &GradientDelta) -> Vec<f32>
pub fn decode_delta(&self, base: &[f32], delta: &GradientDelta) -> Vec<f32>
Reconstruct a full gradient from a base vector and a GradientDelta.
- If
delta.is_full, returns a clone ofdelta.values. - Otherwise, adds
delta.values[i]tobase[i]element-wise.
If the lengths of base and delta.values disagree, the shorter length
is used (extra elements in the longer slice are silently ignored).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DeltaEncoder
impl RefUnwindSafe for DeltaEncoder
impl Send for DeltaEncoder
impl Sync for DeltaEncoder
impl Unpin for DeltaEncoder
impl UnsafeUnpin for DeltaEncoder
impl UnwindSafe for DeltaEncoder
Blanket Implementations§
impl<T> Allocation for T
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