pub struct FedAvg<B: Backend> { /* private fields */ }Expand description
FedAvg aggregator: weighted average where weights are
num_samples / total_samples. Generic over B: Backend so the
reduction composes from the backend’s Mul + Add primitives
without bumping the 30-op floor.
The buffer is a BTreeMap<PeerId, (B::Tensor, u64)> so the
reduction walk has a deterministic iteration order (lexical by
peer id). The engine’s dispatch_atomic(&mut self, ...) contract
gives the aggregator exclusive access for the duration of each
call. The buffer is #[serde(skip)] because snapshot captures
the aggregator’s structural identity, not the per-round transient
contribution state.
Trait Implementations§
Source§impl<B> Aggregator for FedAvg<B>
impl<B> Aggregator for FedAvg<B>
Source§type Element = <B as Backend>::Tensor
type Element = <B as Backend>::Tensor
Storage element type for the tensors this aggregator
operates on. Most f32-native aggregators declare
type Element = [f32]. Read moreSource§type Metadata = FedAvgMeta
type Metadata = FedAvgMeta
Impl-defined metadata that travels alongside the tensor.
Carried as a typed slot value; serde fires only when the
value crosses a wire boundary. Read more
Source§fn contribute(
&mut self,
_ctx: &mut RuntimeResourceRef<'_>,
src: PeerId,
tensor: &Self::Element,
metadata: FedAvgMeta,
_completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>
fn contribute( &mut self, _ctx: &mut RuntimeResourceRef<'_>, src: PeerId, tensor: &Self::Element, metadata: FedAvgMeta, _completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>
Contribute one peer’s update to the in-progress aggregation.
ctx is the per-dispatch runtime surface; impls reach their
declared #[depends(...)] siblings through
RuntimeResourceRef::dependency. tensor is a reference
to the element (e.g. &[f32] for Element = [f32]).
metadata is the typed accompanying data (sample counts for
FedAvg, weights for weighted sum, round ids, …).
Default-constructed Metadata is valid for impls that don’t
have a real metadata channel.Source§fn aggregate(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
_completion: CompletionHandle<(Box<Self::Element>, FedAvgMeta), Self::Error>,
) -> ContractResponse<(Box<Self::Element>, FedAvgMeta), Self::Error>
fn aggregate( &mut self, ctx: &mut RuntimeResourceRef<'_>, _completion: CompletionHandle<(Box<Self::Element>, FedAvgMeta), Self::Error>, ) -> ContractResponse<(Box<Self::Element>, FedAvgMeta), Self::Error>
Reduce the accumulated contributions and return the result.
ctx carries the runtime surface so the aggregator’s
reduction can resolve #[depends(...)] siblings (e.g. the
Backend that supplies the composed weighted-sum).
Output is (params, metadata): Read moreSource§impl<B> AggregatorRuntime for FedAvg<B>
impl<B> AggregatorRuntime for FedAvg<B>
Source§fn atomic_opset(&self) -> AtomicOpsetDecl
fn atomic_opset(&self) -> AtomicOpsetDecl
Atomic-op opset this impl owns.
Source§fn dispatch_atomic(
&mut self,
op_type: &str,
inputs: &[(&str, &dyn SlotValue)],
ctx: &mut RuntimeResourceRef<'_>,
) -> Result<DispatchResult, Self::Error>
fn dispatch_atomic( &mut self, op_type: &str, inputs: &[(&str, &dyn SlotValue)], ctx: &mut RuntimeResourceRef<'_>, ) -> Result<DispatchResult, Self::Error>
Rust-dispatch entry point for atomic ops.
Source§impl<B: Backend + 'static> AnyComponent for FedAvg<B>
impl<B: Backend + 'static> AnyComponent for FedAvg<B>
Source§impl<B> ConcreteComponent for FedAvg<B>
impl<B> ConcreteComponent for FedAvg<B>
Source§const PACKAGE: ComponentPackage = ComponentPackage::Framework
const PACKAGE: ComponentPackage = ComponentPackage::Framework
Origin tag; defaults to
Application.Source§const DEPENDENCIES: &'static [DependencyDecl]
const DEPENDENCIES: &'static [DependencyDecl]
Sibling components this depends on. Populated by the
bb::Concrete derive from #[bb::depends(...)].Source§type Error = Infallible
type Error = Infallible
Error from
Self::new; use Infallible if construction
can’t fail.Source§impl<'de, B: Backend> Deserialize<'de> for FedAvg<B>
impl<'de, B: Backend> Deserialize<'de> for FedAvg<B>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<B> Freeze for FedAvg<B>
impl<B> RefUnwindSafe for FedAvg<B>
impl<B> Send for FedAvg<B>
impl<B> Sync for FedAvg<B>
impl<B> Unpin for FedAvg<B>where
B: Unpin,
impl<B> UnsafeUnpin for FedAvg<B>
impl<B> UnwindSafe for FedAvg<B>
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
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedComponent for T
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>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> SlotValue for T
impl<T> SlotValue for T
Source§fn into_any_boxed(self: Box<T>) -> Box<dyn Any + Sync + Send>
fn into_any_boxed(self: Box<T>) -> Box<dyn Any + Sync + Send>
Repackage
Box<dyn SlotValue> as Box<dyn Any> for
Box::downcast. Required because the SlotValue and
Any vtables are distinct even though SlotValue: Any.Source§fn clone_boxed(&self) -> Box<dyn SlotValue>
fn clone_boxed(&self) -> Box<dyn SlotValue>
Polymorphic clone preserving the concrete type.
Source§fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
Wire-boundary encode (bincode + serde). Local forwarding
uses
clone_boxed instead.Source§fn type_hash(&self) -> u64
fn type_hash(&self) -> u64
Stable cross-Node type discriminator. FNV-1a of
std::any::type_name::<T>(); receiver decodes only on a
matching hash.Source§fn runtime_type(&self) -> &'static TypeNode
fn runtime_type(&self) -> &'static TypeNode
Source§fn charged_bytes(&self) -> usize
fn charged_bytes(&self) -> usize
Bytes the carrier owes against
NodeConfig::ingress_byte_budget. Slot-table eviction calls
this to release the charge. Default 0 — only
ingress-derived carriers register a non-zero resolver via
[register_charged_bytes!].