01. For an image classification model you want each training image converted to a tensor and then standardized per channel.
Which construction correctly chains these steps in order?
a) ToTensor(Normalize(mean, std))
b) Compose([Normalize(mean, std), ToTensor()])
c) Normalize(ToTensor(), mean, std)
d) Compose([ToTensor(), Normalize(mean, std)])
02. You are choosing which per-channel mean and std to pass to Normalize in your training transform pipeline.
Why is normalizing inputs a common preprocessing step?
a) It increases the effective number of training samples by generating extra augmented copies of the data
b) It rescales features to a comparable range, which keeps gradients well-behaved and stabilizes optimization
c) It guarantees the model cannot overfit by clamping every input feature to a fixed unit range
d) It converts the integer class labels into one-hot encoded target vectors for the loss
03. You already hold your features and labels as two aligned tensors, X and y, and want to feed them to a DataLoader without writing a custom class.
Which utility wraps existing tensors into a ready-to-use dataset?
a) random_split(X, y)
b) Compose(X, y)
c) TensorDataset(X, y)
d) DataLoader(X, y)
04. A colleague removes optimizer.zero_grad() from their training loop, keeping the forward pass, loss.backward(), and optimizer.step() each iteration.
What happens as a result, and why?
a) Nothing changes, because loss.backward() automatically overwrites the previous .grad values on every call, so each step still uses only the current batch.
b) Gradients accumulate into .grad, so each step sums gradients across batches rather than using only the current one, corrupting the updates.
c) Training halts with a runtime error, because PyTorch forbids running another backward pass while non-zero gradients from a prior iteration are still present.
d) The parameters gradually stop updating, because the accumulated gradients from successive batches cancel out to a net value of zero.
05. During evaluation a developer calls model.eval() and then runs the validation batches, but memory usage stays high and the autograd graph is still being built.
Which statement best explains the situation and the fix?
a) model.eval() only switches layers like Dropout and BatchNorm; it does not disable gradient tracking, so also wrap evaluation in a with torch.no_grad(): block.
b) model.eval() already disables autograd, so the persistent memory must instead come from an unrelated leak in the data loader or metric accumulation.
c) You must run a loss.backward() pass during validation to release the graph that eval() would otherwise leave allocated across batches.
d) Switching back to model.train() during validation would disable gradient tracking and lower memory, at the cost of re-enabling Dropout.
06. In a standard PyTorch training loop, you call optimizer.step() after computing the loss and calling loss.backward().
What does optimizer.step() do?
a) It resets all parameter gradients to zero so they are clean before the next iteration.
b) It updates the model parameters using the gradients that were computed during backpropagation.
c) It runs the forward pass over the input batch to produce the predictions the loss is computed from.
d) It computes the gradients of the loss with respect to each of the model's trainable parameters.
07. A teammate defines a classifier whose final layer produces raw logits, then writes:
probs = softmax(logits, dim=1) followed by loss = criterion(probs, targets), where criterion = nn.CrossEntropyLoss().
Why is this a bug, and how should it be fixed?
a) The real bug is the softmax dimension: dim=0 normalizes across the batch, so keeping the softmax but switching it to dim=1 makes the loss correct.
b) The targets must also be one-hot encoded to match the softmax output, and adding that encoding aligns the shapes so the loss computes correctly.
c) There is no bug here; nn.CrossEntropyLoss needs probabilities as input, so applying softmax to the logits first is exactly the required preprocessing.
d) nn.CrossEntropyLoss already applies log-softmax internally, so the extra softmax double-applies it; pass the raw logits instead.
08. When implementing gradient accumulation over several mini-batches, a common mistake is forgetting one step of the loop.
Which step is essential to accumulate correctly?
a) Call optimizer.zero_grad() only after the accumulated optimizer.step(), not after every mini-batch.
b) Move the model to the CPU in between the mini-batches so that accumulated gradient memory is freed.
c) Call optimizer.zero_grad() after every single mini-batch so the gradients never overlap between steps.
d) Detach the loss with .item() before you call backward() on it each iteration.
09. A model applies an in-place ReLU (the variant ending in _) to a tensor whose original values are later needed to compute gradients during backward(). The run raises an autograd error about a value modified in place.
Why does the in-place operation cause this?
a) The error happens because in-place operations are forced to run on the CPU while the rest of the model runs on the GPU.
b) In-place ops double the tensor's memory use, triggering an out-of-memory failure that surfaces as an autograd error.
c) The in-place op overwrote a value autograd had saved for the backward pass, so the gradient can no longer be computed.
d) In-place operations are always disallowed anywhere inside a model that relies on autograd for its gradients.
10. During inference you wrap the forward pass in torch.no_grad().
What does torch.no_grad() do?
a) It moves the model along with all of its input tensors onto the GPU so that the forward pass runs faster.
b) It permanently deletes the gradients already stored on the model's parameters.
c) It switches dropout and batch-norm layers into their evaluation behavior for correct inference.
d) It disables gradient tracking so autograd does not build the computation graph, saving memory and time.