CosineAnnealingLR Scheduler
Problem Statement
Use CosineAnnealingLR for cosine-shaped learning rate decay.
Background
CosineAnnealingLR follows a cosine curve from initial LR down to eta_min over T_max epochs, then back up.
Your Task
The starter code creates a model and SGD optimizer. Create a CosineAnnealingLR scheduler that decays over 20 epochs to a minimum LR of 0.001.
The epoch loop is pre-filled.
Output Format
Returns a dictionary with "lr_history" (20 values), "max_lr", "min_lr", and "mid_lr".
Example
None
{'lr_history': [0.1, 0.0976, 0.0905, 0.079, 0.0638, 0.0505, 0.0362, 0.021, 0.0095, 0.0034, 0.001, 0.0034, 0.0095, 0.021, 0.0362, 0.0505, 0.0638, 0.079, 0.0905, 0.0976], 'max_lr': 0.1, 'min_lr': 0.001, 'mid_lr': 0.001}- The
cosine_lr_test()function initializes a learning rate of 0.1 and creates aCosineAnnealingLRscheduler with and . - The scheduler applies a cosine-shaped learning rate decay: , where is the current epoch and is the initial learning rate.
- Over 20 epochs, the learning rate decays and then increases, following the cosine curve, resulting in the recorded
lr_historyvalues. - The maximum, minimum, and mid-point learning rates are extracted from the
lr_historyto produce the final output dictionary values:max_lr,min_lr, andmid_lr.
Constraints
- T_max=20, eta_min=0.001
- Initial lr=0.1
- 20 epochs