The Three-Step Dance
Modern model training is the same loop, repeated millions of times:
- Forward pass: feed batch through the network, compute loss.
- Backward pass: backprop computes gradients for every parameter.
- Step: optimizer updates parameters using the gradients.
Repeat until the loss stops dropping. That's it. That's how every neural network in the world is trained.
The Standard PyTorch Idiom
You'll write this pattern thousands of times in deep learning:
for batch in dataloader:
optimizer.zero_grad() # clear stale gradients
pred = model(batch.x) # forward pass
loss = loss_fn(pred, batch.y)
loss.backward() # backward pass — backprop runs here
optimizer.step() # update parameters
Five lines. The whole training loop. Memorize this rhythm; everything fancy in deep learning is built on top of it.
Common Optimizers
- SGD — vanilla. .
- SGD + momentum — accumulates past gradients. Smoother trajectories.
- Adam — per-parameter adaptive learning rates. Modern default. Works with little tuning.
- AdamW — Adam with proper weight decay. Best default for large transformer models.
Forward → Backward → Step. That's the universal training loop. Everything fancy is wrapping or extending these three steps.