Challenge - 5 Problems
PyTorch Computation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this PyTorch tensor operation?
Consider the following PyTorch code that creates two tensors and adds them. What is the output tensor?
PyTorch
import torch x = torch.tensor([1, 2, 3]) y = torch.tensor([4, 5, 6]) z = x + y print(z)
Attempts:
2 left
💡 Hint
Remember that adding two tensors of the same shape adds their elements one by one.
✗ Incorrect
Adding two tensors element-wise sums each corresponding element. So [1+4, 2+5, 3+6] = [5, 7, 9].
❓ Model Choice
intermediateChoosing the right PyTorch tensor for GPU computation
You want to perform fast matrix multiplication on a GPU using PyTorch. Which tensor creation method ensures the tensor is on the GPU?
Attempts:
2 left
💡 Hint
To use GPU, the tensor must be created or moved to the CUDA device.
✗ Incorrect
Specifying device='cuda' creates the tensor directly on the GPU, enabling fast GPU computations.
❓ Metrics
advancedInterpreting training loss and accuracy in PyTorch
During training a classification model in PyTorch, you observe the following after one epoch: training loss = 0.8, training accuracy = 0.65. What does this mean?
Attempts:
2 left
💡 Hint
Loss measures prediction error; accuracy measures correct predictions percentage.
✗ Incorrect
Loss quantifies how wrong the model predictions are; accuracy shows the fraction of correct predictions. Here, 65% accuracy means 65% correct predictions, and 0.8 loss indicates moderate error.
🔧 Debug
advancedWhy does this PyTorch code raise an error?
What error does this PyTorch code raise and why?
import torch
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5])
z = x + y
PyTorch
import torch x = torch.tensor([1, 2, 3]) y = torch.tensor([4, 5]) z = x + y
Attempts:
2 left
💡 Hint
Check if the two tensors have the same shape or compatible shapes for addition.
✗ Incorrect
PyTorch requires tensors to have the same shape or broadcastable shapes for element-wise operations. Here, shapes (3,) and (2,) are incompatible, causing a RuntimeError.
🧠 Conceptual
expertUnderstanding autograd in PyTorch
Which statement best describes how PyTorch's autograd system works during backpropagation?
Attempts:
2 left
💡 Hint
Think about how PyTorch tracks operations to compute gradients automatically.
✗ Incorrect
PyTorch's autograd tracks operations on tensors that require gradients, building a graph to compute derivatives automatically during backpropagation.
