Struct Learner
pub struct Learner<LC>where
LC: LearningComponentsTypes,{ /* private fields */ }Expand description
Learner struct encapsulating all components necessary to train a Neural Network model.
Implementations§
§impl<B, LR, M, O> Learner<LearningComponentsMarker<B, LR, M, O>>where
B: AutodiffBackend,
LR: LrScheduler + 'static,
M: TrainStep + AutodiffModule<B> + Display + 'static,
<M as AutodiffModule<B>>::InnerModule: InferenceStep,
O: Optimizer<M, B> + 'static,
impl<B, LR, M, O> Learner<LearningComponentsMarker<B, LR, M, O>>where
B: AutodiffBackend,
LR: LrScheduler + 'static,
M: TrainStep + AutodiffModule<B> + Display + 'static,
<M as AutodiffModule<B>>::InnerModule: InferenceStep,
O: Optimizer<M, B> + 'static,
pub fn new(
model: M,
optim: O,
lr_scheduler: LR,
) -> Learner<LearningComponentsMarker<B, LR, M, O>>
pub fn new( model: M, optim: O, lr_scheduler: LR, ) -> Learner<LearningComponentsMarker<B, LR, M, O>>
Create a learner.
§impl<LC> Learner<LC>where
LC: LearningComponentsTypes,
impl<LC> Learner<LC>where
LC: LearningComponentsTypes,
pub fn fork(
&mut self,
device: &<<LC as LearningComponentsTypes>::Backend as Backend>::Device,
)
pub fn fork( &mut self, device: &<<LC as LearningComponentsTypes>::Backend as Backend>::Device, )
Fork the learner’s model to the given device.
pub fn model(&self) -> <LC as LearningComponentsTypes>::TrainingModel
pub fn model(&self) -> <LC as LearningComponentsTypes>::TrainingModel
Returns the current model.
pub fn lr_current(&self) -> f64
pub fn lr_current(&self) -> f64
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: <<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Input,
) -> TrainOutput<<<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Output>
pub fn train_step( &self, item: <<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Input, ) -> TrainOutput<<<LC as LearningComponentsTypes>::TrainingModel 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: <<LC as LearningComponentsTypes>::TrainingModel as Module<<LC as LearningComponentsTypes>::Backend>>::Record,
)
pub fn load_model( &mut self, record: <<LC as LearningComponentsTypes>::TrainingModel as Module<<LC as LearningComponentsTypes>::Backend>>::Record, )
Load the module state from a record.
pub fn load_optim(
&mut self,
record: <<LC as LearningComponentsTypes>::Optimizer as Optimizer<<LC as LearningComponentsTypes>::TrainingModel, <LC as LearningComponentsTypes>::Backend>>::Record,
)
pub fn load_optim( &mut self, record: <<LC as LearningComponentsTypes>::Optimizer as Optimizer<<LC as LearningComponentsTypes>::TrainingModel, <LC as LearningComponentsTypes>::Backend>>::Record, )
Load the state of the learner’s optimizer as a record.
pub fn load_scheduler(
&mut self,
record: <<LC as LearningComponentsTypes>::LrScheduler as LrScheduler>::Record<<LC as LearningComponentsTypes>::Backend>,
)
pub fn load_scheduler( &mut self, record: <<LC as LearningComponentsTypes>::LrScheduler as LrScheduler>::Record<<LC as LearningComponentsTypes>::Backend>, )
Load the state of the learner’s scheduler as a record.
Trait Implementations§
Auto Trait Implementations§
impl<LC> Freeze for Learner<LC>where
<LC as LearningComponentsTypes>::TrainingModel: Freeze,
<LC as LearningComponentsTypes>::Optimizer: Freeze,
<LC as LearningComponentsTypes>::LrScheduler: Freeze,
impl<LC> RefUnwindSafe for Learner<LC>where
<LC as LearningComponentsTypes>::TrainingModel: RefUnwindSafe,
<LC as LearningComponentsTypes>::Optimizer: RefUnwindSafe,
<LC as LearningComponentsTypes>::LrScheduler: RefUnwindSafe,
impl<LC> Send for Learner<LC>
impl<LC> Sync for Learner<LC>where
<LC as LearningComponentsTypes>::TrainingModel: Sync,
<LC as LearningComponentsTypes>::Optimizer: Sync,
impl<LC> Unpin for Learner<LC>where
<LC as LearningComponentsTypes>::TrainingModel: Unpin,
<LC as LearningComponentsTypes>::Optimizer: Unpin,
<LC as LearningComponentsTypes>::LrScheduler: Unpin,
impl<LC> UnwindSafe for Learner<LC>where
<LC as LearningComponentsTypes>::TrainingModel: UnwindSafe,
<LC as LearningComponentsTypes>::Optimizer: UnwindSafe,
<LC as LearningComponentsTypes>::LrScheduler: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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