DeepLLM Quiz
Deep Learning

Reverse-mode automatic differentiation: adjoints, memory and cost

10 questions on adjoint variables, one backward pass for many inputs, memory cost, the cost bound and hybrid Hessian-vector products. With explanations.

  • 10 questions
  • Stopwatch
  • Instant feedback

Shown publicly with your score. Don’t use your full real name.

Sample questions

Play now ↑

Answers stay hidden. Start the quiz to play them.

  1. Sample 1

    A function has 5 million inputs and one output. How many backward sweeps are needed to get its derivative with respect to every input?

    • One
    • 5 million
    • Five

How it works

  • One question per screen. An answer is final once sent.
  • You see right away whether you were right, with a short explanation.
  • The stopwatch runs: on equal scores, the faster player ranks first.
  • Only your best attempt counts, so replaying is never risky.

About this quiz

When a modern framework trains a network, it quietly does something that sounds paradoxical. It first runs the whole computation forwards, recording what happened, and then it walks backwards through the record, working out how much each earlier step contributed to the final error. This backward walk produces the derivative of the error with respect to every one of millions of parameters in a single sweep. The technique is reverse-mode automatic differentiation, and it is the engine under almost every deep learning library.

The quiz explains why this direction is the right one for training, and what it costs. You will meet adjoint variables, the bookkeeping numbers that say how much the final output depends on each intermediate value, and you will see where they start and how each is built from the ones after it. You will compare the effort needed when the function has many inputs and one output with the effort when it has several outputs. You will think about memory, and why training a model can need so much more of it than using the model. And you will look at the surprising guarantee that the whole backward sweep costs only a small multiple of one forward evaluation.

The questions are built around concrete numbers and situations. A function with five million inputs and one output: how many backward sweeps? A model with three outputs: what changes? A computation that takes ten seconds forwards: what is the most the gradient may take? A team that can run its model but cannot train it on the same machine: what is the likely cause? The aim is to make the efficiency of reverse mode feel obvious rather than magical.

Some confusions come up repeatedly. People assume that reverse mode gives every output's derivatives in a single sweep, but each output needs its own sweep. They forget that it needs the intermediate values from the forward pass, and so has to store them. And they sometimes think of backpropagation and reverse-mode differentiation as unrelated, when the first is the special case of the second that is applied to neural networks. The practical consequences show up every day. Techniques with names such as gradient checkpointing, activation recomputation and reversible layers are all attempts to ease the memory demand described here, trading a little extra computation for a smaller store of intermediate values. Understanding why the store exists in the first place is the key to understanding why those techniques are useful and when they are worth turning on. It also explains why the largest models are trained across many machines, not merely run on one.

The quiz suits learners who want to know why training takes the memory it does, and practitioners who want to understand the machinery behind the gradient call in their framework. It needs only counting and multiplication. There are 10 questions, each with an explanation, and it takes about four minutes.

Questions and answers

›How long does the quiz take?

About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation follows every answer, so the quiz also works as a quick summary of the method.

›Should I take the forward-mode quiz first?

It helps, since the two modes are best understood side by side. The questions here recall what is needed, so it is also fine to start with this one. Either way, the contrast between the two is the central lesson.

›What is an adjoint variable?

An adjoint is a number attached to an intermediate value that records how strongly the final output depends on it, that is, the derivative of the output with respect to that value. Adjoints are computed in reverse order, starting from the output itself and moving back through the computation. For a network's error, the adjoints of the weights are exactly the gradients needed for training.

›How is reverse mode related to backpropagation?

Backpropagation is the special case of reverse-mode differentiation applied to the error of a neural network. Reverse mode generalises it to any computation that can be written as a sequence of elementary steps. The same pattern of storing values on the way forward and sweeping backwards applies, which is why a framework can offer gradients for models that nobody anticipated.

›Why is reverse mode preferred for training?

Training has a single quantity to differentiate, the error, and an enormous number of variables to differentiate with respect to. One backward sweep delivers all the derivatives at once, whereas the forward mode would need one pass per variable. When outputs are few and inputs many, reverse mode is overwhelmingly cheaper.

›Why does reverse mode use so much memory?

The backward sweep needs the values calculated on the way forward, and they must be kept until they are used. A deep network with a large batch can therefore require storing a great many numbers. This storage is a major reason why training needs more memory than prediction, and why some systems trade extra computation for less storage.

›How expensive is a backward sweep?

It is guaranteed to cost no more than a modest multiple of the cost of a single evaluation of the function, and in practice the overhead is usually a factor of two or three. That is remarkable, considering that it produces derivatives with respect to every input at once.

›Can the two modes be combined?

Yes. A hybrid approach applies one mode to the code produced by the other. A well-known example gives the product of the table of second derivatives with a vector at a cost proportional to the number of parameters, without ever forming the table. Such combinations extend the reach of automatic differentiation beyond first derivatives.

More quizzes