pub struct LookaheadOptimizer<O: Optimizer> { /* private fields */ }Expand description
Lookahead optimizer (wrapper that uses slow and fast weights).
Maintains two sets of weights: fast weights updated by an inner optimizer, and slow weights that are periodically updated as an exponential moving average.
Reference: Zhang et al., “Lookahead Optimizer: k steps forward, 1 step back”, NeurIPS 2019
Implementations§
Source§impl<O: Optimizer> LookaheadOptimizer<O>
impl<O: Optimizer> LookaheadOptimizer<O>
Sourcepub fn new(inner_optimizer: O, alpha: f64, k: usize) -> TrainResult<Self>
pub fn new(inner_optimizer: O, alpha: f64, k: usize) -> TrainResult<Self>
Create a new Lookahead optimizer.
§Arguments
inner_optimizer- The inner optimizer (e.g., Adam, SGD)alpha- Interpolation coefficient for slow weight update (typically 0.5)k- Number of fast updates before slow weight synchronization (typically 5-10)
Trait Implementations§
Auto Trait Implementations§
impl<O> Freeze for LookaheadOptimizer<O>where
O: Freeze,
impl<O> RefUnwindSafe for LookaheadOptimizer<O>where
O: RefUnwindSafe,
impl<O> Send for LookaheadOptimizer<O>where
O: Send,
impl<O> Sync for LookaheadOptimizer<O>where
O: Sync,
impl<O> Unpin for LookaheadOptimizer<O>where
O: Unpin,
impl<O> UnwindSafe for LookaheadOptimizer<O>where
O: 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> 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