Skip to main content

AdamW

Struct AdamW 

Source
pub struct AdamW { /* private fields */ }
Expand description

Decoupled-weight-decay Adam optimizer over stable Parameter handles.

Implementations§

Source§

impl AdamW

Source

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.

Source

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.

Source

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.

Source

pub fn zero_grad(&self)

Discard every currently accumulated parameter gradient.

Source

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.

Source

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.

Source

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.

Source

pub const fn learning_rate(&self) -> f32

Return the learning rate used by the next optimizer step.

Source

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.

Source

pub const fn step_count(&self) -> u32

Return the number of completed logical optimizer steps.

Trait Implementations§

Source§

impl Optimizer for AdamW

Source§

fn zero_grad(&self)

Discard every currently accumulated parameter gradient.
Source§

fn step(&mut self) -> Result<()>

Record one logical parameter update. Read more
Source§

fn learning_rate(&self) -> f32

Return the learning rate used by the next optimizer step.
Source§

fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>

Set the learning rate used by subsequent optimizer steps. Read more
Source§

fn step_count(&self) -> u64

Return the number of completed logical optimizer steps.
Source§

fn belongs_to(&self, runtime: &Runtime) -> bool

Return whether this optimizer can participate in work owned by runtime.
Source§

fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>

Bind a device-resident finite flag gating captured updates. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for AdamW

§

impl !Send for AdamW

§

impl !Sync for AdamW

§

impl !UnwindSafe for AdamW

§

impl Forget for AdamW

§

impl Freeze for AdamW
where *const u8 is !null: Freeze, PhantomData<MomentParameterState>: Freeze, *const RcInner<RefCell<RuntimeState>> is !null: Freeze, PhantomData<RcInner<RefCell<RuntimeState>>>: Freeze, *const RcInner<StorageInner> is !null: Freeze, PhantomData<RcInner<StorageInner>>: Freeze, PhantomData<usize>: Freeze, *const RcInner<MatrixSemantic> is !null: Freeze, PhantomData<RcInner<MatrixSemantic>>: Freeze, PhantomData<Rc<()>>: Freeze, PhantomData<AdamWGroupMeta>: Freeze,

§

impl Move for AdamW

§

impl Unpin for AdamW
where *const u8 is !null: Unpin, Rc<RefCell<ParameterState>>: Unpin, Rc<RefCell<RuntimeState>>: Unpin, Rc<StorageInner>: Unpin, Rc<MatrixSemantic>: Unpin, Rc<()>: Unpin,

§

impl UnsafeUnpin for AdamW
where *const u8 is !null: UnsafeUnpin, PhantomData<MomentParameterState>: UnsafeUnpin, *const RcInner<RefCell<RuntimeState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<RuntimeState>>>: UnsafeUnpin, *const RcInner<StorageInner> is !null: UnsafeUnpin, PhantomData<RcInner<StorageInner>>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, *const RcInner<MatrixSemantic> is !null: UnsafeUnpin, PhantomData<RcInner<MatrixSemantic>>: UnsafeUnpin, PhantomData<Rc<()>>: UnsafeUnpin, PhantomData<AdamWGroupMeta>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckpointOptimizer for T
where T: Optimizer + Persistence,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.