0
0
PyTorchml~20 mins

Why tensors are PyTorch's core data structure - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tensor Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why are tensors important in PyTorch?
Which of the following best explains why tensors are the core data structure in PyTorch?
ATensors are simple Python lists that PyTorch uses to store data without any special features.
BTensors allow PyTorch to perform fast mathematical operations on GPUs and CPUs with automatic differentiation support.
CTensors are used only for visualization purposes in PyTorch.
DTensors are only used to store images and cannot be used for other data types.
Attempts:
2 left
💡 Hint
Think about what makes PyTorch fast and flexible for machine learning.
Predict Output
intermediate
2:00remaining
Output of tensor operation with GPU
What will be the output of this PyTorch code snippet?
PyTorch
import torch
x = torch.tensor([1.0, 2.0, 3.0])
if torch.cuda.is_available():
    x = x.to('cuda')
print(x.device)
AError: device not found
Bcpu
Ccuda:1
Dcuda:0
Attempts:
2 left
💡 Hint
Check if CUDA is available and where the tensor is moved.
Model Choice
advanced
2:00remaining
Choosing tensor shape for image data
You want to input a batch of 32 RGB images of size 64x64 into a PyTorch model. Which tensor shape correctly represents this batch?
A[32, 3, 64, 64]
B[3, 32, 64, 64]
C[64, 64, 3, 32]
D[32, 64, 64, 3]
Attempts:
2 left
💡 Hint
PyTorch expects batch size first, then channels, then height and width.
Hyperparameter
advanced
2:00remaining
Effect of tensor dtype on model training
How does changing a tensor's data type (dtype) from float32 to float64 affect PyTorch model training?
AIt has no effect on training speed or memory.
BIt speeds up training and reduces memory usage.
CIt increases precision but slows down training and uses more memory.
DIt causes the model to ignore gradients during backpropagation.
Attempts:
2 left
💡 Hint
Consider the trade-off between precision and computational resources.
🔧 Debug
expert
2:00remaining
Identifying error in tensor operation
What error will this PyTorch code raise?
PyTorch
import torch
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5])
z = x + y
ARuntimeError: The size of tensor a (3) must match the size of tensor b (2) at non-singleton dimension 0
BTypeError: unsupported operand type(s) for +: 'int' and 'list'
CValueError: operands could not be broadcast together with shapes (3,) (2,)
DNo error, output tensor is [5, 7, 3]
Attempts:
2 left
💡 Hint
Check if the tensors have the same shape for element-wise addition.