Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN033 · Algorithm

Activation checkpointing / gradient rematerialization

Trades additional forward computation for reduced activation storage during backpropagation.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Trades additional forward computation for reduced activation storage during backpropagation.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

Only selected intermediate activations are stored; missing segments are recomputed when their gradients are needed.

Assumptions

Recomputed functions must preserve required behavior, including random-state and stateful-layer conventions. Non-reentrant versus reentrant implementations differ.

Formula / computational definition

store h0,hk,h2k,…;recompute intermediate hl during backward.\text{store }h_0,h_k,h_{2k},\ldots;\quad\text{recompute intermediate }h_l\text{ during backward}.

Parameters and notation

No new learned parameters. Hyperparameters: checkpoint boundaries, segment length, RNG preservation, offloading, implementation mode.

Fitting, fine-tuning, and adaptation

Enable on expensive blocks, verify gradients against a small non-checkpointed run, and monitor actual memory/time. It combines with PEFT but reduces a different source of memory.

How to use and calibrate

Example: fine-tune a long-context transformer whose activation storage dominates memory. Record throughput penalties and any changed batch/context capacity.

Example application

fine-tune a long-context transformer whose activation storage dominates memory. Record throughput penalties and any changed batch/context capacity.

Interpretation / pitfalls

Watch out

Checkpointing does not remove parameter, optimizer, or KV-cache storage. Recomputing stateful operations incorrectly can update running statistics twice. The example illustrates deterministic rematerialization only.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
x=np.array([1.,2.]); W=np.array([[.2,.3],[.4,.5]])
f=lambda z: np.tanh(z@W); checkpoint=x.copy(); recomputed=f(checkpoint)
print(np.allclose(recomputed,f(x)))
R

Component demo, not a trained model — numerical mechanism demonstration.

x <- c(1,2); W <- rbind(c(.2,.3),c(.4,.5)); f <- function(z) tanh(as.vector(z%*%W))
checkpoint <- x; print(isTRUE(all.equal(f(checkpoint),f(x))))

Sources

From the CodeSplash reference, entry TRN033.