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
None
{'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}- 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: , 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): , producing the remaining learning rates in the
lr_historylist. - 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