pub struct LAMB { /* private fields */ }Expand description
LAMB optimizer for large batch training.
LAMB extends Adam by adding a layer-wise trust ratio that scales the update based on the ratio of parameter norm to update norm. This enables stable training with very large batch sizes.
The update rule is:
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)
r = m_hat / (sqrt(v_hat) + eps) + weight_decay * param
trust_ratio = ||param|| / ||r|| (layer-wise)
param = param - lr * trust_ratio * rImplementations§
Source§impl LAMB
impl LAMB
Sourcepub fn new(params: Vec<Parameter>, lr: f32) -> Self
pub fn new(params: Vec<Parameter>, lr: f32) -> Self
Creates a new LAMB optimizer with default hyperparameters.
Defaults:
- betas: (0.9, 0.999)
- eps: 1e-6
- weight_decay: 0.0
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 LAMB with specified betas.
Sourcepub fn with_options(
params: Vec<Parameter>,
lr: f32,
betas: (f32, f32),
eps: f32,
weight_decay: f32,
) -> Self
pub fn with_options( params: Vec<Parameter>, lr: f32, betas: (f32, f32), eps: f32, weight_decay: f32, ) -> Self
Creates LAMB with all options.
Sourcepub fn weight_decay(self, weight_decay: f32) -> Self
pub fn weight_decay(self, weight_decay: f32) -> Self
Builder: set weight decay
Sourcepub fn bias_correction(self, enabled: bool) -> Self
pub fn bias_correction(self, enabled: bool) -> Self
Builder: set bias correction
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LAMB
impl !RefUnwindSafe for LAMB
impl Send for LAMB
impl Sync for LAMB
impl Unpin for LAMB
impl !UnwindSafe for LAMB
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