Quiz · 06 · PyTorch Fundamentals
42 questions from 8 pages
These are the Check Yourself questions from each page of the module, collected in course order. Each heading links back to the page the questions test. All module quizzes →
Tensors & Autograd
Check yourself
0 / 8 answered
- You run two iterations of forward pass +
loss.backward()without callingzero_grad()in between. What doesw.gradcontain? y = w * x + bwith w=2, x=3, b=1 andloss = (y - 10)**2. What isw.gradafterloss.backward()?- Why do gradients accumulate by default instead of being overwritten?
- What happens if you call
.backward()twice on the same graph withoutretain_graph=True? - What is the difference between
.detach()andtorch.no_grad()? - Why does
model.parameters()require gradients by default but a raw input tensor doesn't? - What does
loss.backward()actually compute mathematically? - Can you call
.backward()on a non-scalar tensor?
Dataset & DataLoader
Check yourself
0 / 6 answered
- GPU utilisation hovers at 30% during training and a profiler shows the model waiting for batches. What do you try first?
- Which setting belongs on a validation DataLoader?
- Why does
__getitem__apply transforms instead of pre-processing the whole dataset once in__init__? - What's the tradeoff of increasing
num_workers? - Why use
drop_last=Truefor training but not always for validation? - What does
collate_fndo and when do you need a custom one?
Training Loop From Scratch
Check yourself
0 / 6 answered
- Which two layer types change behaviour between model.train() and model.eval()?
- Training loss keeps falling while validation loss rises after epoch 5. What is the most likely explanation?
- What's the single most common bug caused by forgetting
model.eval()? - Why is
optimizer.zero_grad()called beforebackward()and not afterstep()? - Why wrap the validation loop in
torch.no_grad()even though you're not callingbackward()there? - How do you compute an epoch-level average loss correctly when the last batch is smaller than the others?
Checkpointing & Mixed Precision
Check yourself
0 / 6 answered
- Why does bfloat16 training usually not need a GradScaler?
- Since PyTorch 2.6, what does torch.load do by default?
- Why save
model.state_dict()instead oftorch.save(model, path)? - What exactly does
GradScalerdo, step by step? - Why does
map_location=devicematter when loading a checkpoint? - Does mixed precision hurt model accuracy?
Debugging & GPU Memory
Check yourself
0 / 7 answered
- Roughly how much memory do parameters + gradients + Adam states need for a 1B-parameter model in full float32 training?
- Memory grows every iteration until an OOM, even at a small batch size. What is the classic cause?
- You get "Expected all tensors to be on the same device, but found at least two devices." What's the most common overlooked cause?
- What's the fastest way to isolate a shape-mismatch bug in a multi-layer model?
- Why does reducing batch size fix a CUDA OOM error?
- What does
torch.cuda.empty_cache()actually do - does it free up "more" memory for training? - A parameter shows
param.grad is Noneafter.backward()- what are the two most likely causes?
PyTorch for LLMs
Check yourself
0 / 3 answered
- Why does bf16 training not need a GradScaler while fp16 does?
- A 13B model's full training state doesn't fit on one 80 GB GPU. What does FSDP2 change compared with DDP?
- You downloaded
model.ptfrom an unfamiliar repository. What is the risk intorch.load('model.pt', weights_only=False), and what should you do instead?
Raw PyTorch Classifier
Check yourself
0 / 3 answered
- The run is interrupted after epoch 3 and restarted with the checkpoint. Which state must the checkpoint contain for training to continue identically?
- Why is GradScaler created with
enabled=use_ampin train.py? - Validation accuracy is noisy between two evaluations of the same checkpoint. What is the first thing to check?
GPT From Scratch
Check yourself
0 / 3 answered
- Your first logged loss is 12.3 with a 256-token vocabulary. What is the most likely problem?
- Why does the model use 2 KV heads for 6 query heads?
- Why is the output projection tied to the input embedding?