pub struct Learner<M: LearnerModel> { /* private fields */ }Expand description
Learner struct encapsulating all components necessary to train a Neural Network model.
Implementations§
Source§impl<M: LearnerModel> Learner<M>
impl<M: LearnerModel> Learner<M>
Sourcepub fn new(
model: M,
optim: ModuleOptimizer,
lr_scheduler: impl Into<ModuleLrScheduler>,
) -> Self
pub fn new( model: M, optim: ModuleOptimizer, lr_scheduler: impl Into<ModuleLrScheduler>, ) -> Self
Create a learner.
Source§impl<M: LearnerModel> Learner<M>
impl<M: LearnerModel> Learner<M>
Sourcepub fn lr_current(&self) -> ModuleLearningRate
pub fn lr_current(&self) -> ModuleLearningRate
Returns the current learning rate.
Sourcepub fn train_step(
&self,
item: <M as TrainStep>::Input,
) -> TrainOutput<<M as TrainStep>::Output>
pub fn train_step( &self, item: <M as TrainStep>::Input, ) -> TrainOutput<<M as TrainStep>::Output>
Sourcepub fn optimizer_step(&mut self, grads: GradientsParams)
pub fn optimizer_step(&mut self, grads: GradientsParams)
Optimize the current module with the provided gradients and learning rate.
§Arguments
optim: Optimizer used for learning.lr: The learning rate used for this step.grads: The gradients of each parameter in the current model.
Sourcepub fn optimizer_step_multi(&mut self, grads: MultiGradientsParams)
pub fn optimizer_step_multi(&mut self, grads: MultiGradientsParams)
Optimize the current module with the provided gradients and learning rate.
§Arguments
optim: Optimizer used for learning.lr: The learning rate used for this step.grads: Multiple gradients associated to each parameter in the current model.
Sourcepub fn load_model(&mut self, record: ModuleRecord)
pub fn load_model(&mut self, record: ModuleRecord)
Load the module state from a record.
Sourcepub fn load_optim(&mut self, record: OptimizerRecord)
pub fn load_optim(&mut self, record: OptimizerRecord)
Load the state of the learner’s optimizer from a record.
No device is needed: the optimizer state is migrated to each parameter’s device on the next
step (see ModuleOptimizer::load_record).
Sourcepub fn load_scheduler(&mut self, record: LrSchedulerRecord)
pub fn load_scheduler(&mut self, record: LrSchedulerRecord)
Load the state of the learner’s scheduler from a record.
Source§impl<M: LearnerModel> Learner<M>
impl<M: LearnerModel> Learner<M>
Sourcepub fn grad_sharded(&mut self)
pub fn grad_sharded(&mut self)
Mark the model as sharded across multiple devices.
Trait Implementations§
Auto Trait Implementations§
impl<M> !RefUnwindSafe for Learner<M>
impl<M> !UnwindSafe for Learner<M>
impl<M> Freeze for Learner<M>where
M: Freeze,
impl<M> Send for Learner<M>
impl<M> Sync for Learner<M>where
M: Sync,
impl<M> Unpin for Learner<M>where
M: Unpin,
impl<M> UnsafeUnpin for Learner<M>where
M: UnsafeUnpin,
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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