In PyTorch, which function creates a tensor filled with zeros of shape (2, 3)?
Pytorch Fundamentals
Question · Easy
What attribute must a tensor have set to True for autograd to track operations and compute its gradient during backpropagation?
Which method moves a tensor x onto a CUDA GPU device in a device-agnostic way that also works on CPU-only machines?
Question · Medium
Tech Exam Prep Podcast
Listen on Spotify
Podcast
What does calling .backward() on a scalar loss tensor do?
Which statement about torch.Tensor.view() versus torch.Tensor.reshape() is correct?
What does tensor.detach() return?
By convention, what do PyTorch tensor methods ending in an underscore, such as add_() or relu_(), indicate?
Which context manager disables gradient tracking to speed up inference and reduce memory usage?
Given a = torch.tensor([1.0, 2.0, 3.0]), what does a.shape return?
Which operation performs matrix multiplication of two 2-D tensors A and B in PyTorch?
What does torch.unsqueeze(x, 0) do to a tensor x of shape (3, 4)?
Why does accessing the .grad attribute of a non-leaf intermediate tensor return None by default after backward()?
Question · Hard
Which call converts a PyTorch tensor t on CPU to a NumPy array that shares memory with the tensor?
What is the default floating-point data type of a tensor created with torch.tensor([1.0, 2.0])?
Calling x.item() on a tensor is valid only when the tensor has how many elements?
When adding a tensor of shape (3, 1) to a tensor of shape (1, 4), what is the resulting shape due to broadcasting?
Which function returns the index of the maximum value along a given dimension, useful for selecting a predicted class from logits?
What does torch.cuda.is_available() return?
Why must both a model and its input tensors reside on the same device before a forward pass?
What is a leaf tensor in the autograd graph?
Which torch function concatenates a list of tensors along an existing dimension without adding a new one?
What happens to gradients stored in leaf tensors across multiple backward() calls if zero_grad() is never invoked?
Which base class must a custom neural network module subclass in PyTorch?
Building Neural Networks
In a class that subclasses nn.Module, where should the network's computation be implemented so that it runs when you call the module instance like model(x)?
Which layer applies a fully connected (dense) affine transformation y = xA^T + b?
Which container holds an ordered sequence of modules and passes input through them in order during forward()?
Which activation function outputs max(0, x), zeroing negative inputs and passing positive inputs unchanged?
For a multi-class classification problem with raw logits as model output, which loss function is appropriate and applies softmax internally?
When constructing an optimizer such as torch.optim.SGD, what should be passed as the first argument?
Which optimizer maintains per-parameter adaptive learning rates using estimates of first and second moments of the gradients?
What does model.parameters() return for an nn.Module?
Which 2-D convolution layer is correctly configured for an RGB image input with 3 channels producing 16 feature maps using 3x3 kernels?
What is the purpose of nn.Dropout(p=0.5) during training?
Why is wrapping a learnable weight tensor in nn.Parameter (rather than using a plain tensor) important inside an nn.Module?
For binary classification, which loss function combines a sigmoid layer and binary cross-entropy in a single numerically stable operation that accepts raw logits?
What does the lr argument in torch.optim.SGD(model.parameters(), lr=0.01) control?
Which normalization layer normalizes each feature channel using batch statistics during training and running estimates during evaluation?
When defining submodules in a custom nn.Module, why should you create them in __init__ and assign them to self attributes rather than instantiating them inside forward()?
Which activation converts a vector of logits into a probability distribution that sums to 1 along a chosen dimension?
What does calling optimizer.zero_grad() do?
When building a custom map-style Dataset by subclassing torch.utils.data.Dataset, which two methods must you implement?
Data Handling
What is the primary role of torch.utils.data.DataLoader?
In a DataLoader, what does setting shuffle=True accomplish, and when is it typically used?
What does the num_workers argument of a DataLoader control?
Which torchvision transform composes multiple transforms so they are applied in sequence to each sample?
When iterating a DataLoader with batch_size=32 over a dataset of 100 samples, how many batches are produced if drop_last=False?
What is the purpose of a custom collate_fn in a DataLoader?
Loading more…