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
impl LearningRateFinder
Sourcepub fn new(start_lr: f64, end_lr: f64, num_steps: usize) -> Self
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
Sourcepub fn with_exponential_scaling(self) -> Self
pub fn with_exponential_scaling(self) -> Self
Enable exponential scaling (recommended, default).
Sourcepub fn with_linear_scaling(self) -> Self
pub fn with_linear_scaling(self) -> Self
Enable linear scaling.
Sourcepub fn with_smoothing(self, smoothing: f64) -> Self
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.
Sourcepub fn suggest_lr(&self) -> Option<f64>
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).
Sourcepub fn print_results(&self)
pub fn print_results(&self)
Print the LR finder results.
Trait Implementations§
Source§impl Callback for LearningRateFinder
impl Callback for LearningRateFinder
Source§fn on_batch_end(
&mut self,
_batch: usize,
state: &TrainingState,
) -> TrainResult<()>
fn on_batch_end( &mut self, _batch: usize, state: &TrainingState, ) -> TrainResult<()>
Source§fn should_stop(&self) -> bool
fn should_stop(&self) -> bool
Source§fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
Source§fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Source§fn on_epoch_begin(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_begin( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Source§fn on_epoch_end(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_end( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Source§fn on_batch_begin(
&mut self,
_batch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_batch_begin( &mut self, _batch: usize, _state: &TrainingState, ) -> TrainResult<()>
Source§fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Auto Trait Implementations§
impl Freeze for LearningRateFinder
impl RefUnwindSafe for LearningRateFinder
impl Send for LearningRateFinder
impl Sync for LearningRateFinder
impl Unpin for LearningRateFinder
impl UnwindSafe for LearningRateFinder
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
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