0
0
PyTorchml~10 mins

StepLR and MultiStepLR in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a StepLR scheduler that decreases the learning rate every 5 epochs.

PyTorch
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=[1], gamma=0.1)
Drag options to blanks, or click blank then click option'
A10
B5
C3
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong step_size value that doesn't match the desired interval.
2fill in blank
medium

Complete the code to create a MultiStepLR scheduler that decreases the learning rate at epochs 10 and 20.

PyTorch
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[1], gamma=0.1)
Drag options to blanks, or click blank then click option'
A[12, 22]
B[5, 15]
C[8, 18]
D[10, 20]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong milestone epochs that don't match the schedule.
3fill in blank
hard

Fix the error in the code to correctly update the learning rate scheduler after each epoch.

PyTorch
for epoch in range(num_epochs):
    train()
    validate()
    [1]
Drag options to blanks, or click blank then click option'
Ascheduler.step()
Bscheduler.update()
Cscheduler.adjust()
Dscheduler.reset()
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like update(), adjust(), or reset().
4fill in blank
hard

Fill both blanks to create a StepLR scheduler with a step size of 7 and a decay factor of 0.5.

PyTorch
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=[1], gamma=[2])
Drag options to blanks, or click blank then click option'
A7
B0.1
C0.5
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up step_size and gamma values.
5fill in blank
hard

Fill all three blanks to create a MultiStepLR scheduler with milestones at epochs 8 and 16, and a decay factor of 0.2.

PyTorch
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[1], gamma=[2])

for epoch in range(num_epochs):
    train()
    validate()
    [3]
Drag options to blanks, or click blank then click option'
A[8, 16]
Bscheduler.step()
C0.2
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong milestone epochs, wrong gamma, or forgetting to call scheduler.step().