Skip to main content

SupervisedTraining

Struct SupervisedTraining 

pub struct SupervisedTraining<M>
where M: LearnerModel,
{ /* private fields */ }
Expand description

Structure to configure and launch supervised learning trainings.

Implementations§

§

impl<M> SupervisedTraining<M>
where M: LearnerModel,

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>>, ) -> SupervisedTraining<M>

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.
§

impl<M> SupervisedTraining<M>
where M: LearnerModel,

pub fn with_training_strategy( self, training_strategy: TrainingStrategy<M>, ) -> SupervisedTraining<M>

Replace the default training strategy (SingleDeviceTrainingStrategy) with the provided one.

§Arguments
  • training_strategy - The training strategy.

pub fn with_metric_logger<ML>(self, logger: ML) -> SupervisedTraining<M>
where ML: MetricLogger + 'static,

Replace the default metric loggers with the provided ones.

§Arguments
  • logger - The training logger.

pub fn with_progress_logger<PL>(self, logger: PL) -> SupervisedTraining<M>
where PL: TrainingProgressLogger + 'static,

Register a progress logger to track and store training progress.

§Example
ⓘ
// `MyTrainingProgressLogger` is a user-defined type that implements
// `burn_train::logger::TrainingProgressLogger`.
let learner = SupervisedTraining::new(...)
    .with_progress_logger(MyTrainingProgressLogger);

pub fn with_checkpointing_strategy<CS>( self, strategy: CS, ) -> SupervisedTraining<M>
where CS: CheckpointingStrategy + 'static,

Update the checkpointing_strategy.

pub fn renderer( self, renderer: Box<dyn MetricsRenderer>, ) -> SupervisedTraining<M>

Replace the default CLI renderer with a custom one.

§Arguments
  • renderer - The custom renderer.

pub fn metrics<Me>(self, metrics: Me) -> SupervisedTraining<M>
where Me: MetricRegistration<M>,

Register all metrics as numeric for the training and validation set.

pub fn metrics_text<Me>(self, metrics: Me) -> SupervisedTraining<M>

Register all metrics as text for the training and validation set.

pub fn metric_train<Me>(self, metric: Me) -> SupervisedTraining<M>
where Me: Metric + 'static, <M as TrainStep>::Output: Adaptor<<Me as Metric>::Input>,

Register a training metric.

pub fn metric_valid<Me>(self, metric: Me) -> SupervisedTraining<M>
where Me: Metric + 'static, <M as InferenceStep>::Output: Adaptor<<Me as Metric>::Input>,

Register a validation metric.

pub fn grads_accumulation(self, accumulation: usize) -> SupervisedTraining<M>

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.

pub fn gradient_checkpointing(self) -> SupervisedTraining<M>

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.

pub fn metric_train_numeric<Me>(self, metric: Me) -> SupervisedTraining<M>
where Me: Metric + Numeric + 'static, <M as TrainStep>::Output: Adaptor<<Me as Metric>::Input>,

Register a numeric training metric.

pub fn metric_valid_numeric<Me>(self, metric: Me) -> SupervisedTraining<M>
where Me: Metric + Numeric + 'static, <M as InferenceStep>::Output: Adaptor<<Me as Metric>::Input>,

Register a numeric validation metric.

pub fn num_epochs(self, num_epochs: usize) -> SupervisedTraining<M>

The number of epochs the training should last.

pub fn checkpoint(self, checkpoint: usize) -> SupervisedTraining<M>

The epoch from which the training must resume.

pub fn interrupter(&self) -> Interrupter

Provides a handle that can be used to interrupt training.

pub fn with_interrupter(self, interrupter: Interrupter) -> SupervisedTraining<M>

Override the handle for stopping training with an externally provided handle

pub fn early_stopping<Strategy>( self, strategy: Strategy, ) -> SupervisedTraining<M>
where Strategy: EarlyStoppingStrategy + Clone + Send + Sync + 'static,

Register an early stopping strategy to stop the training when the conditions are meet.

pub fn with_application_logger( self, logger: Option<Box<dyn ApplicationLoggerInstaller>>, ) -> SupervisedTraining<M>

By default, Rust logs are captured and written into experiment.log. If disabled, standard Rust log handling will apply.

pub fn with_default_checkpointers(self) -> SupervisedTraining<M>

Register a checkpointer that will save the optimizer, the model and the learning rate scheduler to separate burnpack files.

pub fn with_custom_checkpointers<CM, CO, CL>( self, module_checkpointer: CM, optimizer_checkpointer: CO, lr_checkpointer: CL, ) -> SupervisedTraining<M>
where 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.

pub fn summary(self) -> SupervisedTraining<M>

Enable the training summary report.

The summary will be displayed after .fit(), when the renderer is dropped.

pub fn label(self, label: &str) -> SupervisedTraining<M>

Set a label for this training, making it easier to differentiate multiple runs.

§

impl<M> SupervisedTraining<M>
where M: LearnerModel,

pub fn launch(self, learner: Learner<M>) -> LearningResult<M>

Launch this training with the given Learner.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Adaptor<()> for T

§

fn adapt(&self)

Adapt the type to be passed to a metric.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more