internalsGet Pro

Module 04 · Lesson 11 of 11Pro

Automatic differentiation: how PyTorch finds gradients

Level
Intermediate
Topic
Calculus and optimization for machine learning
Reading time
16 min

When you finish this page you can

  1. Trace the graph PyTorch records during a forward pass, and work out by hand the slope each node passes back.
  2. Explain why reverse mode gets every weight’s slope from one backward pass, and when forward mode or finite differences win instead.
  3. Predict when .grad accumulates, when the graph is freed, and when no_grad or detach is the right tool.
  4. Find the cause of doubled gradients, growing memory and in-place errors in a training loop.
  1. PyTorch tensors: shapes, axes and operations14 min
  2. The chain rule: derivatives through layers14 min
  3. Gradients: derivatives with many inputs14 min

The gradient doubled when Farah reran the cell

is our example online store. Every Monday, Joseph’s growth team sends vouchers to the customers most likely to : to stop buying. Farah, an ML engineer, is training the model that gives each customer that probability, on her notebook sample of 200,000 customers.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan