Challenge - 5 Problems
Parameter Inspector Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of model parameter count code
What is the output of the following PyTorch code that counts the total number of parameters in a simple linear model?
PyTorch
import torch import torch.nn as nn model = nn.Linear(3, 2) param_count = sum(p.numel() for p in model.parameters()) print(param_count)
Attempts:
2 left
💡 Hint
Remember that nn.Linear has weights and biases. Weights shape is (out_features, in_features).
✗ Incorrect
The linear layer has weights of shape (2,3) = 6 parameters and biases of shape (2,) = 2 parameters, total 8.
🧠 Conceptual
intermediate2:00remaining
Understanding requires_grad attribute
Which statement correctly describes the effect of setting requires_grad=False on a model parameter in PyTorch?
Attempts:
2 left
💡 Hint
Think about what happens when gradients are not computed for a parameter.
✗ Incorrect
If requires_grad=False, PyTorch does not compute gradients for that parameter, so optimizer does not update it.
❓ Metrics
advanced2:00remaining
Inspecting model parameter shapes
Given the following PyTorch model, what is the shape of the parameter named 'fc2.weight'?
PyTorch
import torch.nn as nn class SimpleNN(nn.Module): def __init__(self): super().__init__() self.fc1 = nn.Linear(10, 5) self.fc2 = nn.Linear(5, 2) model = SimpleNN() print(model.fc2.weight.shape)
Attempts:
2 left
💡 Hint
Recall that nn.Linear weight shape is (out_features, in_features).
✗ Incorrect
fc2 is Linear(5, 2), so weight shape is (2, 5).
🔧 Debug
advanced2:00remaining
Identifying error when accessing model parameters
What error will the following code raise when trying to access a non-existent parameter 'fc3.weight' in a PyTorch model?
PyTorch
import torch.nn as nn model = nn.Sequential( nn.Linear(4, 3), nn.ReLU(), nn.Linear(3, 2) ) param = dict(model.named_parameters())['fc3.weight']
Attempts:
2 left
💡 Hint
Check what keys are in the named_parameters dictionary.
✗ Incorrect
The model has no parameter named 'fc3.weight', so accessing it raises KeyError.
❓ Model Choice
expert3:00remaining
Choosing model to inspect parameters for convolutional layers
You want to inspect the parameters of a convolutional neural network with two Conv2d layers. Which model definition will allow you to correctly access the weight tensor of the second convolutional layer as 'conv2.weight'?
Attempts:
2 left
💡 Hint
Only named attributes can be accessed by their names directly.
✗ Incorrect
Only in option C the second conv layer is named 'conv2', so model.conv2.weight works.