PIXELBANKv9.1.0
Menu

Warmup + Cosine Decay Schedule

Problem Statement

Implement a learning rate schedule with linear warmup followed by cosine decay using LambdaLR.

Background

Modern training often uses warmup (gradually increasing LR) followed by decay. This prevents early training instability. LambdaLR takes a function that returns a multiplier for the initial LR.

Your Task

The starter code creates a model and optimizer with warmup/total epoch constants. Create a LambdaLR scheduler that linearly warms up for 5 epochs, then follows cosine decay for the remaining epochs.

Output Format

Returns a dictionary with "lr_history" (20 values), "warmup_end_lr", and "peak_lr".

Example:

Input:
None
Output:
{'lr_history': [0.02, 0.04, 0.06, 0.08, 0.1, 0.0995, 0.0979, 0.0952, 0.0916, 0.087, 0.0816, 0.0755, 0.069, 0.062, 0.0549, 0.0477, 0.0407, 0.0341, 0.028, 0.0226], 'warmup_end_lr': 0.1, 'peak_lr': 0.1}
Reasoning:
  • The function warmup_cosine_test() initializes a learning rate schedule with a base learning rate of 0.1 and warmup epochs of 5.
  • During the warmup phase (epochs 0-4), the learning rate increases linearly: LR=0.1⋅epoch+15LR = 0.1 \cdot \frac{epoch + 1}{5}, resulting in learning rates of 0.02, 0.04, 0.06, 0.08, and 0.1.
  • After the warmup phase, the learning rate enters a cosine decay phase (epochs 5-19): LR=0.1⋅0.5⋅(1+cos⁡(π⋅epoch−515))LR = 0.1 \cdot 0.5 \cdot (1 + \cos(\pi \cdot \frac{epoch - 5}{15})), producing the remaining learning rates in the lr_history list.
  • The function records the learning rate history, warmup end learning rate, and peak learning rate, returning them as a dictionary with the specified values.

Constraints:

  • Linear warmup for 5 epochs
  • Cosine decay for remaining 15 epochs
  • Use LambdaLR
🔒

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.