Skip to main content

FedAvg

Struct FedAvg 

Source
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>
where B: 'static + Backend, B::Tensor: Tensor,

Source§

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 more
Source§

type Error = OpError

Library-maker-defined error type.
Source§

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>

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>

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 more
Source§

impl<B> AggregatorRuntime for FedAvg<B>
where B: Backend + 'static + Default, B::Tensor: Tensor,

Source§

type Error = OpError

Aggregator-impl-specific error type.
Source§

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>

Rust-dispatch entry point for atomic ops.
Source§

impl<B: Backend + 'static> AnyComponent for FedAvg<B>

Source§

fn as_any(&self) -> &dyn Any

Downcast view - immutable.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Downcast view - mutable.
Source§

impl<B: Backend> Clone for FedAvg<B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B> ConcreteComponent for FedAvg<B>
where B: 'static + Default + Backend,

Source§

const TYPE_NAME: &'static str = "FedAvg"

Stable identifier. Convention: <crate>::<TypeName>.
Source§

const PACKAGE: ComponentPackage = ComponentPackage::Framework

Origin tag; defaults to Application.
Source§

const DEPENDENCIES: &'static [DependencyDecl]

Sibling components this depends on. Populated by the bb::Concrete derive from #[bb::depends(...)].
Source§

type Config = ()

Per-deployment config. Use () for stateless concretes.
Source§

type Error = Infallible

Error from Self::new; use Infallible if construction can’t fail.
Source§

fn new(_: &Self::Config) -> Result<Self, Self::Error>

Construct from &Self::Config. Install calls this once per slot.
Source§

fn serialize(&self) -> Vec<u8>

Serialize state to bytes, including config-derived fields.
Source§

fn restore(bytes: &[u8]) -> Result<Self, RestoreError>

Reconstruct from serialize output.
Source§

impl<B: Debug + Backend> Debug for FedAvg<B>
where B::Tensor: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B: Backend> Default for FedAvg<B>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, B: Backend> Deserialize<'de> for FedAvg<B>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<B: Backend> Serialize for FedAvg<B>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedComponent for T
where T: Any + Send + Sync,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SlotValue for T

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcast surface — recover the concrete type.
Source§

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>

Polymorphic clone preserving the concrete type.
Source§

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

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

Runtime TypeNode for this value. Returns the leaf registered via [register_type_node!] or TYPE_ANY. Consulted at wire boundaries + TypeSolver seeding; the atomic-dispatch hot path uses compile-time-stamped closures.
Source§

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!].
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more