pub struct LionOptimizer { /* private fields */ }Expand description
Lion optimizer.
Update rule:
- c_t = β1 * m_{t-1} + (1 - β1) * g_t (interpolation)
- θ_t = θ_{t-1} - lr * (sign(c_t) + λ * θ_{t-1}) (parameter update with weight decay)
- m_t = β2 * m_{t-1} + (1 - β2) * g_t (momentum update)
Key differences from Adam:
- Uses sign(momentum) instead of normalized gradients
- Only tracks first moment (momentum), no second moment
- Typically requires smaller learning rates than Adam
- More memory efficient
Implementations§
Source§impl LionOptimizer
impl LionOptimizer
Sourcepub fn new(config: LionConfig) -> TrainResult<Self>
pub fn new(config: LionConfig) -> TrainResult<Self>
Create a new Lion optimizer.
Sourcepub fn step(
&mut self,
params: &mut HashMap<String, Array1<f64>>,
gradients: &HashMap<String, Array1<f64>>,
) -> TrainResult<()>
pub fn step( &mut self, params: &mut HashMap<String, Array1<f64>>, gradients: &HashMap<String, Array1<f64>>, ) -> TrainResult<()>
Perform a single optimization step.
Sourcepub fn load_state_dict(
&mut self,
state: &HashMap<String, Vec<f64>>,
) -> TrainResult<()>
pub fn load_state_dict( &mut self, state: &HashMap<String, Vec<f64>>, ) -> TrainResult<()>
Load optimizer state from checkpoint.
Auto Trait Implementations§
impl Freeze for LionOptimizer
impl RefUnwindSafe for LionOptimizer
impl Send for LionOptimizer
impl Sync for LionOptimizer
impl Unpin for LionOptimizer
impl UnwindSafe for LionOptimizer
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> 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 more