pub trait Optimizer: Sized {
type Config: Sized;
// Required methods
fn new(vars: Vec<Var>, config: Self::Config) -> Result<Self>;
fn step(&mut self, grads: &GradStore) -> Result<()>;
fn learning_rate(&self) -> f64;
fn set_learning_rate(&mut self, lr: f64);
// Provided methods
fn empty(config: Self::Config) -> Result<Self> { ... }
fn backward_step(&mut self, loss: &Tensor) -> Result<()> { ... }
fn from_slice(vars: &[&Var], config: Self::Config) -> Result<Self> { ... }
}
Expand description
The interface optimizers should implement.
Required Associated Types§
Required Methods§
fn new(vars: Vec<Var>, config: Self::Config) -> Result<Self>
fn step(&mut self, grads: &GradStore) -> Result<()>
fn learning_rate(&self) -> f64
fn set_learning_rate(&mut self, lr: f64)
Provided Methods§
fn empty(config: Self::Config) -> Result<Self>
fn backward_step(&mut self, loss: &Tensor) -> Result<()>
fn from_slice(vars: &[&Var], config: Self::Config) -> Result<Self>
Object Safety§
This trait is not object safe.