Skip to main content

Module aggregator

Module aggregator 

Source
Expand description

bb::Aggregator — Contract trait for federated aggregators.

Each method takes a CompletionHandle AND returns ContractResponse. See crate::contracts::index for the sync (Now) vs async (Later) semantics.

§Shape

Aggregation is a two-op cycle: contribute(...) writes one peer’s update into an in-progress buffer; aggregate(...) reduces the buffer into the current aggregate AND returns it. There is no separate current_tensor() op — aggregate is the one-stop “compute + emit” call.

§Metadata channel

Both contribute and aggregate carry a typed metadata payload alongside the tensor, defined by the impl as the associated type Aggregator::Metadata.

The metadata is transported through the slot table as a typed Rust value — the framework’s slot-value layer (bb_ir::slot_value) holds every value as Box<dyn SlotValue> and downcasts to the concrete type via Any::downcast_ref. Bincode/serde fires only at the wire boundary (SlotValue::to_wire_bytes) and at snapshot time. In-process contribute/aggregate calls see the typed value directly — no serde overhead.

This is the channel hierarchical aggregation needs: a child FedAvg aggregator’s aggregate(...) emits (params, FedAvgMeta { num_samples }); the parent layer’s contribute(...) receives that and the num_samples weights the child’s contribution in the parent reduction. Both halves work with the typed FedAvgMeta — only the wire crossing does serde.

Impls that have no metadata channel set type Metadata = ();.

Traits§

Aggregator
User-facing Contract trait for a federated/decentralized aggregator. The derive bridges these methods to the engine’s crate::roles::AggregatorRuntime trait.