pub struct Trainer { /* private fields */ }Expand description
Training utilities with scheduler, metrics, and validation
Implementations§
Source§impl Trainer
impl Trainer
Sourcepub fn new(model: TrainableSSM, config: TrainingConfig) -> CoreResult<Self>
pub fn new(model: TrainableSSM, config: TrainingConfig) -> CoreResult<Self>
Create a new trainer
Sourcepub fn train_epoch<F>(
&mut self,
data_loader: &[(Tensor, Tensor)],
loss_fn: F,
) -> CoreResult<f32>
pub fn train_epoch<F>( &mut self, data_loader: &[(Tensor, Tensor)], loss_fn: F, ) -> CoreResult<f32>
Train for one epoch
Sourcepub fn evaluate<F>(
&self,
data_loader: &[(Tensor, Tensor)],
loss_fn: F,
) -> CoreResult<f32>
pub fn evaluate<F>( &self, data_loader: &[(Tensor, Tensor)], loss_fn: F, ) -> CoreResult<f32>
Evaluate on validation data
Sourcepub fn fit<F>(
&mut self,
train_loader: TimeSeriesDataLoader,
val_loader: Option<TimeSeriesDataLoader>,
loss_fn: F,
) -> CoreResult<()>
pub fn fit<F>( &mut self, train_loader: TimeSeriesDataLoader, val_loader: Option<TimeSeriesDataLoader>, loss_fn: F, ) -> CoreResult<()>
Full training loop with validation and early stopping
Sourcepub fn model(&self) -> &TrainableSSM
pub fn model(&self) -> &TrainableSSM
Get reference to the model
Sourcepub fn model_mut(&mut self) -> &mut TrainableSSM
pub fn model_mut(&mut self) -> &mut TrainableSSM
Get mutable reference to the model
Sourcepub fn metrics(&self) -> &TrainingMetrics
pub fn metrics(&self) -> &TrainingMetrics
Get reference to training metrics
Sourcepub fn metrics_mut(&mut self) -> &mut TrainingMetrics
pub fn metrics_mut(&mut self) -> &mut TrainingMetrics
Get mutable reference to training metrics
Sourcepub fn current_step(&self) -> usize
pub fn current_step(&self) -> usize
Get current training step
Sourcepub fn save_checkpoint<P: AsRef<Path>>(
&self,
path: P,
name: &str,
) -> CoreResult<()>
pub fn save_checkpoint<P: AsRef<Path>>( &self, path: P, name: &str, ) -> CoreResult<()>
Save checkpoint to disk
Saves model weights, optimizer state, training configuration, metrics, and metadata.
§Arguments
path- Directory to save checkpoint filesname- Checkpoint name (without extension)
§Example
ⓘ
trainer.save_checkpoint("checkpoints", "epoch_10")?;
// Creates: checkpoints/epoch_10.safetensors and checkpoints/epoch_10.jsonSourcepub fn load_checkpoint<P: AsRef<Path>>(
path: P,
name: &str,
model_config: KizzasiConfig,
) -> CoreResult<Self>
pub fn load_checkpoint<P: AsRef<Path>>( path: P, name: &str, model_config: KizzasiConfig, ) -> CoreResult<Self>
Load checkpoint and resume training
Creates a new Trainer from a saved checkpoint, restoring model weights, configuration, and training state.
§Arguments
path- Directory containing checkpoint filesname- Checkpoint name (without extension)model_config- Model configuration (must match saved model)
§Example
ⓘ
let trainer = Trainer::load_checkpoint("checkpoints", "epoch_10", model_config)?;
// Continue training from epoch 10Sourcepub fn save_checkpoint_auto<P: AsRef<Path>>(&self, path: P) -> CoreResult<()>
pub fn save_checkpoint_auto<P: AsRef<Path>>(&self, path: P) -> CoreResult<()>
Sourcepub fn save_best_checkpoint<P: AsRef<Path>>(&self, path: P) -> CoreResult<()>
pub fn save_best_checkpoint<P: AsRef<Path>>(&self, path: P) -> CoreResult<()>
Auto Trait Implementations§
impl Freeze for Trainer
impl !RefUnwindSafe for Trainer
impl !Send for Trainer
impl !Sync for Trainer
impl Unpin for Trainer
impl UnsafeUnpin for Trainer
impl !UnwindSafe for Trainer
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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