The Lookahead Optimiser Wrapper

easy
Unit 4 · Optimization & CNNs0/3 to milestone

Lookahead (Zhang et al., 2019) wraps any optimiser. The inner optimiser updates "fast" weights for k steps; then the "slow" weights move part of the way towards them and the fast weights are reset to the slow ones:

ϕ←ϕ+α(θ−ϕ),θ←ϕ\phi \leftarrow \phi + \alpha(\theta - \phi), \qquad \theta \leftarrow \phi

Implement a class Lookahead(params, inner_step, k=5, alpha=0.5), where params is a NumPy array (the initial weights) and inner_step(params, grad) returns updated weights:

  • step(grad): apply the inner step to the fast weights. After every k-th call, perform the slow update and sync. Return the current fast weights.
  • attributes fast and slow
#optimization#training2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
The Lookahead Optimiser Wrapper · TechGradify