pub trait Optimizer {
// Required methods
fn zero_grad(&self);
fn step(&mut self) -> Result<()>;
fn learning_rate(&self) -> f32;
fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>;
fn step_count(&self) -> u64;
fn belongs_to(&self, runtime: &Runtime) -> bool;
// Provided method
fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()> { ... }
}Expand description
Common behavior exposed by an OA optimizer to training policy.
This contract deliberately excludes captured-program and persistence internals. Those capabilities depend on optimizer-specific state and are admitted separately only when their complete implementation exists.
Required Methods§
Sourcefn step(&mut self) -> Result<()>
fn step(&mut self) -> Result<()>
Record one logical parameter update.
§Errors
Returns an optimizer, validation, allocation, or runtime recording error.
Sourcefn learning_rate(&self) -> f32
fn learning_rate(&self) -> f32
Return the learning rate used by the next optimizer step.
Sourcefn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
Set the learning rate used by subsequent optimizer steps.
§Errors
Returns an error when the value is outside the optimizer’s contract or optimizer state cannot be updated safely.
Sourcefn step_count(&self) -> u64
fn step_count(&self) -> u64
Return the number of completed logical optimizer steps.
Sourcefn belongs_to(&self, runtime: &Runtime) -> bool
fn belongs_to(&self, runtime: &Runtime) -> bool
Return whether this optimizer can participate in work owned by runtime.
Provided Methods§
Sourcefn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>
fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>
Bind a device-resident finite flag gating captured updates.
The flag is a same-runtime FP32 single-element Matrix written by a
gradient scaler’s device check. When a bound optimizer records its
step inside an Runtime::capture program, the update kernels read the
flag at replay time: a nonzero flag applies the normal update and a
zero flag freezes parameters, moments, and the device step counter
exactly, so AMP overflow handling replays inside one captured
program without a mid-step host decision. Eager steps ignore the
binding; the host-side scaler gate owns that path.
§Errors
Returns an error when the optimizer does not admit gated captured updates or the flag contract is violated.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".