Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a PyTorch model for deployment.
PyTorch
model = torch.load([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the file path string.
Using incorrect function names to load the model.
✗ Incorrect
The model file path must be a string, so it needs quotes around it.
2fill in blank
mediumComplete the code to set the model to evaluation mode before serving predictions.
PyTorch
model.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.train() which enables training mode.
Trying to call non-existent methods like predict or serve.
✗ Incorrect
Calling model.eval() sets the model to evaluation mode, disabling training behaviors like dropout.
3fill in blank
hardFix the error in the code to get predictions from the model without tracking gradients.
PyTorch
with torch.[1](): output = model(input_tensor)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using torch.grad() which does not exist.
Not disabling gradients during prediction causing unnecessary computation.
✗ Incorrect
torch.no_grad() disables gradient tracking, which is important during prediction to save memory and computation.
4fill in blank
hardFill both blanks to convert model output logits to predicted class indices.
PyTorch
predictions = torch.[1](output, dim=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using softmax instead of argmax returns probabilities, not class indices.
Using wrong dimension for argmax.
✗ Incorrect
torch.argmax with dim=1 returns the index of the highest logit for each sample, which is the predicted class.
5fill in blank
hardFill all three blanks to prepare input tensor, run prediction, and convert output to numpy array for deployment.
PyTorch
input_tensor = torch.tensor([1], dtype=[2]) with torch.no_grad(): output = model(input_tensor) predictions = output.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong data type for tensor.
Forgetting to disable gradients during prediction.
Trying to convert tensor to numpy without calling the method.
✗ Incorrect
Input data is converted to a float tensor, model runs without gradients, and output is converted to a numpy array for easy use outside PyTorch.