Skip to main content

TrainingCallback

Trait TrainingCallback 

Source
pub trait TrainingCallback: Send + Sync {
    // Required method
    fn on_epoch_end(&mut self, metrics: &EpochMetrics) -> CallbackAction;

    // Provided method
    fn on_training_end(&mut self) { ... }
}
Expand description

Trait for user-supplied training callbacks.

Implement this to add custom logging, checkpointing, or stopping criteria during training.

§Example

struct PrintLogger;

impl TrainingCallback for PrintLogger {
    fn on_epoch_end(&mut self, metrics: &EpochMetrics) -> CallbackAction {
        println!("Epoch {}: loss={:.4}", metrics.epoch, metrics.train_loss);
        CallbackAction::Continue
    }
}

Required Methods§

Source

fn on_epoch_end(&mut self, metrics: &EpochMetrics) -> CallbackAction

Called at the end of each training epoch.

Return CallbackAction::Stop to halt training early.

Provided Methods§

Source

fn on_training_end(&mut self)

Called when training finishes (after the last epoch).

Default implementation does nothing.

Implementors§