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 StepLR in PyTorch?
StepLR is a learning rate scheduler that decreases the learning rate by a fixed factor every set number of epochs. It helps the model learn more slowly as training progresses.
Click to reveal answer
intermediate
How does MultiStepLR differ from StepLR?
MultiStepLR decreases the learning rate at specific epochs (called milestones) instead of fixed intervals. This allows more control over when the learning rate changes.
Click to reveal answer
beginner
What parameters do you need to provide to StepLR?
You need to provide the optimizer, step_size (number of epochs between each decrease), and gamma (the factor to multiply the learning rate by).
Click to reveal answer
beginner
What are milestones in MultiStepLR?
Milestones are a list of epoch numbers where the learning rate will be decreased by multiplying with gamma.
Click to reveal answer
beginner
Why use learning rate schedulers like StepLR or MultiStepLR?
They help the model converge better by reducing the learning rate over time, which can improve accuracy and prevent overshooting the best solution.
Click to reveal answer
What does StepLR do to the learning rate?
AKeeps it constant
BIncreases it gradually
CRandomly changes it
DReduces it by a fixed factor every few epochs
✗ Incorrect
StepLR reduces the learning rate by multiplying it by gamma every step_size epochs.
In MultiStepLR, what are milestones?
ANumber of batches per epoch
BEpochs where learning rate changes
CInitial learning rates
DLoss values
✗ Incorrect
Milestones are specific epochs where the learning rate is decreased.
Which parameter controls how much the learning rate decreases in StepLR?
Agamma
Bstep_size
Cmilestones
Dmomentum
✗ Incorrect
Gamma is the factor multiplied with the learning rate to reduce it.
If you want to reduce learning rate at epochs 30 and 80, which scheduler is best?
AStepLR
BNo scheduler
CMultiStepLR
DExponentialLR
✗ Incorrect
MultiStepLR lets you specify exact epochs (milestones) to reduce the learning rate.
What is the main benefit of using learning rate schedulers?
AImprove model convergence and accuracy
BPrevent model from learning
CIncrease model size
DFaster training without accuracy loss
✗ Incorrect
Schedulers help the model converge better by adjusting learning rate during training.
Explain how StepLR works and what parameters it needs.
Think about a clock ticking every few epochs to reduce learning rate.
You got /3 concepts.
Describe the difference between StepLR and MultiStepLR and when you might use each.
Compare fixed steps vs chosen milestones.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between StepLR and MultiStepLR in PyTorch?
easy
A. StepLR decreases learning rate at fixed intervals; MultiStepLR decreases at specific epochs.
B. StepLR increases learning rate; MultiStepLR decreases learning rate.
C. StepLR changes learning rate randomly; MultiStepLR keeps it constant.
D. StepLR is used only for batch size adjustment; MultiStepLR for learning rate.
Solution
Step 1: Understand StepLR behavior
StepLR reduces the learning rate by a factor every fixed number of epochs (step size).
Step 2: Understand MultiStepLR behavior
MultiStepLR reduces the learning rate at specific epochs defined by a list of milestones.
Final Answer:
StepLR decreases learning rate at fixed intervals; MultiStepLR decreases at specific epochs. -> Option A
Quick Check:
StepLR fixed steps, MultiStepLR specific milestones [OK]
2. Which of the following is the correct way to create a StepLR scheduler in PyTorch that reduces learning rate every 5 epochs by a factor of 0.1?
easy
A. scheduler = StepLR(optimizer, step_size=5, gamma=0.1)
B. scheduler = StepLR(optimizer, milestones=[5], gamma=0.1)
C. scheduler = MultiStepLR(optimizer, step_size=5, gamma=0.1)
D. scheduler = MultiStepLR(optimizer, milestones=[5], gamma=0.1)
Solution
Step 1: Recall StepLR parameters
StepLR takes step_size (int) and gamma (decay factor).
Step 2: Identify correct syntax
scheduler = StepLR(optimizer, step_size=5, gamma=0.1) uses step_size=5 and gamma=0.1, which matches the requirement.
Final Answer:
scheduler = StepLR(optimizer, step_size=5, gamma=0.1) -> Option A
Quick Check:
StepLR uses step_size, not milestones [OK]
Hint: StepLR uses step_size, MultiStepLR uses milestones list [OK]
Common Mistakes:
Using milestones parameter with StepLR
Confusing MultiStepLR and StepLR syntax
Passing step_size as a list
3. Given the following code, what will be the learning rate after epoch 7?
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
scheduler = MultiStepLR(optimizer, milestones=[3, 6], gamma=0.1)
for epoch in range(8):
scheduler.step()
print(f"Epoch {epoch}: lr = {optimizer.param_groups[0]['lr']}")
medium
A. 0.01
B. 0.001
C. 0.1
D. 0.0001
Solution
Step 1: Understand milestones and gamma
Learning rate reduces by factor 0.1 at epochs 3 and 6.
Step 2: Calculate learning rate at epoch 7
Initial lr=0.1; after epoch 3: 0.1*0.1=0.01; after epoch 6: 0.01*0.1=0.001; so at epoch 7 lr=0.001.
Final Answer:
0.001 -> Option B
Quick Check:
Two milestones reduce lr twice: 0.1 -> 0.01 -> 0.001 [OK]
Hint: Multiply lr by gamma at each milestone passed [OK]
Common Mistakes:
Forgetting to apply gamma at both milestones
Assuming lr changes before first milestone
Confusing StepLR with MultiStepLR behavior
4. Identify the error in this code snippet using StepLR:
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
scheduler = StepLR(optimizer, milestones=[10, 20], gamma=0.5)
for epoch in range(25):
scheduler.step()
print(optimizer.param_groups[0]['lr'])
medium
A. scheduler.step() must be called after optimizer.step() inside loop.
B. Optimizer Adam cannot be used with StepLR scheduler.
C. StepLR does not accept milestones parameter; use step_size instead.
D. Gamma value must be greater than 1 for StepLR.
Solution
Step 1: Check StepLR parameters
StepLR expects step_size, not milestones.
Step 2: Identify misuse of milestones
Passing milestones causes error; correct is step_size=10 for example.
Final Answer:
StepLR does not accept milestones parameter; use step_size instead. -> Option C
Quick Check:
StepLR uses step_size, not milestones [OK]
Hint: StepLR uses step_size, not milestones list [OK]
Common Mistakes:
Using milestones with StepLR
Thinking Adam optimizer is incompatible
Misunderstanding gamma parameter range
5. You want to train a model for 30 epochs. You want the learning rate to drop by 0.1 at epochs 10 and 20, and then again every 5 epochs after epoch 20. Which scheduler setup correctly achieves this?
hard
A. Use StepLR with step_size=10 and gamma=0.1
B. Use StepLR with step_size=5 and gamma=0.1
C. Use MultiStepLR with milestones=[10, 20, 25, 30] and gamma=0.1
D. Use MultiStepLR with milestones=[10, 20] and gamma=0.1, then StepLR with step_size=5 after epoch 20
Solution
Step 1: Understand the requirement
Learning rate drops at epochs 10 and 20, then every 5 epochs after 20 (i.e., 25, 30).
Step 2: Analyze scheduler options
MultiStepLR can handle fixed milestones (10, 20). StepLR can handle regular steps (every 5 epochs). Combining both after epoch 20 fits the requirement.
Step 3: Evaluate options
Use MultiStepLR with milestones=[10, 20, 25, 30] and gamma=0.1 misses epochs after 20 beyond 25 and 30; Use StepLR with step_size=5 and gamma=0.1 drops every 5 epochs from start; Use StepLR with step_size=10 and gamma=0.1 drops every 10 epochs only; Use MultiStepLR with milestones=[10, 20] and gamma=0.1, then StepLR with step_size=5 after epoch 20 correctly combines both schedulers.
Final Answer:
Use MultiStepLR with milestones=[10, 20] and gamma=0.1, then StepLR with step_size=5 after epoch 20 -> Option D
Quick Check:
Combine MultiStepLR for early milestones + StepLR for regular steps after [OK]
Hint: Combine MultiStepLR for milestones + StepLR for regular steps [OK]
Common Mistakes:
Trying to use only one scheduler for mixed schedule