PIXELBANKv9.1.0
Menu

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:
  • We create an nn.Linear(2, 1) model with SGD optimizer and a learning rate of 1.0.
  • An ExponentialLR scheduler is applied to the optimizer with a gamma value of 0.9, which means the learning rate will decay by a factor of 0.90.9 at each epoch.
  • Over 10 epochs, the learning rate is updated at each epoch, resulting in a smooth exponential decay: 1.0,1.0â‹…0.9,1.0â‹…0.92,...,1.0â‹…0.991.0, 1.0 \cdot 0.9, 1.0 \cdot 0.9^2, ..., 1.0 \cdot 0.9^9, yielding the lr_history list.
  • The decay_ratio is calculated as the ratio of the last learning rate to the first, which is 0.990.9^9, and is_exponential is set to True since each learning rate is approximately 0.90.9 times the previous one.

Constraints:

  • gamma=0.9
  • Initial lr=1.0
  • 10 epochs
solution.py

Test Results

0/0
Run code to see test results.
ExponentialLR Scheduler - Easy | PixelBank