← All notes

How PyTorch autograd works

Answer: Conceptually, autograd records a graph recording all of the operations that created the data as you execute operations, giving you a directed acyclic graph whose leaves are the input tensors and roots are the output tensors. By tracing this graph from roots to leaves, you can automatically compute the gradients using the chain rule. (S1)

Forward and backward

requires_grad and leaves

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PyTorch docs, Autograd mechanics — PyTorch 2.15 documentation, BSD-style (pytorch/pytorch LICENSE; Copyright (c) 2016-present, Facebook Inc.; https://github.com/pytorch/pytorch/blob/main/LICENSE); docs only, not the tutorials repo; PyTorch name and logo not licensed; PyTorch docs, Automatic differentiation package - torch.autograd — PyTorch 2.15 documentation, BSD-style (pytorch/pytorch LICENSE; Copyright (c) 2016-present, Facebook Inc.; https://github.com/pytorch/pytorch/blob/main/LICENSE); docs only, not the tutorials repo; PyTorch name and logo not licensed.

Cite this

Permanent ID: iil:note:6h053en6

iinventedlight. 2026. "How PyTorch autograd works." iinventedlight Library, iil:note:6h053en6, version of 2026-11-04. https://iinventedlight.com/library/notes/pytorch-autograd/. License: CC-BY-4.0.

@misc{iil_note_6h053en6,
  author = {{iinventedlight}},
  title = {{How PyTorch autograd works}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/pytorch-autograd/},
  note = {Permanent ID iil:note:6h053en6. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/pytorch-autograd.md.