Concept notebookChecking saved investigationReading browser-local route memory before showing a continuation.

Reverse-Mode Automatic Differentiation

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

published · difficulty 3/5 · 14 min read

01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

PredictName the object in plain language, then predict what should change.Leave with one reusable mental picture before notation appears.

Suppose one scalar loss depends on millions of parameters. Do you need to run one derivative computation for each parameter to know how to change them all?

Reverse-mode automatic differentiation is the bookkeeping trick that makes the answer no.

The previous idea, computation graphs, makes dependencies visible. Reverse-mode AD adds an execution rule: during the forward pass, record the primitive operations and the intermediate values they will need later. During the reverse pass, start from the final question, "how much does the loss change if this output changes?", and walk backward through the recorded operations. Each local backward rule converts an output sensitivity into input sensitivities.

The key advantage is shape. If one scalar loss depends on many parameters, reverse mode can compute all parameter gradients in one backward sweep through the graph. Forward mode would ask, one input direction at a time, how the output changes.

The useful mental model is a tape plus a register file. The tape remembers what primitive operations ran. The registers store cotangents such as aˉ\bar aaˉ and xˉ\bar xxˉ. The model breaks if you imagine symbolic simplification: reverse mode does not expand the formula by hand; it accumulates local contributions on the graph that actually ran.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

InspectTrack the same object through the notation and check each symbol.Leave with the invariant the equations preserve.

Let a differentiable computation graph produce a scalar output LLL from intermediate variables v1,,vnv_1,\dots,v_nv1,,vn. Reverse mode stores, for each node, an adjoint or cotangent

vˉi=Lvi.\bar v_i = \frac{\partial L}{\partial v_i}.vˉi=viL.

Before the reverse sweep, initialize every non-output cotangent register to zero. Then seed the scalar output with

Lˉ=LL=1.\bar L = \frac{\partial L}{\partial L} = 1.Lˉ=LL=1.

For scalar nodes and a local operation vj=f(vi)v_j = f(v_i)vj=f(vi), the chain rule sends sensitivity backward. When the operation producing vjv_jvj is processed, vˉj\bar v_jvˉj already contains all downstream contributions:

vˉi+=vˉjvjvi.\bar v_i \mathrel{+}= \bar v_j \frac{\partial v_j}{\partial v_i}.vˉi+=vˉjvivj.

For an operation with multiple inputs, such as vj=f(u,w)v_j=f(u,w)vj=f(u,w), each input receives its own local derivative:

uˉ+=vˉjvju,wˉ+=vˉjvjw.\bar u \mathrel{+}= \bar v_j \frac{\partial v_j}{\partial u},\qquad \bar w \mathrel{+}= \bar v_j \frac{\partial v_j}{\partial w}.uˉ+=vˉjuvj,wˉ+=vˉjwvj.

The plus-equals matters. If a value is reused by several later nodes, all downstream paths contribute to its total sensitivity. Reverse mode is therefore not symbolic simplification; it is graph-local accumulation of vector-Jacobian products.

For vector nodes, choose column-vector cotangents. If viRnv_i\in\mathbb{R}^nviRn, vj=f(vi)Rmv_j=f(v_i)\in\mathbb{R}^mvj=f(vi)Rm, vˉiRn\bar v_i\in\mathbb R^nvˉiRn, vˉjRm\bar v_j\in\mathbb R^mvˉjRm, and

Jji=vjviRm×n,J_{ji}=\frac{\partial v_j}{\partial v_i}\in\mathbb{R}^{m\times n},Jji=vivjRm×n,

then the reverse update is

vˉi+=JjiTvˉj.\bar v_i \mathrel{+}= J_{ji}^{\mathsf T}\bar v_j.vˉi+=JjiTvˉj.

This is the direction contrast:

JVP: v˙j=Jjiv˙i,VJP: vˉi=JjiTvˉj.\text{JVP: }\dot v_j=J_{ji}\dot v_i,\qquad \text{VJP: }\bar v_i=J_{ji}^{\mathsf T}\bar v_j.JVP: v˙j=Jjiv˙i,VJP: vˉi=JjiTvˉj.

For a scalar loss L:RpRL:\mathbb R^p\to\mathbb RL:RpR, one forward evaluation records the needed values, and one reverse sweep gives the full gradient

θL=(Lθ1,,Lθp)T\nabla_\theta L = \left(\frac{\partial L}{\partial \theta_1},\dots,\frac{\partial L}{\partial \theta_p}\right)^{\mathsf T}θL=(θ1L,,θpL)T

assuming primitive backward rules are available. The cost is memory for saved forward values on a tape, or extra compute if some values are recomputed. An autodiff engine automates this bookkeeping by recording primitive operations during the forward pass and executing their local backward rules in reverse topological order.

These equations assume the recorded primitives are differentiable at the saved forward values. For nonsmooth primitives, an implementation must choose a convention, use a subgradient, or report that the derivative is undefined. If the program has control flow, reverse mode differentiates the branch that actually ran.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

TraceMatch variables to symbols before reading the implementation.Leave with a runnable witness for the math.
import math

x, y = 2.0, 3.0

# Forward graph:
# a = x * y
# b = sin(a)
# L = a + b
a = x * y
b = math.sin(a)
L = a + b

# Reverse-mode table: each bar_* stores dL/d(node).
# Start with empty cotangent registers, then seed the output.
bar_L = 0.0
bar_a = 0.0
bar_b = 0.0
bar_x = 0.0
bar_y = 0.0

bar_L = 1.0

# Read the tape backward.
# L = a + b sends one unit of sensitivity to both inputs.
bar_a += bar_L * 1.0
bar_b += bar_L * 1.0

# b = sin(a) contributes another path back into a.
bar_a += bar_b * math.cos(a)

# a = x * y sends sensitivity to both inputs.
bar_x += bar_a * y
bar_y += bar_a * x

print("L:", round(L, 4))
print("dL/dx:", round(bar_x, 4))
print("dL/dy:", round(bar_y, 4))

The code initializes every cotangent register and then uses += for local contributions. The reused node aaa receives two contributions: directly through L=a+bL=a+bL=a+b, and indirectly through b=sin(a)b=\sin(a)b=sin(a). With x=2x=2x=2 and y=3y=3y=3, the output is approximately L=5.7206L=5.7206L=5.7206, L/x=5.8805\partial L/\partial x=5.8805L/x=5.8805, and L/y=3.9203\partial L/\partial y=3.9203L/y=3.9203.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

ManipulateChange one control and predict the visible response before reveal.Leave with the observed invariant or a repaired model.

Live Concept Demo

Explore Reverse-Mode Automatic Differentiation

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo inquiry checkpoint

Manipulate one control and predict the visible change.

01Choose lensTrace a quantity
02ObserveDemo state pending
03GroundName the equation, invariant, or control that explains it.
04CarryNext: Backpropagation

Choose what to inspect in Reverse-Mode Automatic Differentiation. This shared fallback is an observation guide, not evidence of learning.

Loading interactive demo...

Use the sliders to change xxx and yyy, then compare the three phases.

Forward tape mode records the primitive operations and the saved values that local backward rules will need. Reverse sweep mode reads the same tape backward, starts from Lˉ=1\bar L=1Lˉ=1, and fills the cotangent registers. Cost shape mode highlights the main reason reverse mode matters for deep learning: when many inputs feed one scalar loss, one reverse sweep gives the whole gradient vector.

Try the second preset after making a prediction. It changes the product regime so the same tape can expose a different cotangent-accumulation pattern.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

4/4 sections ready

Concept: Reverse-Mode Automatic Differentiation

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

BeforeComputation GraphsNow4/4 sections readyTryManipulate one control and predict the visible change.NextBackpropagation
Object contextCalculus
ConceptLearner lens

Reverse-Mode Automatic Differentiation

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

Mode questionCan I say the mechanism back in one sentence before I reveal anything?

Start with the prediction checkpoint, then compare the reveal to the mental model.

Take this move

Study modes

Keep the object fixed; change the lens.

Route back through the notebook

Carry the same object through intuition, math, code, and demo.

4/4 sections ready
Carry inComputation Graphs

Bring the mental model from Computation Graphs; this page will reuse it instead of restarting from zero.

Work hereReverse-Mode Automatic Differentiation

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

Carry outBackpropagation

The next edge should feel earned: use the demo prediction here before following Backpropagation.

After The First Pass

Turn the concept into an inspected object.

The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.
ConceptReverse-Mode Automatic DifferentiationCalculus

Mechanism Storyboard

See the idea move before the page explains it

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

Demo notes open01 / Intuition
Editorial autodiff illustration of a forward tape and reverse cotangent sweep through computation nodes.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Reverse-Mode Automatic Differentiation should make visible.

Visual Inquiry

Make the image answer a mathematical question

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

4/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Reverse-Mode Automatic Differentiation easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

Object - ConceptReverse-Mode Automatic DifferentiationQuestion

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

concept:calculus/reverse-mode-autodiff
Boundary

sources: baydin-2018-ad-survey

Check

Open the closest source note before trusting the local explanation.

Evidence

1 selected-object source shown first; 1 reference total.

Next move

Audit the claim boundary, then ask from the same selected object.

selected object source · paper · 2018Automatic differentiation in machine learning: a surveyBaydin et al.
Located CF editorial boundary

Grounds reverse mode as the efficient way to compute gradients of scalar losses with many parameters.

Used here as

Baydin et al. describe reverse mode as running code forward to populate intermediate variables and record graph dependencies, then propagating adjoints backward. Their example shows incre...

Caveat

Checks reverse-mode bookkeeping for one executed differentiable computation: forward tape/saved values, then reverse cotangent sweep with primitive backward rules. Not checkpointing, reco...

Open source

Claim Review

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

Object - ConceptReverse-Mode Automatic DifferentiationQuestion

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

concept:calculus/reverse-mode-autodiff
Boundary

sources: baydin-2018-ad-survey

Check

Treat every claim as provisional until source support and a local witness agree.

Evidence

1 structured claim check on this concept.

Next move

Run the prediction or practice transfer before asking for a grounded review.

1 CF editorial source-scope review recorded

Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 1 reference and 3 local witnesses are available for inspection.

Reverse-mode AD records a forward evaluation trace of primitive operations and saved values, seeds a scalar output cotangent with 1, then sweeps backward applying local VJPs and += accumulation so one reverse pass computes the full gradient of one scalar loss with respect to many inputs.
Used here as

Baydin et al. describe reverse mode as running code forward to populate intermediate variables and record graph dependencies, then propagating adjoints backward. Their example shows incremental adjoint accum...

Local witness
Equation 1
vˉi=Lvi.\bar v_i = \frac{\partial L}{\partial v_i}.
Equation 2
Lˉ=LL=1.\bar L = \frac{\partial L}{\partial L} = 1.
Caveat

Checks reverse-mode bookkeeping for one executed differentiable computation: forward tape/saved values, then reverse cotangent sweep with primitive backward rules. Not checkpointing, recomputation, nonsmooth...

Review stateCF editorial source-scope reviewClaim metadata: source checkedPublisher-side editorial review only; not independent replication. Check caveats and exact source scope.

Checked Baydin et al. 3.2: reverse mode runs code forward to populate intermediates and record dependencies, then propagates adjoints backward. The example starts from output adjoint 1, accumulates reused-variable cotangents from downstream paths, and gets both input derivatives in one reverse pass. Baydin says for f:R^n->R one reverse application computes the full gradient. Local witnesses match tape values, bar L=1, += pullbacks, VJP/J^T notation, and scalar-loss shape.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice notebook

Use the idea, then test it somewhere new

Reverse-mode autodiff computes gradients by sending cotangents backward through a computation graph.

AttemptNo learning claim inferred
Object - ConceptReverse-Mode Automatic DifferentiationQuestion

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

concept:calculus/reverse-mode-autodiff
Boundary

sources: baydin-2018-ad-survey

Check

Use one state from Reverse-Mode Automatic Differentiation to explain what changes, why it changes, and which assumption the explanation needs.

Evidence

No learner move yet; no learning state is inferred.

Next move

Write first, use only the help you need, then try a new case without it.

Explain

Use one state from Reverse-Mode Automatic Differentiation to explain what changes, why it changes, and which assumption the explanation needs.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded object roomClose
Selected object routeAsk from this object; carry one invariant back.sources: baydin-2018-ad-survey
  1. ObjectConceptReverse-Mode Automatic Differentiation
  2. PredictBefore revealReverse-Mode Automatic Differentiation prediction
  3. WitnessCompare codeReverse-Mode Automatic Differentiation code witness 1
  4. RoomAsk groundedChecking local snapshot
ConceptReverse-Mode Automatic DifferentiationCalculus
Code witness comparisonReverse-Mode Automatic Differentiation code witness 1x, y = 2.0, 3.0Prediction before revealReverse-Mode Automatic Differentiation predictionManipulate one control and predict the visible change.
Grounded room questionWhat is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?Checking local snapshot

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptCalculus

Reverse-Mode Automatic Differentiation

Anchored question

What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math?

Source boundaryInspect source ids: baydin-2018-ad-surveyStable content-object key attached
Role lenses for this object

These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.

Learner evidence requestAsk what would make "Reverse-Mode Automatic Differentiation" feel predictable rather than familiar.
Assumption

Source ids baydin-2018-ad-survey must support the exact object, not just the surrounding topic.

Source-checking summary

Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.

Proposed experiment

Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.

Next action

The learner can state the mechanism in their own words

Evidence4 checks
PredictionChecking carried observation
ActionReady for one action
AILearner handoff ready
Open source object
01PredictionChecking browser-local route memory
02EvidenceChecking for a carried observation
03BoundaryInspect source ids: baydin-2018-ad-survey
04Next moveSave one next action
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:calculus/reverse-mode-autodiff.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: baydin-2018-ad-survey
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Object-attached AI handoff

I am working in Continuous Function's research reading room. Object: concept - Reverse-Mode Automatic Differentiation Object key: concept:calculus/reverse-mode-autodiff Context: Calculus Anchor id: concept/concept-notebook/calculus/reverse-mode-autodiff Open question: What is the smallest example that makes Reverse-Mode Automatic Differentiation click without losing the math? Evidence to inspect: - Source ids to inspect: baydin-2018-ad-survey - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids baydin-2018-ad-survey must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Reverse-Mode Automatic Differentiation" feel predictable rather than familiar." | assumption: Source ids baydin-2018-ad-survey must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: baydin-2018-ad-survey" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Reverse-Mode Automatic Differentiation" feel predictable rather than familiar. - Assumption to keep visible: Source ids baydin-2018-ad-survey must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words

concept/concept-notebook/calculus/reverse-mode-autodiff concept:calculus/reverse-mode-autodiff