Linear Learning Rate Decay: Big Steps, Then Small

OptimizationMedium+20 XP+15

Linear Learning Rate Decay: Big Steps, Then Small

A fixed learning rate is a compromise: large enough to make progress early, and therefore too large to settle later. Decaying it fixes both ends — move fast at first, then take smaller steps as you approach a minimum.

Task: write linear_schedule(initial_lr, final_lr, total_steps) returning the learning rate at every step, rounded to 6 decimal places.

  • The list has exactly total_steps entries.
  • Step 0 is initial_lr and the last step is exactly final_lr, with even spacing between — so the divisor is total_steps - 1.
  • total_steps = 1 returns just [initial_lr].
  • total_steps = 0 returns an empty list.

Six decimal places, not four, because learning rates live down at 1e-4 and below — rounding to 4 would flatten most real schedules into a list of zeros.

Examples

initial_lr = 0.1
final_lr = 0.0
total_steps = 5
returns [0.1, 0.075, 0.05, 0.025, 0.0]
initial_lr = 1.0
final_lr = 0.5
total_steps = 3
returns [1.0, 0.75, 0.5]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run