Skip to main content

LearningRateFinder

Struct LearningRateFinder 

Source
pub struct LearningRateFinder {
    pub history: Vec<(f64, f64)>,
    /* private fields */
}
Expand description

Learning rate finder callback using the LR range test.

This callback implements the learning rate range test proposed by Leslie N. Smith. It gradually increases the learning rate from a minimum to a maximum value over a specified number of iterations/epochs and tracks the loss at each step.

The optimal learning rate is typically found just before the loss starts to increase.

§Example

use tensorlogic_train::{LearningRateFinder, CallbackList};

let mut callbacks = CallbackList::new();
callbacks.add(Box::new(LearningRateFinder::new(
    1e-7,   // start_lr
    10.0,   // end_lr
    100,    // num_steps
)));

Fields§

§history: Vec<(f64, f64)>

History of (lr, loss) pairs.

Implementations§

Source§

impl LearningRateFinder

Source

pub fn new(start_lr: f64, end_lr: f64, num_steps: usize) -> Self

Create a new learning rate finder.

§Arguments
  • start_lr - Starting learning rate (e.g., 1e-7)
  • end_lr - Ending learning rate (e.g., 10.0)
  • num_steps - Number of steps to test
Source

pub fn with_exponential_scaling(self) -> Self

Enable exponential scaling (recommended, default).

Source

pub fn with_linear_scaling(self) -> Self

Enable linear scaling.

Source

pub fn with_smoothing(self, smoothing: f64) -> Self

Set loss smoothing factor (0.0-1.0).

Recommended: 0.9 for noisy losses, 0.0 for smooth losses.

Source

pub fn suggest_lr(&self) -> Option<f64>

Find the suggested optimal learning rate.

Returns the learning rate with the steepest negative gradient (fastest decrease in loss).

Source

pub fn print_results(&self)

Print the LR finder results.

Trait Implementations§

Source§

impl Callback for LearningRateFinder

Source§

fn on_batch_end( &mut self, _batch: usize, state: &TrainingState, ) -> TrainResult<()>

Called at the end of a batch.
Source§

fn should_stop(&self) -> bool

Check if training should stop early.
Source§

fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>

Called at the beginning of training.
Source§

fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>

Called at the end of training.
Source§

fn on_epoch_begin( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>

Called at the beginning of an epoch.
Source§

fn on_epoch_end( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>

Called at the end of an epoch.
Source§

fn on_batch_begin( &mut self, _batch: usize, _state: &TrainingState, ) -> TrainResult<()>

Called at the beginning of a batch.
Source§

fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>

Called after validation.

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V