pub struct AdamW { /* private fields */ }Expand description
Decoupled-weight-decay Adam optimizer over stable Parameter handles.
Implementations§
Source§impl AdamW
impl AdamW
Sourcepub fn new(
parameters: impl IntoIterator<Item = Parameter>,
learning_rate: f32,
) -> Result<Self>
pub fn new( parameters: impl IntoIterator<Item = Parameter>, learning_rate: f32, ) -> Result<Self>
Bind AdamW to a nonempty parameter set using standard OA defaults.
§Errors
Returns an error when the parameter set is empty, learning rate is not finite and non-negative, a parameter handle appears more than once, or moment allocation fails.
Sourcepub fn new_with_hyperparameters(
parameters: impl IntoIterator<Item = Parameter>,
learning_rate: f32,
beta1: f32,
beta2: f32,
epsilon: f32,
weight_decay: f32,
) -> Result<Self>
pub fn new_with_hyperparameters( parameters: impl IntoIterator<Item = Parameter>, learning_rate: f32, beta1: f32, beta2: f32, epsilon: f32, weight_decay: f32, ) -> Result<Self>
Bind AdamW with explicit scalar hyperparameters.
§Errors
Returns an error for non-finite or out-of-range scalars, an empty or duplicate parameter set, mixed-runtime ownership, or moment allocation.
Sourcepub fn new_with_groups(
groups: Vec<ParameterGroup>,
learning_rate: f32,
beta1: f32,
beta2: f32,
epsilon: f32,
weight_decay: f32,
) -> Result<Self>
pub fn new_with_groups( groups: Vec<ParameterGroup>, learning_rate: f32, beta1: f32, beta2: f32, epsilon: f32, weight_decay: f32, ) -> Result<Self>
Bind AdamW over named parameter groups with differential treatment.
Group membership must be disjoint; the concatenated membership is the
optimizer’s parameter set. lr_scale multiplies the base learning
rate per group, weight_decay replaces the optimizer default per
group (Some(0.0) excludes members from decay), and frozen groups
skip value and moment updates entirely. Non-uniform groups are an
eager execution contract: captured step recording rejects them
clearly rather than baking uniform scalars over differential groups.
§Errors
Returns the construction errors of Self::new_with_hyperparameters
plus overlapping membership, empty groups, and non-finite or negative
group scales.
Sourcepub fn step(&mut self) -> Result<()>
pub fn step(&mut self) -> Result<()>
Record one AdamW update for every parameter carrying a gradient.
Parameter and moment storage is updated in place while the stable
Parameter handle advances its mutation version. No submission or waiting
occurs here.
§Errors
Returns an error when the step counter is exhausted, a gradient contract changed, or allocation/runtime recording fails.
Sourcepub fn parameters(&self) -> Vec<Parameter>
pub fn parameters(&self) -> Vec<Parameter>
Clone the bound parameter handles in construction order.
Scaled training loops need the parameter set to unscale gradients in-graph; the clones share device state with the optimizer’s own.
Sourcepub fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>
pub fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>
Bind a device-resident finite flag gating captured replayed updates.
With a flag bound, step inside Runtime::capture records the gated
kernels: the device step counter and every parameter, first-moment, and
second-moment write are selected against their prior values when the
flag is zero, which freezes the update exactly as a skipped
torch.cuda.amp step does. GradScaler::record_finite_gate produces
the flag each replayed step.
§Errors
Returns an error when the flag is not a same-runtime single-element F32 matrix.
Sourcepub const fn learning_rate(&self) -> f32
pub const fn learning_rate(&self) -> f32
Return the learning rate used by the next optimizer 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 eager or captured steps.
A captured program reads optimizer scalars from graph-resident state. This method updates that state only after its prior GPU use is complete, so a scheduler changes the existing program rather than silently changing only the host-side optimizer.
§Errors
Returns an error when learning_rate is not finite and non-negative, when a
captured optimizer state is still in flight, or when its host upload fails.
Sourcepub const fn step_count(&self) -> u32
pub const fn step_count(&self) -> u32
Return the number of completed logical optimizer steps.
Trait Implementations§
Source§impl Optimizer for AdamW
impl Optimizer for AdamW
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.