Model and Inference EngineeringTraining execution and recoveryStaff
What random state must activation checkpointing preserve to reproduce the original dropout gradient?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A trainer saves memory by discarding selected intermediate activations and recomputing them during backward. The forward loss matches a seeded reference, but gradients differ in a region containing dropout. Explain the required relationship between forward and recomputation, diagnose random-state and device boundaries, and compare valid repairs with the memory and runtime costs.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Activation checkpointing is a memory technique inside one training step. It differs from saving a durable training checkpoint to storage. The runtime discards some intermediate values and reruns part of the forward computation when backward needs them. Dropout randomly suppresses activations, so recomputation must recreate the relevant mask if backward is meant to differentiate the original sampled function. Replaying just the input tensors while drawing a new mask is not the same computation.
If dropout draws a new mask during recomputation, backward uses a different function than the one that produced the visible loss. A seed set once at the start of the step is not enough if the random-number generator (RNG) stream has advanced before recomputation. PyTorch's checkpointing documentation describes preserving RNG state by default to make checkpointed dropout behave like the non-checkpointed path, with caveats around devices and moving tensors.
I would compare one microbatch in a small deterministic setup, capturing dropout masks or the RNG state at the checkpoint boundary, forward activations, gradients and the parameters after a single update. Disable unrelated sources of nondeterminism for this diagnostic. Then reproduce it with the real distributed configuration. A rank-local RNG seed, model-parallel dropout stream and device transfer can complicate state restoration. The exact framework setting and checkpoint implementation matter, so inspect them rather than assuming all checkpointing libraries preserve RNG the same way.
The fix may be to preserve the relevant RNG state, use a stateless counter-based mask keyed to the same layer, token and step, or move stochastic operations outside the recomputed region where that is valid. If the team intentionally accepts different masks to save overhead, that is a changed training computation, not a free memory optimization. Compare convergence and quality under controlled runs. Measure the throughput cost of saving RNG state as well as the memory saving from checkpointing.
What if dropout is disabled? Then this particular explanation goes away. You still need to check custom ops with side effects, changing global state, non-deterministic kernels and tensor movement. Every training rank has a different shard. Why are its random augmentations identical? covers identical augmentations across ranks because seeds were reused. This question is the opposite temporal problem: the same sample's backward replay gets a different stochastic forward from the one whose loss it is differentiating.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux