Skip to content

A Tensor's Autograd Life

Lifecycle

A tensor's autograd states, from recorded to walked to released, plus the version-mismatch recovery loop.

8 states · 4 guided chapters

Key facts

What gets recorded

  • grad_fn (XxxBackward), next_edges and the input versions
  • A leaf gets AccumulateGrad as its grad_fn on first use

Ways back

  • VersionMismatch clears once forward re-runs and builds a new graph
  • Only a graph kept with retain_graph=True can be walked again

Guided chapters

  1. 01

    Record to .grad

    A leaf used in an op builds a graph; backward fills the grads, then the graph is released.

  2. 02

    Keeping the graph

    Only a graph kept with retain_graph=True can run backward again.

  3. 03

    Version mismatch

    An in-place change to a saved tensor stops the walk; re-running forward recovers.

  4. 04

    Nothing recorded

    With GradMode off (no_grad, inference_mode) the kernels skip node creation entirely.