Learning-rate range test
Background
The learning-rate range test (Leslie Smith, popularized by fast.ai) finds a good learning rate cheaply: run a few hundred iterations while increasing the LR geometrically from tiny to large, recording the loss at each LR. Plotting loss against gives a curve that descends, then explodes. A common heuristic picks the LR at the point of steepest descent — where loss is dropping fastest — which sits safely below the LR that minimizes the loss.
Problem statement
Implement suggest_lr(lrs, losses) that returns the learning rate at the point of steepest descent of the loss curve:
Use np.gradient(losses, np.log10(lrs)) to estimate the slope, then return the LR where that slope is most negative.
Input
lrs—np.ndarrayof learning rates, strictly increasing (typically geometric).losses—np.ndarrayof recorded losses, same length aslrs.
Output
A float: the learning rate at the steepest-descent point.
Examples
Example 1
Input: lrs = [1e-4, 1e-3, 1e-2, 1e-1, 1.0]
losses = [2.5, 2.3, 1.8, 1.0, 3.0]
Output: 0.01
Explanation: taking the gradient of loss with respect to gives slopes . The most negative slope is at index 2, so the suggested LR is .
Constraints
- Differentiate loss with respect to , not raw lr (the test sweeps LR on a log scale).
- The suggested LR is the one at the minimum (most negative) gradient.
- Return one of the values in
lrsas afloat.
Notes
- Picking the steepest-descent LR (rather than the loss-minimizing LR) leaves headroom before the curve blows up — the loss-min LR is often already too large to train stably.
- Real implementations smooth the loss (EMA) before differentiating to reduce noise; here the raw losses are used.
This problem ships 4 hidden tests. They run in your browser via Pyodide — no backend, no submission queue. Press ▶ Run tests to execute.
- •Reference example
- •Returned LR is one of the inputs
- •Picks the steepest (most negative central-difference) slope
- •Differentiates on a log scale (geometric lrs)