Skip to main content

CosineAnnealingLr

Struct CosineAnnealingLr 

Source
pub struct CosineAnnealingLr {
    pub max_lr: f64,
    pub min_lr: f64,
    pub total_steps: usize,
    pub warmup_steps: usize,
}
Expand description

§Cosine Annealing Learning Rate Scheduler with Linear Warmup.

This scheduler:

  1. Linearly increases LR from 0 to max_lr during warmup phase
  2. Applies cosine annealing from max_lr to min_lr after warmup

This is a common pattern in modern deep learning training.

Fields§

§max_lr: f64

The maximum learning rate (reached after warmup)

§min_lr: f64

The minimum learning rate (reached at end of training)

§total_steps: usize

The total number of training steps

§warmup_steps: usize

The number of warmup steps

Implementations§

Source§

impl CosineAnnealingLr

Source

pub fn new(total_steps: usize) -> Self

Create a new instance of the config.

§Arguments
§Required Arguments
§total_steps

The total number of training steps

§Default Arguments
§max_lr

The maximum learning rate (reached after warmup)

  • Defaults to 1e-4
§min_lr

The minimum learning rate (reached at end of training)

  • Defaults to 1e-6
§warmup_steps

The number of warmup steps

  • Defaults to 0
Source§

impl CosineAnnealingLr

Source

pub fn with_max_lr(self, max_lr: f64) -> Self

Sets the value for the field max_lr.

The maximum learning rate (reached after warmup)

  • Defaults to 1e-4
Source

pub fn with_min_lr(self, min_lr: f64) -> Self

Sets the value for the field min_lr.

The minimum learning rate (reached at end of training)

  • Defaults to 1e-6
Source

pub fn with_warmup_steps(self, warmup_steps: usize) -> Self

Sets the value for the field warmup_steps.

The number of warmup steps

  • Defaults to 0
Source§

impl CosineAnnealingLr

Source

pub fn get_lr(&self, step: usize) -> f64

Get the learning rate for the current training step.

§Arguments
  • step - Current training step (0-indexed)
§Returns
  • Learning rate for this step

Trait Implementations§

Source§

impl Clone for CosineAnnealingLr

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Config for CosineAnnealingLr

§

fn load_binary(data: &[u8]) -> Result<Self, ConfigError>

Loads the configuration from a binary buffer. Read more
Source§

impl Debug for CosineAnnealingLr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CosineAnnealingLr

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for CosineAnnealingLr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for CosineAnnealingLr

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,