v9.1.1
Menu

ExponentialLR Scheduler

easyFREELearning Rate SchedulersPyTorch Advanced

Problem Statement

Use ExponentialLR for smooth exponential decay of the learning rate.

Background

ExponentialLR multiplies the learning rate by gamma every epoch: lr[n] = initial_lr * gamma^n.

Your Task

The starter code creates a model and SGD optimizer. Create an ExponentialLR scheduler with gamma=0.9.

The epoch loop and exponential verification are pre-filled.

Output Format

Returns a dictionary with "lr_history" (10 values), "decay_ratio", and "is_exponential".

Example

Input
None
Output
{'lr_history': [1.0, 0.9, 0.81, 0.729, 0.6561, 0.5905, 0.5314, 0.4783, 0.4305, 0.3874], 'decay_ratio': 0.3874, 'is_exponential': True}
Reasoning
  • There is no argument: the function builds a tiny linear model whose optimizer starts at a learning rate of η0=1.0\eta_0 = 1.0, and the schedule uses decay factor γ=0.9\gamma = 0.9.
  • Each epoch first records the current rate, then advances the schedule by one epoch, so the rate recorded at epoch nn is ηn=η0γn\eta_n = \eta_0 \gamma^n.
  • Working it through: η1=0.9\eta_1 = 0.9, η2=0.81\eta_2 = 0.81, η3=0.729\eta_3 = 0.729, η4=0.6561\eta_4 = 0.6561, and η5=0.59049→0.5905\eta_5 = 0.59049 \to 0.5905 once rounded to 4 decimal places. Then 0.53140.5314, 0.47830.4783, 0.43050.4305, and η9=0.387420…→0.3874\eta_9 = 0.387420\ldots \to 0.3874.
  • Ten values cover n=0n = 0 to 99, so the last entry is γ9\gamma^9, not γ10\gamma^{10}. That is why decay_ratio =η9/η0=0.3874= \eta_9 / \eta_0 = 0.3874.
  • Every consecutive ratio ηn/ηn−1\eta_n / \eta_{n-1} is 0.90.9 (within 0.010.01 even after rounding), so is_exponential is True.
  • Notice the curve: the rate shrinks by a constant fraction each epoch, so the absolute drop gets smaller over time (0.10.1 at first, about 0.0430.043 at the end).

Constraints

  • gamma=0.9
  • Initial lr=1.0
  • 10 epochs

More from PyTorch Advanced

solution.py

Test results

Sign in to run your code against the test cases.