LR Scheduler
Implement a warmup + cosine decay learning rate scheduler.
The schedule has two phases:
- Warmup (steps 0 to warmup_steps-1): Linear warmup from 0 to max_lr
- Cosine decay (steps warmup_steps to total_steps-1): Decay from max_lr to min_lr
Input: warmup_steps total_steps max_lr min_lr Output: Learning rate for each step (0 to total_steps-1), one per line, rounded to 6 decimal places.
Example
2 6 0.001 0.0001
0.000000 0.000500 0.001000 0.000775 0.000325 0.000100
- The warmup phase starts from step 0 to 1 (since warmup_steps = 2), with a linear increase from 0 to max_lr = 0.001. At step 0, the learning rate is , and at step 1, it's .
- From step 2 onwards, the cosine decay phase begins, with the learning rate calculated as .
- Applying this formula for steps 2 to 5 gives the remaining learning rates: at step 2, (since ), at step 3, , at step 4, , and at step 5, .
- These calculated learning rates are then rounded to 6 decimal places and output, one per line, resulting in the given sample output.
Constraints
- 0 < warmup_steps < total_steps
- min_lr < max_lr
- Round to 6 decimal places