PythonFan.org
Toggle Menu
Home
Online Python Compiler
Tutorials
Python FastAPI
Python Pandas
Python PyTorch
Python Seaborn
Blog
All Posts
PyTorch Fundamentals
Test your understanding of tensors,autograd,and model building.
1. What is the basic building block of data in PyTorch?
Array
Tensor
Matrix
Vector
2. Which PyTorch function creates a tensor with values sampled from a standard normal distribution (mean=0, variance=1)?
torch.rand
torch.zeros
torch.randn
torch.ones
3. Which method is used to enable gradient computation for a tensor?
.requires_grad_()
.grad()
.backward()
.detach()
4. What is the default data type of a tensor created with torch.tensor([1, 2, 3])?
torch.float32
torch.int64
torch.int32
torch.bool
5. By default, where are PyTorch tensors stored?
GPU
TPU
CPU
MPS
6. What does the torch.cat function do?
Splits a tensor into chunks
Concatenates tensors along a specified dimension
Stacks tensors along a new dimension
Transposes tensor dimensions
7. Which PyTorch module provides tools for building neural networks?
torch.autograd
torch.optim
torch.nn
torch.utils.data
8. What is the shape of the tensor created by torch.rand(3, 4, 2)?
(3, 4)
(4, 2)
(3, 4, 2)
(2, 3, 4)
9. Which method prevents a tensor from tracking gradients?
.detach()
.backward()
.requires_grad_()
.grad.zero_()
10. What is the result of torch.ones(2, 2) * 3?
A tensor with all elements 3
A tensor with all elements 1
A tensor with shape (3, 3)
An error
11. Which of the following are valid ways to create a tensor with ones in PyTorch?
torch.ones(3)
torch.ones_like(torch.zeros(2,2))
torch.full((2,2), 1)
torch.empty(3).fill_(1)
12. Which operations are element-wise in PyTorch?
tensor1 + tensor2
tensor1 @ tensor2
tensor1 * tensor2
torch.matmul(tensor1, tensor2)
13. Which are components of a PyTorch training loop?
Forward pass
Loss computation
Backward pass
Parameter update
14. Which data types are supported by PyTorch tensors?
torch.float32
torch.int64
torch.bool
torch.string
15. PyTorch's autograd automatically computes gradients for tensor operations.
True
False
16. Tensors must be on GPU to use autograd.
True
False
17. torch.Tensor is an alias for torch.FloatTensor.
True
False
18. What does 'Py' in PyTorch stand for?
19. Name the PyTorch module for optimization (abbrev.)
20. Output of torch.tensor([2, 3]) + torch.tensor([4, 5])?
Reset
Answered 0 of 0 — 0 correct