ReduceLROnPlateau Scheduler
Problem Statement
Use ReduceLROnPlateau to automatically reduce LR when a metric stops improving.
Background
ReduceLROnPlateau monitors a metric and reduces LR when it stops improving for patience epochs. Unlike other schedulers, it requires passing the metric value to scheduler.step(loss).
Your Task
The starter code creates a model, optimizer, and simulated loss values. Create a ReduceLROnPlateau scheduler that halves the LR when loss doesn't improve for 2 epochs.
The epoch loop (which passes each loss to scheduler.step(loss)) is pre-filled.
Output Format
Returns a dictionary with "lr_history" (10 values), "num_reductions", and "final_lr".
Example
None
{'lr_history': [0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.025, 0.025], 'num_reductions': 2, 'final_lr': 0.025}- The
plateau_lr_test()function initializes the learning rate (LR) to 0.1 and creates aReduceLROnPlateauscheduler with a patience of 2 epochs and a reduction factor of 0.5. - The function then simulates 10 epochs with the given loss values: . The scheduler reduces the LR when the loss stops improving for 2 consecutive epochs.
- After the first 2 epochs, the loss improves from 1.0 to 0.9 to 0.8, so the LR remains at 0.1. However, the loss plateaus at 0.8 for the next 2 epochs, triggering the first LR reduction to .
- The loss remains at 0.8 for the next 4 epochs, triggering a second LR reduction to after the 6th epoch, resulting in an LR history of .
Constraints
- mode='min', factor=0.5, patience=2
- Pass simulated losses to scheduler.step()
- Count LR reductions