pub struct Sgd { /* private fields */ }Implementations§
Source§impl Sgd
impl Sgd
Sourcepub fn new(
parameters: impl IntoIterator<Item = Parameter>,
learning_rate: f32,
momentum: f32,
weight_decay: f32,
) -> Result<Self>
pub fn new( parameters: impl IntoIterator<Item = Parameter>, learning_rate: f32, momentum: f32, weight_decay: f32, ) -> Result<Self>
Bind SGD to a nonempty FP32 parameter set.
A positive momentum coefficient allocates one zero-initialized momentum tensor per parameter. Weight decay follows the donor kernels exactly.
§Errors
Returns an error for invalid hyperparameters, duplicate parameters, mixed-runtime ownership, or momentum allocation/upload failure.
Sourcepub fn new_with_groups(
groups: Vec<ParameterGroup>,
learning_rate: f32,
momentum: f32,
weight_decay: f32,
) -> Result<Self>
pub fn new_with_groups( groups: Vec<ParameterGroup>, learning_rate: f32, momentum: f32, weight_decay: f32, ) -> Result<Self>
Bind SGD over named parameter groups with differential treatment,
following the AdamW contract: lr_scale multiplies the base learning
rate, weight_decay replaces the optimizer default per group
(Some(0.0) excludes members), and frozen groups skip value and
momentum updates entirely.
§Errors
Returns the construction errors of the uniform constructor plus overlapping membership, empty groups, and invalid group scales.
Sourcepub fn step(&mut self) -> Result<()>
pub fn step(&mut self) -> Result<()>
Record one SGD update for every parameter carrying a gradient.
§Errors
Returns an error when the step counter is exhausted, a parameter contract changed, or runtime recording fails.
Sourcepub const fn learning_rate(&self) -> f32
pub const fn learning_rate(&self) -> f32
Return the learning rate used by the next step.
Sourcepub fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
pub fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
Set the learning rate used by subsequent steps.
§Errors
Returns an error when the value is not finite and non-negative.
Sourcepub const fn step_count(&self) -> u64
pub const fn step_count(&self) -> u64
Return the number of completed logical steps.
Trait Implementations§
Source§impl Optimizer for Sgd
impl Optimizer for Sgd
Source§fn learning_rate(&self) -> f32
fn learning_rate(&self) -> f32
Source§fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>
Source§fn step_count(&self) -> u64
fn step_count(&self) -> u64
Source§fn belongs_to(&self, runtime: &Runtime) -> bool
fn belongs_to(&self, runtime: &Runtime) -> bool
runtime.