pub struct GradientArrowBlock {
pub cid: String,
pub layer_name: String,
pub shape: Vec<usize>,
pub values: Vec<f32>,
pub num_samples: usize,
}Expand description
A gradient stored as an Arrow IPC block with content-addressing.
Fields§
§cid: String§layer_name: String§shape: Vec<usize>§values: Vec<f32>§num_samples: usizeImplementations§
Source§impl GradientArrowBlock
impl GradientArrowBlock
Sourcepub fn to_arrow_bytes(&self) -> Vec<u8> ⓘ
pub fn to_arrow_bytes(&self) -> Vec<u8> ⓘ
Serialize gradient values to custom Arrow-flavoured IPC bytes.
Layout:
4 bytes magic "GARW"
4 bytes shape_len (u32 LE)
4n bytes shape (u32 LE each)
4 bytes values_len (u32 LE)
4m bytes values (f32 LE each)
4 bytes num_samples (u32 LE)Sourcepub fn from_arrow_bytes(
cid: String,
layer_name: String,
data: &[u8],
) -> Result<Self, ArrowBlockError>
pub fn from_arrow_bytes( cid: String, layer_name: String, data: &[u8], ) -> Result<Self, ArrowBlockError>
Deserialize from bytes produced by Self::to_arrow_bytes.
Sourcepub fn compute_cid(
layer_name: &str,
values: &[f32],
num_samples: usize,
) -> String
pub fn compute_cid( layer_name: &str, values: &[f32], num_samples: usize, ) -> String
Compute a deterministic CID string: "grad-" + hex(FNV-1a hash of serialized bytes).
Sourcepub fn fedavg(
blocks: &[GradientArrowBlock],
) -> Result<Vec<f32>, ArrowBlockError>
pub fn fedavg( blocks: &[GradientArrowBlock], ) -> Result<Vec<f32>, ArrowBlockError>
FedAvg: weighted average of multiple gradient blocks.
Weights are proportional to num_samples. All blocks must have the same
shape. Returns ArrowBlockError::EmptyInput for empty input and
ArrowBlockError::ShapeMismatch if shapes differ.
Auto Trait Implementations§
impl Freeze for GradientArrowBlock
impl RefUnwindSafe for GradientArrowBlock
impl Send for GradientArrowBlock
impl Sync for GradientArrowBlock
impl Unpin for GradientArrowBlock
impl UnsafeUnpin for GradientArrowBlock
impl UnwindSafe for GradientArrowBlock
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
Mutably borrows from an owned value. Read more
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>
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