Skip to content
BIASED

PyTorch and automatic differentiation

Block 1 of 7~1 min

From the loop to a library

The topic What deep learning is reduced training any network to one loop: take a batch, run the model forward, compute the loss, run backward for the gradient, take a step. A library must supply four things for that loop: arrays that hold batches and parameters, a forward pass that remembers what it computed, a backward pass that turns that memory into gradients, and optimizers that apply them. This topic covers how PyTorch supplies each, builds reverse-mode differentiation for scalars from scratch, and ends with the bugs that make a pipeline run without errors and still train badly.

Notation. LL is a scalar loss and uˉ=∂L/∂u\bar u = \partial L / \partial u is the adjoint of a quantity uu, with the same shape as uu. A tensor's shape is written like (64,10)(64, 10); dimension 0 is the first. η\eta is the learning rate.

Answers are saved on the server and tied to this browser until you sign in.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • Broadcasting, gradients, and tensor shapeoptional

    NumPy notebook — silent (n,1)×(n,) broadcasting, grad accumulation without clearing, and shape alignment. Self-check in the notebook.

    ~25 min · easier on a computer · The PyTorch and autograd topic read; basic NumPy.

    Self-check in the notebook — not part of mastery or the certificate.

  • Softmax in codeoptional

    Turn a batch of logits into distributions without overflowing.

    ~15 min · easier on a computer · The PyTorch and autograd topic; softmax along the class axis.

    Open practice