Deep Learning / Editorial solution guide
Diagnose Checkpointed Gradient Disagreement
Trace state, randomness, and recomputation when activation checkpointing changes a training update.
Read-only knowledge base ยท No public comments
Recognize the symptoms
A controlled step produces different gradients after activation checkpointing is enabled.
Training loss or model state diverges from an otherwise comparable run.
Understand the likely causes
- The checkpointed function may depend on mutable state, side effects, random operations, or a changed execution context.
- Input, loss reduction, optimizer state, or data order may differ between the compared runs.
Create a controlled comparison
In a bounded lab, preserve the original model and configuration. Use the same small input, model parameters and buffers, loss, precision, and evaluation conditions for ordinary and checkpointed runs. Reset relevant random state and avoid optimizer updates until forward outputs and gradients have been compared.
Record library and device versions, checkpoint options, and an explicit numerical tolerance. A mismatch in a complete training run has many possible causes; isolating one block reduces the number of moving parts without assuming that every environment is bitwise deterministic.
Trace the first divergence
Compare the block input and output first, then parameter and input gradients. Inspect operations inside the block for mutation, counters, external calls, random sampling, or stateful layers whose state changes when the block is recomputed. Check the documented behavior of the installed checkpoint implementation and the selected random-state handling.
If the forward values already differ, inspect data, mode, precision, and state before blaming backward. If forward values agree but gradients do not, narrow the block and compare individual operations. Preserve the failing fixture and change one confirmed factor at a time.
Correct, verify, and measure
Remove or isolate an unintended side effect, restore the intended state handling, or move the checkpoint boundary as appropriate. Compare gradients again on the original fixture and on a second representative shape. Then compare one optimizer update and a small held-out metric against the baseline using the agreed tolerance.
Measure peak memory and step time under the same conditions before retaining the optimization. If the evidence remains inconclusive, use the ordinary path while investigating. Release through the normal review process and keep the previous configuration available for rollback.
Verify the fix
Forward outputs, relevant gradients, and one update agree with the baseline within the documented tolerance for representative controlled fixtures.
The chosen boundary meets the measured memory and runtime requirements, and stateful or random operations behave as documented.
Keep it from recurring
- Keep a small baseline-versus-checkpoint gradient comparison with realistic state and input shapes.
- Document checkpoint boundaries, random-state handling, library versions, and performance measurements whenever the training configuration changes.