pub struct SupervisedTraining<M: LearnerModel> { /* private fields */ }Expand description
Structure to configure and launch supervised learning trainings.
Implementations§
Source§impl<M: LearnerModel> SupervisedTraining<M>
impl<M: LearnerModel> SupervisedTraining<M>
Sourcepub fn new(
directory: impl AsRef<Path>,
dataloader_train: Arc<dyn DataLoader<<M as TrainStep>::Input>>,
dataloader_valid: Arc<dyn DataLoader<<M as InferenceStep>::Input>>,
) -> Self
pub fn new( directory: impl AsRef<Path>, dataloader_train: Arc<dyn DataLoader<<M as TrainStep>::Input>>, dataloader_valid: Arc<dyn DataLoader<<M 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<M: LearnerModel> SupervisedTraining<M>
impl<M: LearnerModel> SupervisedTraining<M>
Sourcepub fn with_training_strategy(
self,
training_strategy: TrainingStrategy<M>,
) -> Self
pub fn with_training_strategy( self, training_strategy: TrainingStrategy<M>, ) -> Self
Replace the default training strategy (SingleDeviceTrainingStrategy) with the provided one.
§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_progress_logger<PL>(self, logger: PL) -> Selfwhere
PL: TrainingProgressLogger + 'static,
pub fn with_progress_logger<PL>(self, logger: PL) -> Selfwhere
PL: TrainingProgressLogger + '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(self, renderer: Box<dyn MetricsRenderer + 'static>) -> Self
pub fn renderer(self, renderer: Box<dyn MetricsRenderer + 'static>) -> Self
Sourcepub fn metrics<Me: MetricRegistration<M>>(self, metrics: Me) -> Self
pub fn metrics<Me: MetricRegistration<M>>(self, metrics: Me) -> Self
Register all metrics as numeric for the training and validation set.
Sourcepub fn metrics_text<Me: TextMetricRegistration<M>>(self, metrics: Me) -> Self
pub fn metrics_text<Me: TextMetricRegistration<M>>(self, metrics: Me) -> Self
Register all metrics as text for the training and validation set.
Sourcepub fn metric_train<Me: Metric + 'static>(self, metric: Me) -> Self
pub fn metric_train<Me: Metric + 'static>(self, metric: Me) -> Self
Register a training metric.
Sourcepub fn metric_valid<Me: Metric + 'static>(self, metric: Me) -> Self
pub fn metric_valid<Me: Metric + 'static>(self, metric: Me) -> Self
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.
§Panics
Panics if accumulation is zero.
Sourcepub fn gradient_checkpointing(self) -> Self
pub fn gradient_checkpointing(self) -> Self
Enables autodiff checkpointing.
§Notes
Gradient checkpointing recomputes activations during backpropagation for operations marked as memory-bound, while compute-bound operations still cache their output. This reduces peak memory usage at the cost of additional computation for memory-bound ops.
Sourcepub fn metric_train_numeric<Me>(self, metric: Me) -> Self
pub fn metric_train_numeric<Me>(self, metric: Me) -> Self
Sourcepub fn metric_valid_numeric<Me: Metric + Numeric + 'static>(
self,
metric: Me,
) -> Self
pub fn metric_valid_numeric<Me: Metric + Numeric + 'static>( self, metric: Me, ) -> Self
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_default_checkpointers(self) -> Self
pub fn with_default_checkpointers(self) -> Self
Register a checkpointer that will save the optimizer, the model and the learning rate scheduler to separate burnpack files.
Sourcepub fn with_custom_checkpointers<CM, CO, CL>(
self,
module_checkpointer: CM,
optimizer_checkpointer: CO,
lr_checkpointer: CL,
) -> Selfwhere
CM: Checkpointer<ModuleRecord> + 'static,
CO: Checkpointer<OptimizerRecord> + 'static,
CL: Checkpointer<LrSchedulerRecord> + 'static,
pub fn with_custom_checkpointers<CM, CO, CL>(
self,
module_checkpointer: CM,
optimizer_checkpointer: CO,
lr_checkpointer: CL,
) -> Selfwhere
CM: Checkpointer<ModuleRecord> + 'static,
CO: Checkpointer<OptimizerRecord> + 'static,
CL: Checkpointer<LrSchedulerRecord> + 'static,
Register your own checkpointers that will save the optimizer, the model and the learning rate scheduler to separate burnpack files.
Source§impl<M: LearnerModel> SupervisedTraining<M>
impl<M: LearnerModel> SupervisedTraining<M>
Sourcepub fn launch(self, learner: Learner<M>) -> LearningResult<M>
pub fn launch(self, learner: Learner<M>) -> LearningResult<M>
Launch this training with the given Learner.
Auto Trait Implementations§
impl<M> !RefUnwindSafe for SupervisedTraining<M>
impl<M> !Send for SupervisedTraining<M>
impl<M> !Sync for SupervisedTraining<M>
impl<M> !UnwindSafe for SupervisedTraining<M>
impl<M> Freeze for SupervisedTraining<M>where
MetricsTraining<<M as TrainStep>::Output, <M as InferenceStep>::Output>: Freeze,
Option<TrainingStrategy<M>>: Freeze,
Arc<dyn DataLoader<<M as TrainStep>::Input>>: Freeze,
Arc<dyn DataLoader<<M as InferenceStep>::Input>>: Freeze,
impl<M> Unpin for SupervisedTraining<M>where
MetricsTraining<<M as TrainStep>::Output, <M as InferenceStep>::Output>: Unpin,
Option<TrainingStrategy<M>>: Unpin,
Arc<dyn DataLoader<<M as TrainStep>::Input>>: Unpin,
Arc<dyn DataLoader<<M as InferenceStep>::Input>>: Unpin,
impl<M> UnsafeUnpin for SupervisedTraining<M>where
MetricsTraining<<M as TrainStep>::Output, <M as InferenceStep>::Output>: UnsafeUnpin,
Option<TrainingStrategy<M>>: UnsafeUnpin,
Arc<dyn DataLoader<<M as TrainStep>::Input>>: UnsafeUnpin,
Arc<dyn DataLoader<<M as InferenceStep>::Input>>: 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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