PIXELBANKv9.1.0
Menu

Problem Statement

Compare three different schedulers side by side over the same number of epochs.

Background

Different schedulers produce different decay curves. StepLR gives discrete drops, ExponentialLR gives smooth decay, CosineAnnealingLR gives a cosine-shaped curve.

Your Task

The starter code provides a run_scheduler helper function. Use it to generate LR curves for StepLR (step_size=5, gamma=0.5), ExponentialLR (gamma=0.9), and CosineAnnealingLR (T_max=15, eta_min=0.001).

Output Format

Returns a dictionary with "step_lrs", "exp_lrs", "cosine_lrs", and "final_comparison".

Example:

Input:
None
Output:
{'step_lrs': [0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.025, 0.025, 0.025, 0.025, 0.025], 'exp_lrs': [0.1, 0.09, 0.081, 0.0729, 0.0656, 0.059, 0.0531, 0.0478, 0.043, 0.0387, 0.0349, 0.0314, 0.0282, 0.0254, 0.0229], 'cosine_lrs': [0.1, 0.0966, 0.0868, 0.0714, 0.0517, 0.0505, 0.0302, 0.0302, 0.0143, 0.0143, 0.001, 0.001, 0.001, 0.001, 0.001], 'final_comparison': {'step': 0.025, 'exponential': 0.0229, 'cosine': 0.001}}
Reasoning:
  • We initialize three schedulers: StepLR with lr=0.1lr=0.1, step_size=5step\_size=5, and γ=0.5\gamma=0.5; ExponentialLR with lr=0.1lr=0.1 and γ=0.9\gamma=0.9; and CosineAnnealingLR with lr=0.1lr=0.1, T_max=15T\_max=15, and η_min=0.001\eta\_min=0.001.
  • For each of the 15 epochs, we update the learning rate for each scheduler: StepLR reduces the rate by a factor of γ\gamma every step_sizestep\_size epochs, ExponentialLR reduces the rate by a factor of γ\gamma every epoch, and CosineAnnealingLR reduces the rate according to a cosine schedule.
  • We record the learning rate values for each scheduler at each epoch, rounding to 4 decimals, resulting in the 'step_lrs', 'exp_lrs', and 'cosine_lrs' lists in the output.
  • Finally, we create the 'final_comparison' dictionary with the final learning rate of each scheduler, giving the output {'step': 0.025, 'exponential': 0.0229, 'cosine': 0.001}.

Constraints:

  • Same initial LR for all three
  • 15 epochs each
  • Compare final values
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Compare Scheduler Curves - Medium | PixelBank