Repository navigation
Conversation
…pointing With Hugging Face per-layer reentrant gradient checkpointing, backward recomputes every decoder layer, including its attention forward. install_attention_stash(model, num_layers) keeps the cuDNN SDPA output and log-sum-exp of the last num_layers decoder layers from the first forward, and the recompute builds the attention node from the kept output instead of running the attention forward again. Projections, norms and RoPE are still recomputed; the replayed backward is the call PyTorch's derivative for _scaled_dot_product_cudnn_attention makes. Kept outputs are keyed by the decoder layer's input (data pointer, version and shape); the reentrant recompute runs on a detached alias of that tensor, so each backward can only use its own forward's output, and outputs of forwards dropped without a backward are released with their input. Unsupported use fails instead of falling back: non-SDPA models, training outside a reentrant checkpoint, attention masks or dropout, and SDPA backends other than cuDNN. Like the fused RoPE installer, it belongs to the attention layers and is installed rather than configured under expert_parallel. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: yh0903 <helloyu0903@gmail.com>
Release pending inputs even after failed decoder forwards, preflight every layer before duplicate-install rejection, and bypass stashing in evaluation. Explicitly reject higher-order gradients without changing the cuDNN forward/backward arguments. Run CUDA tests in fresh workers, restore the SDPA wrapper within the engine worker, and move the consolidated regression file into the current v1 CI scope. Preserve the documented first-order, single-backward and cuDNN-only contract. Signed-off-by: yh0903 <helloyu0903@gmail.com>
yh0903
force-pushed
the
yh0903/autoep-attention-output-stash
branch
from
November 17, 2026 04:27
f0de17d to
8cac4da
Compare
yh0903
marked this pull request as ready for review
November 17, 2026 04:27
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8cac4da02e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Reject noncanonical SDPA registry entries before patching any layer, while allowing reuse of the installer's own canonical wrapper. Detach consumed inputs' finalizers so an older same-storage alias cannot delete a later forward's saved output. Move CPU stand-ins to the documented ATen and backend-selector collaborator boundaries. Add no-mutation, wrapper-reuse and CPU/cuDNN alias-lifecycle regressions; preserve the cuDNN arithmetic and opt-in support limits. Signed-off-by: yh0903 <helloyu0903@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With Hugging Face per-layer reentrant gradient checkpointing, backward recomputes every decoder layer, including its attention forward. On Qwen3-30B-A3B on 8 H100s (sequence 4096, micro-batch 4), that recomputed attention forward was about 0.79 s of an 18.7 s step.
This adds an opt-in installer,
install_attention_stash(model, num_layers). For the lastnum_layersdecoder layers, the first forward keeps its attention output, and the recompute uses it instead of running the attention forward again. It is a memory-for-compute trade: one attention output plus its log-sum-exp per stashed layer, held from the layer's forward to its recompute.Change
deepspeed/runtime/activation_checkpointing/attention_stash.py. Like the fused RoPE installer (Add an opt-in fused Triton RoPE for Hugging Face split-half models #8663), it belongs to the attention layers, so it is installed rather than configured underexpert_parallel, and it works with or without AutoEP."sdpa"entry inALL_ATTENTION_FUNCTIONS. Attention modules without a stash call the original function.aten._scaled_dot_product_cudnn_attention, the opF.scaled_dot_product_attentiondispatches to, with the log-sum-exp;aten._scaled_dot_product_cudnn_attention_backward, called with exactly the arguments of PyTorch's derivative for the forward op.weakref.finalize.attn_implementation="sdpa";num_layers, or missing PyTorch entry points.autoep.rstafter the fused RoPE one.Finalization
create_graph=True; saved outputs are consumed once, so repeated backward through a retained graph is outside the contract.DistributedTestworkers, and the engine test restores its process-wide SDPA patch inside the worker.pytest --forked, on a 4x NVIDIA H100 80GB HBM3 allocation (CUDA cases use one worker), driver 580.159.04, torch 2.10.0.2/CUDA 13.0, Triton 3.6.0, transformers 5.12.0 and cuDNN 9.17. The first run passed all 15 CPU contracts and both direct cuDNN cases; the engine case was blocked by transport initialization. Only the engine case was retried with the accepted default NCCL transport setup and passed on unchanged source. This includes the actual AutoEP training-step comparison.tests/unit/v1/activation_checkpointing/test_attention_stash.pyso the current diff selector includes it, rather than silently selecting no tests from the old out-of-scope location. Executable test ASTs are unchanged by this relocation; the relocated CPU file also passes 15 cases with 3 CUDA skips. The CI selector includes exactly this file; collection checks are separate from the actual Linux/H100 runs.Numerics
torch.equal; this does not prove signed-zero bit-pattern equality.torch.use_deterministic_algorithms(True), and six autograd runs on the same inputs gave six different dQ results.torch.equal, and both have identical error against an FP32 reference in the recorded experiment.Tests
tests/unit/v1/activation_checkpointing/test_attention_stash.py:torch.equalfor output, dK and dV; dQ as accurate as autograd's against FP32;Current device command, from
tests/on the documented H100/cuDNN setup:End to end
Qwen3-30B-A3B on 8 H100s: expert parallel 8 with DeepEP, sequence 4096, micro-batch 4, 16 accumulation steps, per-layer reentrant checkpointing. Measured with an equivalent benchmark prototype on our benchmark stack, one allocation, order 0 / 30 / 48 stashed layers, then reverse:
AI assistance was used for final review, integration and regression tests. The submitting human authorized this existing PR update; maintainer review is still required. This is not a new duplicate feature, and the historical performance evidence is not a retiming of the current branch.
AI review follow-up
torch.ops.atenand the Torch SDPA selector, with the real ATen signatures and supported argument contract. Production_cudnn_forward,_cudnn_backwardand_sdp_backendhelpers all remain in the tested path; the fixture no longer replaces stash-module internals.pytest --forkedfile selector above. The runtime and every retained test body are unchanged from the first follow-up device run; the complete consolidated file was rerun to verify a clean process exit, not retimed.An additional two-rank installation-only probe reached the expected Ulysses-wrapper rejection, but its pytest process did not exit before the timeout. That probe is not counted as passing and is not included in the consolidated CI file: rejecting any noncanonical registry function is an unconditional installer contract, covered by the CPU no-mutation regression without introducing sequence-group setup/teardown dependencies. No stash/Ulysses composition or sequence-parallel numerical validation is claimed.
The cuDNN arithmetic/call arguments and existing E2E memory-for-compute evidence are unchanged; no fresh performance or convergence experiment was run.