pub struct DataParallelModel { /* private fields */ }Expand description
Data-parallel wrapper around a named weight map.
Simulates splitting a mini-batch across world_size workers, each
computing local gradients, then performing an AllReduce followed by an
SGD update. Because all workers live in the same process they share a
single Arc<RwLock<HashMap>> so weight broadcasts are free.
Implementations§
Source§impl DataParallelModel
impl DataParallelModel
Sourcepub fn new(
weights: HashMap<String, Vec<f32>>,
config: DistributedConfig,
) -> Self
pub fn new( weights: HashMap<String, Vec<f32>>, config: DistributedConfig, ) -> Self
Create a new data-parallel model with the given weight map and config.
Sourcepub fn weights(&self) -> HashMap<String, Vec<f32>>
pub fn weights(&self) -> HashMap<String, Vec<f32>>
Return a snapshot of the current weight map.
Sourcepub fn step(
&self,
local_grads: Vec<GradientBuffer>,
learning_rate: f32,
) -> ModelResult<()>
pub fn step( &self, local_grads: Vec<GradientBuffer>, learning_rate: f32, ) -> ModelResult<()>
Apply a gradient update using the configured strategy.
For AllReduce with world_size > 1 this pushes local gradients to the
SharedGradientStore and then applies the averaged result. For single-
worker or NoSync modes the update is applied directly.
§Errors
Propagates gradient-store and weight-lock errors.
Sourcepub fn broadcast_weights(&self) -> ModelResult<()>
pub fn broadcast_weights(&self) -> ModelResult<()>
Broadcast weights from rank 0 to all ranks.
In-process: all workers already share the same Arc, so this is a
no-op that succeeds immediately.
Auto Trait Implementations§
impl Freeze for DataParallelModel
impl RefUnwindSafe for DataParallelModel
impl Send for DataParallelModel
impl Sync for DataParallelModel
impl Unpin for DataParallelModel
impl UnsafeUnpin for DataParallelModel
impl UnwindSafe for DataParallelModel
Blanket Implementations§
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
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