Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of ReduceLROnPlateau in PyTorch?
ReduceLROnPlateau lowers the learning rate when a model's performance stops improving, helping the model learn better by taking smaller steps.
Click to reveal answer
beginner
Which metric does ReduceLROnPlateau monitor to decide when to reduce the learning rate?
It monitors a chosen metric like validation loss or accuracy to detect when the model stops improving.
Click to reveal answer
intermediate
What does the 'patience' parameter control in ReduceLROnPlateau?
Patience sets how many epochs to wait without improvement before reducing the learning rate.
Click to reveal answer
intermediate
How does the 'factor' parameter affect learning rate reduction in ReduceLROnPlateau?
Factor is the multiplier applied to the current learning rate to reduce it, for example, factor=0.1 reduces the rate to 10% of its value.
Click to reveal answer
beginner
Show a simple PyTorch code snippet using ReduceLROnPlateau with validation loss monitoring.
import torch.optim as optim
optimizer = optim.Adam(model.parameters(), lr=0.01)
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=5)
# In training loop:
# val_loss = compute_validation_loss()
# scheduler.step(val_loss)
Click to reveal answer
What does ReduceLROnPlateau do when the monitored metric stops improving?
AStops the training
BIncreases the learning rate
CReduces the learning rate
DResets the model weights
✗ Incorrect
ReduceLROnPlateau reduces the learning rate to help the model improve when progress stalls.
Which parameter controls how long to wait before reducing the learning rate?
Apatience
Bfactor
Cthreshold
Dcooldown
✗ Incorrect
Patience sets the number of epochs to wait without improvement before reducing the learning rate.
If factor=0.5, what happens to the learning rate when ReduceLROnPlateau triggers?
AIt halves
BIt doubles
CIt stays the same
DIt becomes zero
✗ Incorrect
Factor multiplies the learning rate; 0.5 means the learning rate is reduced to half.
Which mode should you use to monitor validation loss with ReduceLROnPlateau?
Amax
Bnone
Cauto
Dmin
✗ Incorrect
Use mode='min' when monitoring loss because lower loss is better.
When should you call scheduler.step() in training with ReduceLROnPlateau?
AAfter each batch
BAfter each epoch with the monitored metric
CBefore training starts
DOnly once at the end
✗ Incorrect
Call scheduler.step() after each epoch, passing the metric value to decide if learning rate should reduce.
Explain how ReduceLROnPlateau helps improve model training and what key parameters control its behavior.
Think about when and how the learning rate changes during training.
You got /4 concepts.
Describe how you would implement ReduceLROnPlateau in a PyTorch training loop to adjust learning rate based on validation loss.
Focus on the code steps and when to call the scheduler.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of ReduceLROnPlateau in PyTorch training?
easy
A. To shuffle the training data before each epoch
B. To increase the batch size automatically during training
C. To stop training early when accuracy reaches a threshold
D. To reduce the learning rate when a monitored metric stops improving
Solution
Step 1: Understand the role of learning rate schedulers
Learning rate schedulers adjust the learning rate during training to improve convergence.
Step 2: Identify what ReduceLROnPlateau does
This scheduler reduces the learning rate when a monitored metric (like validation loss) stops improving.
Final Answer:
To reduce the learning rate when a monitored metric stops improving -> Option D
Quick Check:
ReduceLROnPlateau lowers LR on no improvement [OK]
Hint: Remember: it lowers LR when progress stalls [OK]
Common Mistakes:
Confusing it with early stopping
Thinking it changes batch size
Assuming it shuffles data
2. Which of the following is the correct way to create a ReduceLROnPlateau scheduler in PyTorch?
easy
A. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min')
B. scheduler = torch.optim.ReduceLROnPlateau(optimizer, mode='max')
C. scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=10)
D. scheduler = torch.optim.ReduceLROnPlateau(optimizer, patience=5)
Solution
Step 1: Check the correct module and class name
The correct class is ReduceLROnPlateau inside torch.optim.lr_scheduler.
Step 2: Verify the constructor parameters
It requires the optimizer and optional parameters like mode. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min') uses correct syntax and parameters.
Final Answer:
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min') -> Option A
Quick Check:
Correct class and module usage [OK]
Hint: Use torch.optim.lr_scheduler.ReduceLROnPlateau with optimizer [OK]
Common Mistakes:
Using wrong module path
Confusing with StepLR scheduler
Missing required optimizer argument
3. Given the code below, what will be the learning rate after the third call to scheduler.step(val_loss) if val_loss values are [0.5, 0.4, 0.4, 0.4] and patience=2?
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', patience=2, factor=0.1)
val_losses = [0.5, 0.4, 0.4, 0.4]
for loss in val_losses:
scheduler.step(loss)
print(f"LR: {optimizer.param_groups[0]['lr']}")
medium
A. 0.1
B. 0.01
C. 0.001
D. 0.4
Solution
Step 1: Understand patience and when LR reduces
Patience=2 means LR reduces after 2 epochs with no improvement in monitored metric.
Step 2: Analyze val_loss sequence and scheduler calls
val_loss improves from 0.5 to 0.4 at second call, then stays same (no improvement) for next two calls. LR reduces only after 2 consecutive no improvements, so after the fourth call, not the third.
Final Answer:
0.1 -> Option A
Quick Check:
LR reduces after patience epochs, not before [OK]
Hint: LR changes after patience epochs without improvement [OK]
Common Mistakes:
Reducing LR immediately on no improvement
Confusing patience count
Using val_loss value as LR
4. Identify the error in the following code snippet using ReduceLROnPlateau:
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer)
for epoch in range(5):
train()
val_loss = validate()
scheduler.step()
medium
A. Learning rate must be set to 0.1 initially
B. Optimizer should be SGD, not Adam
C. Missing metric argument in scheduler.step() call
D. scheduler.step() should be called before training
Solution
Step 1: Check how ReduceLROnPlateau.step() is called
This scheduler requires the monitored metric (e.g., val_loss) as an argument in step().
Step 2: Identify missing argument in code
The code calls scheduler.step() without passing val_loss, causing an error.
Final Answer:
Missing metric argument in scheduler.step() call -> Option C
Quick Check:
Pass metric to step() for ReduceLROnPlateau [OK]
Hint: Always pass metric to scheduler.step() for ReduceLROnPlateau [OK]
Common Mistakes:
Calling step() without metric
Confusing optimizer type
Wrong order of scheduler call
5. You want to train a model and reduce the learning rate by half if the validation accuracy does not improve for 3 epochs. Which of the following is the correct way to set up ReduceLROnPlateau for this task?
hard
A. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='max', factor=2.0, patience=3)
B. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='max', factor=0.5, patience=3)
C. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=3)
D. scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=2.0, patience=3)
Solution
Step 1: Determine the mode based on metric type
Validation accuracy should be maximized, so mode='max' is correct.
Step 2: Set factor and patience correctly
Factor=0.5 halves the learning rate, patience=3 waits 3 epochs before reducing.
Final Answer:
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='max', factor=0.5, patience=3) -> Option B
Quick Check:
Maximize accuracy, reduce LR by half after 3 no improvements [OK]
Hint: Use mode='max' for accuracy, factor <1 to reduce LR [OK]