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 a learning rate scheduler in PyTorch?
A learning rate scheduler is a tool that changes the learning rate during training to help the model learn better and faster.
Click to reveal answer
beginner
Why do we adjust the learning rate during training?
Adjusting the learning rate helps the model avoid getting stuck and improves accuracy by starting with bigger steps and then taking smaller steps as it learns.
Click to reveal answer
intermediate
Name two common types of learning rate schedulers in PyTorch.
StepLR and ExponentialLR are two common schedulers. StepLR reduces the learning rate after fixed steps, ExponentialLR reduces it smoothly over time.
Click to reveal answer
intermediate
How does StepLR scheduler work?
StepLR lowers the learning rate by a factor every few epochs, like turning down the volume step by step.
Click to reveal answer
beginner
What is the benefit of using a learning rate scheduler?
It helps the model train more efficiently by adjusting learning speed, leading to better results and less chance of missing the best solution.
Click to reveal answer
What does a learning rate scheduler do during training?
AChanges the loss function
BChanges the model architecture
CChanges the training data
DChanges the learning rate over time
✗ Incorrect
A learning rate scheduler adjusts the learning rate during training to improve learning.
Which PyTorch scheduler reduces learning rate after fixed steps?
AExponentialLR
BStepLR
CCosineAnnealingLR
DReduceLROnPlateau
✗ Incorrect
StepLR reduces the learning rate by a factor every fixed number of epochs.
Why start training with a higher learning rate?
ATo increase loss
BTo avoid training
CTo make big learning steps initially
DTo reduce model size
✗ Incorrect
Starting with a higher learning rate helps the model learn faster at the beginning.
What happens if learning rate is too high all the time?
AModel may not learn well or miss best solution
BModel learns perfectly
CTraining is faster and better
DModel size increases
✗ Incorrect
Too high learning rate can cause the model to miss the best solution or not learn properly.
Which scheduler adjusts learning rate based on validation loss?
AReduceLROnPlateau
BStepLR
CExponentialLR
DCosineAnnealingLR
✗ Incorrect
ReduceLROnPlateau lowers learning rate when validation loss stops improving.
Explain in your own words why learning rate schedulers are useful in training neural networks.
Think about how changing speed helps when learning something new.
You got /4 concepts.
Describe how the StepLR scheduler changes the learning rate during training.
Imagine turning down volume in steps after some time.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using a learning rate scheduler in PyTorch training?
easy
A. To change the model architecture dynamically
B. To increase the batch size automatically
C. To shuffle the training data at each epoch
D. To adjust the learning rate during training for better model performance
Solution
Step 1: Understand the role of learning rate
The learning rate controls how fast the model updates its knowledge during training.
Step 2: Identify what a scheduler does
A learning rate scheduler changes the learning rate over time to improve training stability and performance.
Final Answer:
To adjust the learning rate during training for better model performance -> Option D
StepLR reduces learning rate by gamma every step_size epochs. Here, step_size=2, gamma=0.5.
Step 2: Calculate learning rate after 3 steps
After 1 step: lr=0.1 (no change, step 1 < 2) After 2 steps: lr=0.1 * 0.5 = 0.05 (step 2 reached) After 3 steps: lr remains 0.05 (step 3 < 4)
Final Answer:
0.05 -> Option A
Quick Check:
StepLR halves lr every 2 steps [OK]
Hint: Learning rate changes only at multiples of step_size [OK]
Common Mistakes:
Reducing learning rate every step instead of every step_size
Multiplying gamma incorrectly
Ignoring initial learning rate
4. Identify the error in the following PyTorch learning rate scheduler code:
import torch
opt = torch.optim.Adam([torch.nn.Parameter(torch.randn(3, 3, requires_grad=True))], lr=0.01)
scheduler = torch.optim.lr_scheduler.ExponentialLR(opt, gamma=0.9)
for epoch in range(5):
scheduler.step()
print(f"Epoch {epoch}: lr = {opt.param_groups[0]['lr']}")
medium
A. Learning rate should be set inside the loop
B. scheduler.step() should be called after optimizer.step()
C. ExponentialLR does not exist in PyTorch
D. gamma value must be greater than 1
Solution
Step 1: Recall correct scheduler usage
In PyTorch, scheduler.step() should be called after optimizer.step() to update learning rate correctly.
Step 2: Check code order
The code calls scheduler.step() before any optimizer.step(), which is incorrect and may cause unexpected lr updates.
Final Answer:
scheduler.step() should be called after optimizer.step() -> Option B
Quick Check:
Call scheduler.step() after optimizer.step() [OK]
Hint: Always call scheduler.step() after optimizer.step() [OK]
Common Mistakes:
Calling scheduler.step() before optimizer.step()
Using invalid gamma values
Misunderstanding scheduler existence
5. You want to train a model where the learning rate starts at 0.1, then reduces by half every 5 epochs, but after 20 epochs, it should decay exponentially by 0.9 every epoch. Which PyTorch scheduler setup achieves this behavior?
hard
A. Use CosineAnnealingLR with T_max=20 and then StepLR with step_size=5, gamma=0.5
B. Use ExponentialLR with gamma=0.9 from start and manually adjust learning rate at epoch 20
C. Use StepLR with step_size=5, gamma=0.5 for first 20 epochs, then switch to ExponentialLR with gamma=0.9
D. Use StepLR with step_size=20, gamma=0.5 and ignore exponential decay
Solution
Step 1: Understand the two-phase learning rate schedule
First phase: reduce lr by half every 5 epochs for 20 epochs. Second phase: after 20 epochs, apply exponential decay by 0.9 every epoch.
Step 2: Match PyTorch schedulers to phases
StepLR with step_size=5, gamma=0.5 fits first phase. ExponentialLR with gamma=0.9 fits second phase. Switching schedulers after 20 epochs achieves desired behavior.
Final Answer:
Use StepLR with step_size=5, gamma=0.5 for first 20 epochs, then switch to ExponentialLR with gamma=0.9 -> Option C
Quick Check:
Combine StepLR then ExponentialLR for phased decay [OK]
Hint: Combine schedulers for multi-phase learning rate changes [OK]