pub struct LearningRateScheduler {
pub strategy: SchedulerStrategy,
pub state: LrSchedulerState,
/* private fields */
}Expand description
Multi-strategy learning rate scheduler.
Supports Constant, StepDecay, ExponentialDecay, CosineAnnealing,
WarmupCosine, CyclicLR, and ReduceOnPlateau.
Fields§
§strategy: SchedulerStrategyThe scheduling strategy in use.
state: LrSchedulerStateMutable runtime state.
Implementations§
Source§impl LearningRateScheduler
impl LearningRateScheduler
Sourcepub fn new(strategy: SchedulerStrategy) -> Self
pub fn new(strategy: SchedulerStrategy) -> Self
Create a new scheduler. The initial learning rate is derived from the
strategy variant’s initial_lr (or lr for Constant).
Sourcepub fn step(&mut self, epoch: u64) -> f64
pub fn step(&mut self, epoch: u64) -> f64
Compute the learning rate for the given epoch without mutating
significant state (except appending to history and updating
current_epoch / current_lr).
For ReduceOnPlateau this ignores plateau tracking — use
step_with_loss instead.
Sourcepub fn step_with_loss(&mut self, epoch: u64, loss: f64) -> f64
pub fn step_with_loss(&mut self, epoch: u64, loss: f64) -> f64
Advance one step using a loss value. For ReduceOnPlateau this
updates the internal plateau counter and reduces LR as needed.
For other strategies it behaves identically to step.
Sourcepub fn current_lr(&self) -> f64
pub fn current_lr(&self) -> f64
Return the most recently computed learning rate.
Sourcepub fn history(&self) -> &[LrHistory]
pub fn history(&self) -> &[LrHistory]
Return a slice of the LR history (capped at the last 1 000 entries).
Sourcepub fn warmup_factor(epoch: u64, warmup_epochs: u64) -> f64
pub fn warmup_factor(epoch: u64, warmup_epochs: u64) -> f64
Linear interpolation factor for a warmup phase.
Returns values in [0.0, 1.0] linearly from 0 to 1 as epoch
goes from 0 to warmup_epochs. Returns 1.0 when epoch >= warmup_epochs.
Sourcepub fn cosine_factor(epoch: u64, t_max: u64) -> f64
pub fn cosine_factor(epoch: u64, t_max: u64) -> f64
Cosine annealing factor: (1 + cos(π * epoch / t_max)) / 2.
Returns values in [0.0, 1.0]. Clamps epoch at t_max.
Trait Implementations§
Source§impl Clone for LearningRateScheduler
impl Clone for LearningRateScheduler
Source§fn clone(&self) -> LearningRateScheduler
fn clone(&self) -> LearningRateScheduler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LearningRateScheduler
impl RefUnwindSafe for LearningRateScheduler
impl Send for LearningRateScheduler
impl Sync for LearningRateScheduler
impl Unpin for LearningRateScheduler
impl UnsafeUnpin for LearningRateScheduler
impl UnwindSafe for LearningRateScheduler
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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