pub struct DistributedLayeredModel<M: LayerParallelism> { /* private fields */ }Expand description
A LayerParallelism model split across devices, holding where each of its layers runs so
the forward reads it rather than working it out again on every call. It is itself a
Module, so records, devices and training flags work as they do on the model alone.
Implementations§
Source§impl<M: LayerParallelism> DistributedLayeredModel<M>
impl<M: LayerParallelism> DistributedLayeredModel<M>
Sourcepub fn new(model: M, placement: &LayerPlacement) -> Self
pub fn new(model: M, placement: &LayerPlacement) -> Self
Split model across the devices placement gives its layers. Nothing moves: each layer is
built where it runs, and this checks it is.
§Panics
Panics when placement does not give a device to every hidden layer, or when a layer holds
a tensor off the device placement gives it.
Sourcepub fn placement(&self) -> &LayerPlacement
pub fn placement(&self) -> &LayerPlacement
Where each layer runs, which is where its own parameters are.
Sourcepub fn forward(
&self,
input: <M::InputLayer as DistributedLayer>::Input,
) -> <M::OutputLayer as DistributedLayer>::Output
pub fn forward( &self, input: <M::InputLayer as DistributedLayer>::Input, ) -> <M::OutputLayer as DistributedLayer>::Output
Run each layer on its device, moving what passes between them.
Sourcepub fn into_inner(self) -> M
pub fn into_inner(self) -> M
The model on its own, no longer carrying where its layers run.
Sourcepub fn into_stages(self) -> StagedLayers<M>
pub fn into_stages(self) -> StagedLayers<M>
The model taken apart, its hidden layers cut into the placement’s stages.
§Panics
Panics when a stage would hold a layer off its device, which is what an
into_layers giving the hidden layers in another order than
layers_hidden does.
Trait Implementations§
Source§impl<M: Clone + LayerParallelism> Clone for DistributedLayeredModel<M>
impl<M: Clone + LayerParallelism> Clone for DistributedLayeredModel<M>
Source§impl<M: Debug + LayerParallelism> Debug for DistributedLayeredModel<M>
impl<M: Debug + LayerParallelism> Debug for DistributedLayeredModel<M>
Source§impl<M: LayerParallelism> Module for DistributedLayeredModel<M>
A mapper is trusted to leave each parameter where it found it, so only a move of the whole
model rewrites the placement.
impl<M: LayerParallelism> Module for DistributedLayeredModel<M>
A mapper is trusted to leave each parameter where it found it, so only a move of the whole model rewrites the placement.
Source§fn collect_devices(&self, devices: Devices) -> Devices
fn collect_devices(&self, devices: Devices) -> Devices
Source§fn fork(self, device: &Device) -> Self
fn fork(self, device: &Device) -> Self
Source§fn to_device(self, device: &Device) -> Self
fn to_device(self, device: &Device) -> Self
Source§fn train(self) -> Self
fn train(self) -> Self
Source§fn valid(&self) -> Self
fn valid(&self) -> Self
Source§fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
Source§fn materialize(self) -> Self
fn materialize(self) -> Self
Source§fn devices(&self) -> Devices
fn devices(&self) -> Devices
Source§fn set_require_grad(self, require_grad: bool) -> Self
fn set_require_grad(self, require_grad: bool) -> Self
Source§fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
Source§fn no_grad(self) -> Self
fn no_grad(self) -> Self
Source§fn freeze_group(self, group: ParamGroup) -> Self
fn freeze_group(self, group: ParamGroup) -> Self
Source§fn unfreeze_group(self, group: ParamGroup) -> Self
fn unfreeze_group(self, group: ParamGroup) -> Self
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§fn quantize_weights_group(
self,
quantizer: &mut Quantizer,
group: ParamGroup,
) -> Self
fn quantize_weights_group( self, quantizer: &mut Quantizer, group: ParamGroup, ) -> Self
Source§fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
Reparameterizer. Read moreSource§fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
Source§fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
Source§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read moreSource§fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
Source§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read moreSource§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read moreSource§fn save_file<P: AsRef<Path>>(self, path: P) -> Result<(), RecordError>where
Self: Sized,
fn save_file<P: AsRef<Path>>(self, path: P) -> Result<(), RecordError>where
Self: Sized,
std only.Source§fn load_file<P: AsRef<Path>>(self, path: P) -> Selfwhere
Self: Sized,
fn load_file<P: AsRef<Path>>(self, path: P) -> Selfwhere
Self: Sized,
std only.Source§fn try_load_file<P: AsRef<Path>>(self, path: P) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_file<P: AsRef<Path>>(self, path: P) -> Result<Self, RecordError>where
Self: Sized,
std only.Auto Trait Implementations§
impl<M> Freeze for DistributedLayeredModel<M>where
M: Freeze,
impl<M> RefUnwindSafe for DistributedLayeredModel<M>where
M: RefUnwindSafe,
impl<M> Send for DistributedLayeredModel<M>
impl<M> Sync for DistributedLayeredModel<M>where
M: Sync,
impl<M> Unpin for DistributedLayeredModel<M>where
M: Unpin,
impl<M> UnsafeUnpin for DistributedLayeredModel<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for DistributedLayeredModel<M>where
M: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneExpand for Twhere
T: Clone,
impl<T> CloneExpand for Twhere
T: Clone,
fn __expand_clone_method(&self, _: &Scope) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
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