Struct Learner
pub struct Learner<M>where
M: LearnerModel,{ /* private fields */ }Expand description
Learner struct encapsulating all components necessary to train a Neural Network model.
Implementations§
§impl<M> Learner<M>where
M: LearnerModel,
impl<M> Learner<M>where
M: LearnerModel,
pub fn new(
model: M,
optim: ModuleOptimizer,
lr_scheduler: impl Into<ModuleLrScheduler>,
) -> Learner<M>
pub fn new( model: M, optim: ModuleOptimizer, lr_scheduler: impl Into<ModuleLrScheduler>, ) -> Learner<M>
Create a learner.
§impl<M> Learner<M>where
M: LearnerModel,
impl<M> Learner<M>where
M: LearnerModel,
pub fn model(&self) -> M
pub fn model(&self) -> M
Returns the current model.
pub fn lr_current(&self) -> ModuleLearningRate
pub fn lr_current(&self) -> ModuleLearningRate
Returns the current learning rate.
pub fn lr_step(&mut self)
pub fn lr_step(&mut self)
Executes a step of the learning rate scheduler.
pub 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>
pub 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.
pub 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.
pub fn load_model(&mut self, record: ModuleRecord)
pub fn load_model(&mut self, record: ModuleRecord)
Load the module state from a record.
pub 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).
pub 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.
§impl<M> Learner<M>where
M: LearnerModel,
impl<M> Learner<M>where
M: LearnerModel,
pub 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,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
Compare self to
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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