pub struct CosineWarmupLR { /* private fields */ }Expand description
Linear warmup from 0 to initial_lr over warmup_steps, then cosine
decay from initial_lr to min_lr over the remaining steps.
This is the standard scheduler used for training transformers (GPT, BERT, etc.).
warmup phase (step < warmup_steps):
lr = initial_lr * step / warmup_steps
decay phase (step >= warmup_steps):
progress = (step - warmup_steps) / (total_steps - warmup_steps)
lr = min_lr + 0.5 * (initial_lr - min_lr) * (1 + cos(π * progress))Implementations§
Source§impl CosineWarmupLR
impl CosineWarmupLR
Sourcepub fn new(
initial_lr: f64,
warmup_steps: u64,
total_steps: u64,
min_lr: f64,
) -> CosineWarmupLR
pub fn new( initial_lr: f64, warmup_steps: u64, total_steps: u64, min_lr: f64, ) -> CosineWarmupLR
Create a cosine warmup scheduler.
§Arguments
initial_lr: Peak learning rate (reached at end of warmup)warmup_steps: Number of linear warmup stepstotal_steps: Total training steps (warmup + decay)min_lr: Minimum learning rate at end of training
Trait Implementations§
Source§impl LrScheduler for CosineWarmupLR
impl LrScheduler for CosineWarmupLR
Source§fn current_lr(&self) -> f64
fn current_lr(&self) -> f64
Get the current learning rate without advancing.
Source§fn current_step(&self) -> u64
fn current_step(&self) -> u64
Get the current step count.
Auto Trait Implementations§
impl Freeze for CosineWarmupLR
impl RefUnwindSafe for CosineWarmupLR
impl Send for CosineWarmupLR
impl Sync for CosineWarmupLR
impl Unpin for CosineWarmupLR
impl UnwindSafe for CosineWarmupLR
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