Bird
Raised Fist0
PyTorchml~20 mins

ReduceLROnPlateau in PyTorch - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
ReduceLROnPlateau Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding ReduceLROnPlateau behavior

What does the ReduceLROnPlateau scheduler do in PyTorch?

AIt increases the learning rate after every epoch regardless of performance.
BIt resets the model weights to initial values when loss plateaus.
CIt reduces the learning rate when a monitored metric stops improving.
DIt stops training automatically when the validation loss stops decreasing.
Attempts:
2 left
💡 Hint

Think about what happens when the model's performance metric does not improve.

Predict Output
intermediate
2:00remaining
Output of learning rate after plateau

Given the following PyTorch code snippet, what will be the learning rate after 3 epochs if the validation loss does not improve?

PyTorch
import torch
import torch.optim as optim

model_params = [torch.nn.Parameter(torch.randn(2, 2, requires_grad=True))]
optimizer = optim.SGD(model_params, lr=0.1)
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=2)

val_losses = [0.5, 0.5, 0.5]

for epoch, loss in enumerate(val_losses):
    scheduler.step(loss)
    print(f"Epoch {epoch+1} LR: {optimizer.param_groups[0]['lr']}")
A
Epoch 1 LR: 0.1
Epoch 2 LR: 0.01
Epoch 3 LR: 0.001
B
Epoch 1 LR: 0.1
Epoch 2 LR: 0.1
Epoch 3 LR: 0.010000000000000002
C
Epoch 1 LR: 0.1
Epoch 2 LR: 0.1
Epoch 3 LR: 0.1
D
Epoch 1 LR: 0.1
Epoch 2 LR: 0.05
Epoch 3 LR: 0.025
Attempts:
2 left
💡 Hint

Remember the patience is 2, so learning rate reduces after 2 epochs without improvement.

Model Choice
advanced
1:30remaining
Choosing correct scheduler for validation accuracy

You want to reduce the learning rate when validation accuracy stops improving. Which mode should you use in ReduceLROnPlateau?

A'max', because accuracy should increase to improve.
B'min', because accuracy should decrease to improve.
C'min', because accuracy is a loss metric.
D'max', because accuracy should decrease to improve.
Attempts:
2 left
💡 Hint

Think about whether accuracy is better when higher or lower.

Hyperparameter
advanced
1:30remaining
Effect of patience parameter in ReduceLROnPlateau

What is the effect of setting a high patience value in ReduceLROnPlateau?

AThe learning rate reduces immediately after one bad epoch.
BThe learning rate stays fixed and never changes.
CThe learning rate increases after many epochs without improvement.
DThe learning rate reduces only after many epochs without improvement.
Attempts:
2 left
💡 Hint

Patience controls how long the scheduler waits before reducing LR.

🔧 Debug
expert
2:30remaining
Why does ReduceLROnPlateau not reduce LR as expected?

Consider this code snippet:

import torch
import torch.optim as optim

model_params = [torch.nn.Parameter(torch.randn(2, 2, requires_grad=True))]
optimizer = optim.Adam(model_params, lr=0.01)
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=1)

val_losses = [0.3, 0.3, 0.3, 0.3]

for epoch, loss in enumerate(val_losses):
    scheduler.step(loss)
    print(f"Epoch {epoch+1} LR: {optimizer.param_groups[0]['lr']}")

Why does the learning rate never reduce?

ABecause the scheduler.step() must be called with a metric that decreases, but here loss is constant, so no improvement triggers LR reduction.
BBecause the optimizer is Adam, which does not support learning rate changes.
CBecause the validation loss never improves, so LR stays the same.
DBecause patience=1 means LR reduces only after 3 epochs without improvement.
Attempts:
2 left
💡 Hint

Check how the scheduler detects improvement and what happens if the metric stays the same.

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

  1. Step 1: Understand the role of learning rate schedulers

    Learning rate schedulers adjust the learning rate during training to improve convergence.
  2. Step 2: Identify what ReduceLROnPlateau does

    This scheduler reduces the learning rate when a monitored metric (like validation loss) stops improving.
  3. Final Answer:

    To reduce the learning rate when a monitored metric stops improving -> Option D
  4. 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

  1. Step 1: Check the correct module and class name

    The correct class is ReduceLROnPlateau inside torch.optim.lr_scheduler.
  2. 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.
  3. Final Answer:

    scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min') -> Option A
  4. 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

  1. Step 1: Understand patience and when LR reduces

    Patience=2 means LR reduces after 2 epochs with no improvement in monitored metric.
  2. 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.
  3. Final Answer:

    0.1 -> Option A
  4. 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

  1. Step 1: Check how ReduceLROnPlateau.step() is called

    This scheduler requires the monitored metric (e.g., val_loss) as an argument in step().
  2. Step 2: Identify missing argument in code

    The code calls scheduler.step() without passing val_loss, causing an error.
  3. Final Answer:

    Missing metric argument in scheduler.step() call -> Option C
  4. 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

  1. Step 1: Determine the mode based on metric type

    Validation accuracy should be maximized, so mode='max' is correct.
  2. Step 2: Set factor and patience correctly

    Factor=0.5 halves the learning rate, patience=3 waits 3 epochs before reducing.
  3. Final Answer:

    scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='max', factor=0.5, patience=3) -> Option B
  4. 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]
Common Mistakes:
  • Using mode='min' for accuracy
  • Setting factor > 1 (increases LR)
  • Confusing patience value