pub struct CosineAnnealingScheduler { /* private fields */ }Expand description
Cosine annealing with optional warm restarts (SGDR).
lr_t = min_lr + 0.5 * (max_lr - min_lr) * (1 + cos(pi * t_cur / t_max))
If restart_period is Some(T), restarts every T steps (warm restarts).
Implementations§
Source§impl CosineAnnealingScheduler
impl CosineAnnealingScheduler
Sourcepub fn new(
max_lr: f64,
min_lr: f64,
t_max: usize,
) -> Result<Self, SchedulerError>
pub fn new( max_lr: f64, min_lr: f64, t_max: usize, ) -> Result<Self, SchedulerError>
Create a new cosine annealing scheduler.
§Errors
Returns SchedulerError::InvalidConfig if any parameter is invalid.
Sourcepub fn with_warm_restarts(self, period: usize) -> Self
pub fn with_warm_restarts(self, period: usize) -> Self
Enable warm restarts every period steps.
Trait Implementations§
Source§impl LrSchedulerV2 for CosineAnnealingScheduler
impl LrSchedulerV2 for CosineAnnealingScheduler
Source§fn current_lr(&self) -> f64
fn current_lr(&self) -> f64
Return the current learning rate without advancing.
Source§fn steps_taken(&self) -> usize
fn steps_taken(&self) -> usize
Total number of steps taken.
Source§fn completed_cycle(&self) -> bool
fn completed_cycle(&self) -> bool
Whether the scheduler has completed a cycle (if applicable).
Auto Trait Implementations§
impl Freeze for CosineAnnealingScheduler
impl RefUnwindSafe for CosineAnnealingScheduler
impl Send for CosineAnnealingScheduler
impl Sync for CosineAnnealingScheduler
impl Unpin for CosineAnnealingScheduler
impl UnsafeUnpin for CosineAnnealingScheduler
impl UnwindSafe for CosineAnnealingScheduler
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