What is Gradient checkpointing?

Storing only some intermediate forward results and recomputing the rest during backpropagation, trading extra computation for less memory.

Field: AI Hardware & Software Stack

Japanese name: 勾配チェックポイント

Why backpropagation uses so much memory

When backpropagation computes the gradient of each layer, it uses the intermediate result that layer produced in the forward pass. These intermediate results are called activations. Ordinary training stores the activations of all layers until backpropagation finishes. Their amount grows in proportion to the number of layers and the batch size. In inference an activation can be discarded once it has been used, but in training it cannot. Gradient checkpointing is a way to cut down this storage.

Storing fewer results and recomputing

The model is divided into several segments, and only the results at the segment boundaries are stored. The stored points are called checkpoints. When backpropagation reaches a segment, the forward pass is rerun from the checkpoint just before it. The activations inside the segment are rebuilt, and discarded once the gradients have been computed. Suppose 16 layers are divided into 4 segments of 4 layers each. What is held is the 4 boundaries plus roughly 4 layers' worth for the segment being computed. That is about half of what storing all 16 layers would take.

Extra computation and cautions

Each layer is recomputed at most once, so the added computation is about one forward pass. Memory falls, but each training step becomes slower by that amount. It is used when memory is short and a large model or a large batch would not otherwise fit. The gradients obtained are the same as when everything is stored. This assumes, however, that the recomputation gives the same result as the first forward pass. Operations that use random numbers have to be handled so that the same values can be reproduced.

Try it: questions about Gradient checkpointing

Which describes gradient checkpointing (activation recomputation) used in training?

  1. AStore only some intermediate forward results and recompute the rest when needed during backpropagation, trading extra computation for less memory
  2. BSaving model weights to disk partway through training
  3. CTraining without computing gradients
Show answer and explanation

Answer: A. Store only some intermediate forward results and recompute the rest when needed during backpropagation, trading extra computation for less memory

Backpropagation needs each layer's intermediate forward results, but storing them all makes memory grow with layer count and batch size. Gradient checkpointing stores results only every few layers, and when backpropagation reaches a segment it reruns the forward pass from the saved point to regenerate the needed values. At the cost of roughly one extra forward pass, activation memory is greatly reduced.

FAQ

Is it the same as a 'checkpoint' that saves the model partway through training?

No, that is a different thing. That kind of checkpoint means saving the weights and other state to a file so that training can be resumed. Gradient checkpointing is a way to save activation memory within a single backward pass.

Is it used in inference too?

No. Inference is only a forward pass, and there is no need to store activations for backpropagation. Gradient checkpointing is a method for reducing the memory of training.

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary