Trait TrainStep
pub trait TrainStep {
type Input: Send + 'static;
type Output: ItemLazy + 'static;
// Required method
fn step(&self, item: Self::Input) -> TrainOutput<Self::Output>;
// Provided methods
fn optimize(
self,
optim: &mut ModuleOptimizer,
lr_module: ModuleLearningRate,
grads: GradientsParams,
) -> Self
where Self: Sized + Module { ... }
fn optimize_multi(
self,
optim: &mut ModuleOptimizer,
lr_module: ModuleLearningRate,
grads: MultiGradientsParams,
) -> Self
where Self: Sized + Module { ... }
}Expand description
Trait to be implemented for models to be able to be trained.
The step method needs to be manually implemented for all structs.
The optimize method can be overridden if you want to control how the optimizer is used to update the model. This can be useful if you want to call custom mutable functions on your model (e.g., clipping the weights) before or after the optimizer is used.
§Notes
To be used with the Learner struct, the struct which implements this trait must also implement the Module trait, which is done automatically with its derive.
Required Associated Types§
Required Methods§
Provided Methods§
fn optimize(
self,
optim: &mut ModuleOptimizer,
lr_module: ModuleLearningRate,
grads: GradientsParams,
) -> Self
fn optimize( self, optim: &mut ModuleOptimizer, lr_module: ModuleLearningRate, grads: GradientsParams, ) -> Self
fn optimize_multi(
self,
optim: &mut ModuleOptimizer,
lr_module: ModuleLearningRate,
grads: MultiGradientsParams,
) -> Self
fn optimize_multi( self, optim: &mut ModuleOptimizer, lr_module: ModuleLearningRate, grads: MultiGradientsParams, ) -> Self
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".