pub struct LARS<A: Float> { /* private fields */ }Expand description
Layer-wise Adaptive Rate Scaling (LARS) optimizer
LARS is an optimization algorithm specifically designed for large batch training, which allows scaling up the batch size significantly without loss of accuracy. It works by adapting the learning rate per layer based on the ratio of weight norm to gradient norm.
§Parameters
learning_rate- Base learning ratemomentum- Momentum factor (default: 0.9)weight_decay- Weight decay factor (default: 0.0001)trust_coefficient- Trust coefficient for scaling (default: 0.001)eps- Small constant for numerical stability (default: 1e-8)exclude_bias_and_norm- Whether to exclude bias and normalization layers from LARS adaptation (default: true)
§Example
use scirs2_core::ndarray::Array1;
use optirs_core::optimizers::{LARS, Optimizer};
let mut optimizer = LARS::new(0.01)
.with_momentum(0.9)
.with_weight_decay(0.0001)
.with_trust_coefficient(0.001);
let params = Array1::zeros(10);
let gradients = Array1::ones(10);
let updated_params = optimizer.step(¶ms, &gradients).unwrap();
// Parameters are automatically updatedImplementations§
Source§impl<A: Float + ScalarOperand + Debug + Send + Sync> LARS<A>
impl<A: Float + ScalarOperand + Debug + Send + Sync> LARS<A>
Sourcepub fn with_momentum(self, momentum: A) -> Self
pub fn with_momentum(self, momentum: A) -> Self
Set the momentum factor
Sourcepub fn with_weight_decay(self, weight_decay: A) -> Self
pub fn with_weight_decay(self, weight_decay: A) -> Self
Set the weight decay factor
Sourcepub fn with_trust_coefficient(self, trust_coefficient: A) -> Self
pub fn with_trust_coefficient(self, trust_coefficient: A) -> Self
Set the trust coefficient
Sourcepub fn with_exclude_bias_and_norm(self, exclude_bias_and_norm: bool) -> Self
pub fn with_exclude_bias_and_norm(self, exclude_bias_and_norm: bool) -> Self
Set whether to exclude bias and normalization layers from LARS adaptation
Trait Implementations§
Source§impl<A: Float + ScalarOperand + Debug + Send + Sync, D: Dimension + Send + Sync> Optimizer<A, D> for LARS<A>
impl<A: Float + ScalarOperand + Debug + Send + Sync, D: Dimension + Send + Sync> Optimizer<A, D> for LARS<A>
Source§fn step(
&mut self,
params: &Array<A, D>,
gradients: &Array<A, D>,
) -> Result<Array<A, D>>
fn step( &mut self, params: &Array<A, D>, gradients: &Array<A, D>, ) -> Result<Array<A, D>>
Updates parameters using the given gradients Read more
Source§fn set_learning_rate(&mut self, learning_rate: A)
fn set_learning_rate(&mut self, learning_rate: A)
Sets a new learning rate
Source§fn get_learning_rate(&self) -> A
fn get_learning_rate(&self) -> A
Gets the current learning rate
Auto Trait Implementations§
impl<A> Freeze for LARS<A>where
A: Freeze,
impl<A> RefUnwindSafe for LARS<A>where
A: RefUnwindSafe,
impl<A> Send for LARS<A>where
A: Send,
impl<A> Sync for LARS<A>where
A: Sync,
impl<A> Unpin for LARS<A>where
A: Unpin,
impl<A> UnwindSafe for LARS<A>where
A: UnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.