pub struct AdamW { /* private fields */ }Expand description
AdamW optimizer (Adam with decoupled weight decay).
Unlike standard Adam which applies L2 regularization to the gradient,
AdamW applies weight decay directly to the parameters.
Update rule:
m_t = beta1 * m_{t-1} + (1 - beta1) * grad
v_t = beta2 * v_{t-1} + (1 - beta2) * grad^2
m_hat = m_t / (1 - beta1^t)
v_hat = v_t / (1 - beta2^t)
param = param - lr * (m_hat / (sqrt(v_hat) + eps) + weight_decay * param)Implementations§
Source§impl AdamW
impl AdamW
Sourcepub fn new(params: Vec<Parameter>, lr: f32) -> Self
pub fn new(params: Vec<Parameter>, lr: f32) -> Self
Creates a new AdamW optimizer with default hyperparameters.
Sourcepub fn with_betas(params: Vec<Parameter>, lr: f32, betas: (f32, f32)) -> Self
pub fn with_betas(params: Vec<Parameter>, lr: f32, betas: (f32, f32)) -> Self
Creates AdamW with specified betas.
Sourcepub fn with_options(
params: Vec<Parameter>,
lr: f32,
betas: (f32, f32),
eps: f32,
weight_decay: f32,
amsgrad: bool,
) -> Self
pub fn with_options( params: Vec<Parameter>, lr: f32, betas: (f32, f32), eps: f32, weight_decay: f32, amsgrad: bool, ) -> Self
Creates AdamW with all options.
Sourcepub fn weight_decay(self, weight_decay: f32) -> Self
pub fn weight_decay(self, weight_decay: f32) -> Self
Builder method to set weight decay.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AdamW
impl !RefUnwindSafe for AdamW
impl Send for AdamW
impl Sync for AdamW
impl Unpin for AdamW
impl !UnwindSafe for AdamW
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more