PyTorch basics
For engineers
Tensors, autograd, nn.Module and DataLoader, a complete training loop, and debugging shapes, devices and NaN losses, including in AI-written code
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
A tensor has shape [32, 1] and another has shape [32]. You subtract one from the other. What shape comes out?
Check yourself · 2 of 5
You call loss.backward() three times in a row on freshly built graphs without zeroing. What does w.grad hold?
Check yourself · 3 of 5
Which two methods must a custom torch Dataset implement?
Check yourself · 4 of 5
Which order is correct inside one training step?
Check yourself · 5 of 5
A traceback says mat1 and mat2 shapes cannot be multiplied (32x784 and 100x10). What does it mean?
Topics
- Tensors, dtypes and devices4 min read · Creating, reshaping and broadcasting tensors, choosing float32 or bfloat16, and keeping data on one device across CPU, CUDA and Apple MPS
- Autograd and computation graphs4 min read · How requires_grad and backward() produce gradients, why .grad accumulates until zero_grad, and when to use torch.no_grad for inference
- Models with nn.Module and DataLoader4 min read · Defining and registering layers in an nn.Module, batching data with Dataset and DataLoader, and switching correctly between train and eval mode
- Writing a PyTorch training loop5 min read · The forward, loss, zero_grad, backward and step sequence, plus a no-grad validation pass and saving the best checkpoint
- Debugging shape errors and NaN losses5 min read · Reading tracebacks, printing shapes, overfitting one batch and chasing NaN losses, including bugs hidden in agent-written PyTorch code
Start here
- Learn the Basics (PyTorch tutorials) (opens in a new tab)DocsFree
Official end-to-end walk through tensors, datasets, models, autograd, optimization and saving.
- PyTorch tutorials: automatic differentiation with torch.autograd (opens in a new tab)DocsFree
Short, runnable explanation of requires_grad, backward and no_grad.
- PyTorch notes: autograd mechanics (opens in a new tab)DocsFree
How the graph is built and freed and how gradients accumulate.
Helps to know first
110 questions · last verified 2026-12