pub struct SupervisedTraining<LC>where
LC: LearningComponentsTypes,{ /* private fields */ }Expand description
Structure to configure and launch supervised learning trainings.
Implementations§
Source§impl<B, LR, M, O> SupervisedTraining<LearningComponentsMarker<B, LR, M, O>>where
B: AutodiffBackend,
LR: LrScheduler + 'static,
M: TrainStep + AutodiffModule<B> + Display + 'static,
M::InnerModule: InferenceStep,
O: Optimizer<M, B> + 'static,
impl<B, LR, M, O> SupervisedTraining<LearningComponentsMarker<B, LR, M, O>>where
B: AutodiffBackend,
LR: LrScheduler + 'static,
M: TrainStep + AutodiffModule<B> + Display + 'static,
M::InnerModule: InferenceStep,
O: Optimizer<M, B> + 'static,
Sourcepub fn new(
directory: impl AsRef<Path>,
dataloader_train: Arc<dyn DataLoader<B, M::Input>>,
dataloader_valid: Arc<dyn DataLoader<B::InnerBackend, <M::InnerModule as InferenceStep>::Input>>,
) -> Self
pub fn new( directory: impl AsRef<Path>, dataloader_train: Arc<dyn DataLoader<B, M::Input>>, dataloader_valid: Arc<dyn DataLoader<B::InnerBackend, <M::InnerModule as InferenceStep>::Input>>, ) -> Self
Creates a new runner for a supervised training.
§Arguments
directory- The directory to save the checkpoints.dataloader_train- The dataloader for the training split.dataloader_valid- The dataloader for the validation split.
Source§impl<LC: LearningComponentsTypes> SupervisedTraining<LC>
impl<LC: LearningComponentsTypes> SupervisedTraining<LC>
Sourcepub fn with_training_strategy(
self,
training_strategy: TrainingStrategy<LC>,
) -> Self
pub fn with_training_strategy( self, training_strategy: TrainingStrategy<LC>, ) -> Self
Replace the default training strategy (SingleDeviceTrainingStrategy) with the provided ones.
§Arguments
training_strategy- The training strategy.
Sourcepub fn with_metric_logger<ML>(self, logger: ML) -> Selfwhere
ML: MetricLogger + 'static,
pub fn with_metric_logger<ML>(self, logger: ML) -> Selfwhere
ML: MetricLogger + 'static,
Sourcepub fn with_checkpointing_strategy<CS: CheckpointingStrategy + 'static>(
self,
strategy: CS,
) -> Self
pub fn with_checkpointing_strategy<CS: CheckpointingStrategy + 'static>( self, strategy: CS, ) -> Self
Update the checkpointing_strategy.
Sourcepub fn renderer<MR>(self, renderer: MR) -> Selfwhere
MR: MetricsRenderer + 'static,
pub fn renderer<MR>(self, renderer: MR) -> Selfwhere
MR: MetricsRenderer + 'static,
Sourcepub fn metrics<Me: MetricRegistration<LC>>(self, metrics: Me) -> Self
pub fn metrics<Me: MetricRegistration<LC>>(self, metrics: Me) -> Self
Register all metrics as numeric for the training and validation set.
Sourcepub fn metrics_text<Me: TextMetricRegistration<LC>>(self, metrics: Me) -> Self
pub fn metrics_text<Me: TextMetricRegistration<LC>>(self, metrics: Me) -> Self
Register all metrics as numeric for the training and validation set.
Sourcepub fn metric_train<Me: Metric + 'static>(self, metric: Me) -> Selfwhere
<<<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
pub fn metric_train<Me: Metric + 'static>(self, metric: Me) -> Selfwhere
<<<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
Register a training metric.
Sourcepub fn metric_valid<Me: Metric + 'static>(self, metric: Me) -> Selfwhere
<<<LC as LearningComponentsTypes>::InferenceModel as InferenceStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
pub fn metric_valid<Me: Metric + 'static>(self, metric: Me) -> Selfwhere
<<<LC as LearningComponentsTypes>::InferenceModel as InferenceStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
Register a validation metric.
Sourcepub fn grads_accumulation(self, accumulation: usize) -> Self
pub fn grads_accumulation(self, accumulation: usize) -> Self
Enable gradients accumulation.
§Notes
When you enable gradients accumulation, the gradients object used by the optimizer will be the sum of all gradients generated by each backward pass. It might be a good idea to reduce the learning to compensate.
The effect is similar to increasing the batch size and the learning rate by the accumulation
amount.
Sourcepub fn metric_train_numeric<Me>(self, metric: Me) -> Selfwhere
Me: Metric + Numeric + 'static,
<<<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
pub fn metric_train_numeric<Me>(self, metric: Me) -> Selfwhere
Me: Metric + Numeric + 'static,
<<<LC as LearningComponentsTypes>::TrainingModel as TrainStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
Sourcepub fn metric_valid_numeric<Me: Metric + Numeric + 'static>(
self,
metric: Me,
) -> Selfwhere
<<<LC as LearningComponentsTypes>::InferenceModel as InferenceStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
pub fn metric_valid_numeric<Me: Metric + Numeric + 'static>(
self,
metric: Me,
) -> Selfwhere
<<<LC as LearningComponentsTypes>::InferenceModel as InferenceStep>::Output as ItemLazy>::ItemSync: Adaptor<Me::Input>,
Sourcepub fn num_epochs(self, num_epochs: usize) -> Self
pub fn num_epochs(self, num_epochs: usize) -> Self
The number of epochs the training should last.
Sourcepub fn checkpoint(self, checkpoint: usize) -> Self
pub fn checkpoint(self, checkpoint: usize) -> Self
The epoch from which the training must resume.
Sourcepub fn interrupter(&self) -> Interrupter
pub fn interrupter(&self) -> Interrupter
Provides a handle that can be used to interrupt training.
Sourcepub fn with_interrupter(self, interrupter: Interrupter) -> Self
pub fn with_interrupter(self, interrupter: Interrupter) -> Self
Override the handle for stopping training with an externally provided handle
Sourcepub fn early_stopping<Strategy>(self, strategy: Strategy) -> Self
pub fn early_stopping<Strategy>(self, strategy: Strategy) -> Self
Register an early stopping strategy to stop the training when the conditions are meet.
Sourcepub fn with_application_logger(
self,
logger: Option<Box<dyn ApplicationLoggerInstaller>>,
) -> Self
pub fn with_application_logger( self, logger: Option<Box<dyn ApplicationLoggerInstaller>>, ) -> Self
By default, Rust logs are captured and written into
experiment.log. If disabled, standard Rust log handling
will apply.
Sourcepub fn with_file_checkpointer<FR>(self, recorder: FR) -> Selfwhere
FR: FileRecorder<<LC as LearningComponentsTypes>::Backend> + 'static + FileRecorder<<<LC as LearningComponentsTypes>::Backend as AutodiffBackend>::InnerBackend>,
pub fn with_file_checkpointer<FR>(self, recorder: FR) -> Selfwhere
FR: FileRecorder<<LC as LearningComponentsTypes>::Backend> + 'static + FileRecorder<<<LC as LearningComponentsTypes>::Backend as AutodiffBackend>::InnerBackend>,
Source§impl<LC: LearningComponentsTypes + Send + 'static> SupervisedTraining<LC>
impl<LC: LearningComponentsTypes + Send + 'static> SupervisedTraining<LC>
Sourcepub fn launch(
self,
learner: Learner<LC>,
) -> LearningResult<<LC as LearningComponentsTypes>::InferenceModel>
pub fn launch( self, learner: Learner<LC>, ) -> LearningResult<<LC as LearningComponentsTypes>::InferenceModel>
Launch this training with the given Learner.
Auto Trait Implementations§
impl<LC> Freeze for SupervisedTraining<LC>
impl<LC> !RefUnwindSafe for SupervisedTraining<LC>
impl<LC> !Send for SupervisedTraining<LC>
impl<LC> !Sync for SupervisedTraining<LC>
impl<LC> Unpin for SupervisedTraining<LC>
impl<LC> !UnwindSafe for SupervisedTraining<LC>
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> 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