The checkpoint dictionary contains keys 'model_state', 'optimizer_state', and 'epoch'.
Step 2: Identify printed value
Variable 'epoch' is assigned checkpoint['epoch'], so print(epoch) outputs the saved epoch number.
Final Answer:
The epoch number saved in the checkpoint -> Option D
Quick Check:
Print epoch from checkpoint = epoch number [OK]
Hint: Print shows saved epoch from checkpoint dictionary [OK]
Common Mistakes:
Thinking print shows model parameters count
Confusing optimizer state with epoch
Assuming missing keys cause error here
4. You tried to resume training but got an error: RuntimeError: Error(s) in loading state_dict. What is the most likely cause related to checkpointing?
medium
A. The training data was modified after checkpointing
B. The checkpoint file was saved with torch.load instead of torch.save
C. The model architecture changed after saving the checkpoint
D. The optimizer state was not saved in the checkpoint
Solution
Step 1: Understand error meaning
Loading state_dict errors usually happen if model layers differ from saved checkpoint.
Step 2: Connect error to checkpoint cause
If model architecture changed after saving, weights won't match, causing this error.
Final Answer:
The model architecture changed after saving the checkpoint -> Option C
Quick Check:
State_dict error = architecture mismatch [OK]
Hint: Mismatch model layers cause state_dict loading errors [OK]
Common Mistakes:
Confusing save/load functions causing error
Assuming missing optimizer state causes this error
Blaming training data changes for state_dict error
5. You want to checkpoint your training every 5 epochs to avoid losing progress. Which approach best preserves training progress including optimizer state and epoch count?
hard
A. Save a dictionary with model.state_dict(), optimizer.state_dict(), and current epoch number
B. Save only model.state_dict() every 5 epochs
C. Save optimizer.state_dict() and epoch number but not model weights
D. Save the training data batch every 5 epochs
Solution
Step 1: Identify what preserves full training state
Saving model weights, optimizer state, and epoch number allows full resume.
Step 2: Compare options
Only saving model weights misses optimizer info; saving optimizer and epoch without model is incomplete; saving data batch doesn't preserve progress.
Final Answer:
Save a dictionary with model.state_dict(), optimizer.state_dict(), and current epoch number -> Option A
Quick Check:
Checkpoint = model + optimizer + epoch [OK]
Hint: Checkpoint all: model, optimizer, and epoch for full resume [OK]
Common Mistakes:
Saving only model weights loses optimizer progress
Ignoring epoch number causes restart from zero
Saving training data batch does not preserve model state