pub trait Aggregator: Send + Sync {
type Element: ?Sized + Storage;
type Error: Error + Display + Send + Sync + 'static;
type Metadata: Clone + Default + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static;
// Required methods
fn contribute(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
src: PeerId,
tensor: &Self::Element,
metadata: Self::Metadata,
completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>;
fn aggregate(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
completion: CompletionHandle<(Box<Self::Element>, Self::Metadata), Self::Error>,
) -> ContractResponse<(Box<Self::Element>, Self::Metadata), Self::Error>;
}Expand description
User-facing Contract trait for a federated/decentralized
aggregator. The derive bridges these methods to the engine’s
crate::roles::AggregatorRuntime trait.
Required Associated Types§
Sourcetype Element: ?Sized + Storage
type Element: ?Sized + Storage
Storage element type for the tensors this aggregator
operates on. Most f32-native aggregators declare
type Element = [f32].
The bound ?Sized + bb_ir::types::Storage allows unsized
slice types like [f32] (a Box<[f32]> is the owned form
returned from aggregate).
Sourcetype Metadata: Clone + Default + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static
type Metadata: Clone + Default + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static
Impl-defined metadata that travels alongside the tensor. Carried as a typed slot value; serde fires only when the value crosses a wire boundary.
For FedAvg: type Metadata = FedAvgMeta { num_samples: u64 };.
For impls with no metadata channel: type Metadata = ();.
Required Methods§
Sourcefn contribute(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
src: PeerId,
tensor: &Self::Element,
metadata: Self::Metadata,
completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>
fn contribute( &mut self, ctx: &mut RuntimeResourceRef<'_>, src: PeerId, tensor: &Self::Element, metadata: Self::Metadata, 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.
Sourcefn aggregate(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
completion: CompletionHandle<(Box<Self::Element>, Self::Metadata), Self::Error>,
) -> ContractResponse<(Box<Self::Element>, Self::Metadata), Self::Error>
fn aggregate( &mut self, ctx: &mut RuntimeResourceRef<'_>, completion: CompletionHandle<(Box<Self::Element>, Self::Metadata), Self::Error>, ) -> ContractResponse<(Box<Self::Element>, Self::Metadata), 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):
params: the aggregated tensor, owned asBox<Self::Element>(e.g.Box<[f32]>). Same allocator footprint as aVec<f32>— usevec.into_boxed_slice().metadata: typed accompanying data describing the aggregation (e.g. summednum_samplesfor hierarchical FedAvg).
The output edge fires only when the reduction completes;
downstream consumers wire directly to the (params, metadata) outputs — no separate read op needed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".