pub struct DistributedGradientAccumulator {
pub local_gradient: Vec<f32>,
pub peer_gradients: HashMap<String, Vec<f32>>,
/* private fields */
}Expand description
Accumulates gradients from distributed peers via content-addressed storage.
Workflow:
- Call
commit_localto serialize and store the local gradient, obtaining aCidthat can be broadcast to peers. - Call
add_peer_gradientfor each CID received from a peer. The accumulator fetches the raw bytes from theBlockStore, decodes them via Arrow IPC, and caches the result. - Once
is_readyreturnstrue, callaggregateto run FedAvg over all collected gradients (local + peers).
Fields§
§local_gradient: Vec<f32>The local node’s gradient, set by commit_local.
peer_gradients: HashMap<String, Vec<f32>>Gradients received from peers, keyed by peer ID.
Implementations§
Source§impl DistributedGradientAccumulator
impl DistributedGradientAccumulator
Sourcepub fn new(session_id: &str, config: BackwardPassConfig) -> Self
pub fn new(session_id: &str, config: BackwardPassConfig) -> Self
Create a new accumulator for the given session.
Sourcepub async fn commit_local(
&mut self,
grad: Vec<f32>,
store: &dyn BlockStore,
) -> Result<Cid>
pub async fn commit_local( &mut self, grad: Vec<f32>, store: &dyn BlockStore, ) -> Result<Cid>
Store the local gradient as Arrow IPC bytes in store, returning its CID.
The CID is computed as a raw-block CID (SHA-256) over the Arrow IPC bytes.
Sourcepub async fn add_peer_gradient(
&mut self,
peer_id: &str,
cid: &Cid,
store: &dyn BlockStore,
) -> Result<()>
pub async fn add_peer_gradient( &mut self, peer_id: &str, cid: &Cid, store: &dyn BlockStore, ) -> Result<()>
Fetch and decode a peer’s gradient from store using its CID.
Sourcepub fn aggregate(&self) -> Result<Vec<f32>, GradientError>
pub fn aggregate(&self) -> Result<Vec<f32>, GradientError>
Aggregate all collected gradients using the configured AggregationMethod.
Includes the local gradient plus all peer gradients collected so far.
The aggregation strategy is taken from BackwardPassConfig::aggregation.
Sourcepub fn is_ready(&self, min_peers: usize) -> bool
pub fn is_ready(&self, min_peers: usize) -> bool
Returns true when at least min_peers peer gradients have been collected.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session identifier passed at construction time.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Number of peer gradients collected so far (not counting local).
Auto Trait Implementations§
impl Freeze for DistributedGradientAccumulator
impl RefUnwindSafe for DistributedGradientAccumulator
impl Send for DistributedGradientAccumulator
impl Sync for DistributedGradientAccumulator
impl Unpin for DistributedGradientAccumulator
impl UnsafeUnpin for DistributedGradientAccumulator
impl UnwindSafe for DistributedGradientAccumulator
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
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>
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>
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