pub struct DistributedOptimizer {
pub strategy: AggregationStrategy,
pub current_step: u64,
pub dropped_updates: u64,
/* private fields */
}Expand description
Coordinator for distributed gradient aggregation across multiple workers.
Fields§
§strategy: AggregationStrategyAggregation strategy that governs when and how updates are combined.
current_step: u64The global training step counter.
dropped_updates: u64Number of updates that were rejected (staleness or other).
Implementations§
Source§impl DistributedOptimizer
impl DistributedOptimizer
Sourcepub fn new(strategy: AggregationStrategy) -> Self
pub fn new(strategy: AggregationStrategy) -> Self
Create a new optimizer with the given aggregation strategy.
Sourcepub fn register_worker(&mut self, worker_id: WorkerId) -> bool
pub fn register_worker(&mut self, worker_id: WorkerId) -> bool
Register a worker.
Returns true if the worker was newly registered, false if it was
already present (even if inactive).
Sourcepub fn deregister_worker(&mut self, worker_id: &WorkerId) -> bool
pub fn deregister_worker(&mut self, worker_id: &WorkerId) -> bool
Mark a worker as inactive (soft-deregister).
Returns true if the worker existed and was marked inactive,
false if it was not found.
Sourcepub fn submit_update(
&mut self,
update: GradientUpdate,
now: u64,
) -> Result<(), OptimizerDistError>
pub fn submit_update( &mut self, update: GradientUpdate, now: u64, ) -> Result<(), OptimizerDistError>
Submit a gradient update from a worker.
§Errors
OptimizerDistError::WorkerNotFoundif the worker is not registered.OptimizerDistError::StaleUpdatefor async strategy when the update is too far behind the global step.OptimizerDistError::DimensionMismatchwhen the gradient dimension conflicts with an already-pending update for the same layer.
Sourcepub fn try_aggregate(&mut self, layer_id: &str) -> Option<AggregatedGradient>
pub fn try_aggregate(&mut self, layer_id: &str) -> Option<AggregatedGradient>
Attempt to aggregate pending updates for layer_id.
Returns Some(AggregatedGradient) if the strategy’s quorum condition
is satisfied, None otherwise. On success the pending queue for that
layer is cleared and the result is stored in aggregated.
Sourcepub fn aggregate_gradients(updates: &[GradientUpdate]) -> Vec<f64>
pub fn aggregate_gradients(updates: &[GradientUpdate]) -> Vec<f64>
Compute the element-wise mean of a slice of GradientUpdates.
Returns an empty vector if updates is empty or all gradient vectors
are empty.
Sourcepub fn advance_step(&mut self)
pub fn advance_step(&mut self)
Advance the global training step by one.
For the AggregationStrategy::Synchronous strategy this also
clears all pending updates left over from the previous step (workers
that did not submit in time are implicitly skipped).
Sourcepub fn active_workers(&self) -> Vec<&WorkerState>
pub fn active_workers(&self) -> Vec<&WorkerState>
Returns references to all active workers.
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Total number of registered workers (active and inactive).
Sourcepub fn active_worker_count(&self) -> usize
pub fn active_worker_count(&self) -> usize
Number of currently active workers.
Sourcepub fn pending_updates_for(&self, layer_id: &str) -> usize
pub fn pending_updates_for(&self, layer_id: &str) -> usize
Number of pending (not-yet-aggregated) updates for a layer.
Sourcepub fn last_aggregated(&self, layer_id: &str) -> Option<&AggregatedGradient>
pub fn last_aggregated(&self, layer_id: &str) -> Option<&AggregatedGradient>
Returns the most recently aggregated gradient for a layer, if any.
Sourcepub fn evict_stale_workers(&mut self, max_age_ms: u64, now: u64) -> usize
pub fn evict_stale_workers(&mut self, max_age_ms: u64, now: u64) -> usize
Mark workers inactive if their last_seen timestamp is older than
now - max_age_ms.
Returns the number of workers evicted.
Sourcepub fn stats(&self) -> DistOptimizerStats
pub fn stats(&self) -> DistOptimizerStats
Snapshot current optimizer statistics.
Auto Trait Implementations§
impl Freeze for DistributedOptimizer
impl RefUnwindSafe for DistributedOptimizer
impl Send for DistributedOptimizer
impl Sync for DistributedOptimizer
impl Unpin for DistributedOptimizer
impl UnsafeUnpin for DistributedOptimizer
impl UnwindSafe for DistributedOptimizer
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