0
0
PyTorchml~10 mins

Checkpoint with optimizer state 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 save the model checkpoint including the optimizer state.

PyTorch
torch.save({'model_state_dict': model.state_dict(), 'optimizer_state_dict': [1], 'checkpoint.pth')
Drag options to blanks, or click blank then click option'
Aoptimizer.state_dict()
Bmodel.state_dict()
Coptimizer.save()
Dmodel.save()
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.state_dict() instead of optimizer.state_dict() for optimizer state
Calling save() method on optimizer which does not exist
2fill in blank
medium

Complete the code to load the optimizer state from the checkpoint.

PyTorch
checkpoint = torch.load('checkpoint.pth')
optimizer.[1](checkpoint['optimizer_state_dict'])
Drag options to blanks, or click blank then click option'
Astate_dict
Bload
Cload_optimizer
Dload_state_dict
Attempts:
3 left
💡 Hint
Common Mistakes
Using load() instead of load_state_dict()
Trying to assign the state dict directly without using the method
3fill in blank
hard

Fix the error in the code to correctly save the checkpoint with model and optimizer states.

PyTorch
torch.save({'model': model.state_dict(), 'optimizer': [1], 'checkpoint.pth')
Drag options to blanks, or click blank then click option'
Aoptimizer.state_dict()
Boptimizer.load_state_dict()
Coptimizer.save()
Dmodel.state_dict()
Attempts:
3 left
💡 Hint
Common Mistakes
Using load_state_dict() instead of state_dict() when saving
Calling save() on optimizer which is not a valid method
4fill in blank
hard

Fill both blanks to correctly load the model and optimizer states from the checkpoint.

PyTorch
checkpoint = torch.load('checkpoint.pth')
model.[1](checkpoint['model'])
optimizer.[2](checkpoint['optimizer'])
Drag options to blanks, or click blank then click option'
Aload_state_dict
Bload
Cstate_dict
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using load() instead of load_state_dict()
Using state_dict property instead of method to load
5fill in blank
hard

Fill all three blanks to save a checkpoint with model state, optimizer state, and current epoch.

PyTorch
torch.save({'model_state_dict': model.[1](), 'optimizer_state_dict': optimizer.[2](), 'epoch': [3], 'checkpoint.pth')
Drag options to blanks, or click blank then click option'
Astate_dict
Bstate_dict()
Ccurrent_epoch
Depoch
Attempts:
3 left
💡 Hint
Common Mistakes
Using state_dict without parentheses which is a property, not a method call
Saving epoch as a string instead of a variable