pub trait Optimizer {
// Required methods
fn step(&mut self);
fn zero_grad(&mut self);
fn lr(&self) -> f32;
fn set_lr(&mut self, lr: f32);
}Expand description
Common trait for all optimizers.
Required Methods§
Sourcefn step(&mut self)
fn step(&mut self)
Marks the optimizer as having stepped. This does NOT update parameters.
Gradients live in a global autograd graph keyed by tensor id, so an
optimizer (which holds only parameter ids + state) cannot reach the
parameter tensors from here. To actually apply updates, call
step_with_params(&mut params) (e.g.
sgd.step_with_params(&mut model.parameters_mut())). Canonical training
loop: clear_graph(); let loss = ...; loss.backward(); opt.step_with_params(&mut model.parameters_mut());
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".