Skip to course content
Free PyTorch course

Advanced Deep Learning with PyTorch

Module 03 Activity

Scenario

A training loop that runs is not a training loop that works. Build one whose correctness you can prove.

Task

  1. Compute a forward pass and a loss. Confirm the loss is a scalar with a grad_fn.
  2. Verify a gradient by hand: for y = w * x with x = 3, w.grad must be 3.
  3. Work the chain-rule example on paper, then check a.grad and b.grad against your arithmetic.
  4. Demonstrate gradient accumulation by calling .backward() twice without clearing.
  5. Train on data generated by a known rule and confirm the learned parameters recover it.
  6. Checkpoint on validation loss and reload, confirming the restored score matches.

Deliverable

A training script plus a note recording the hand-calculated gradients and the recovered coefficients.

Check your work

The habit

Validate a loop on a problem whose answer you already know. A falling loss is not proof.