Repository navigation
Conversation
hallerite
marked this pull request as ready for review
October 11, 2026 20:18
hallerite
force-pushed
the
fix/checkpoint-compile-replay
branch
from
October 12, 2026 09:37
5784fa8 to
c520a61
Compare
hallerite
changed the base branch from
main
to
fix/ac-recompute-dynamo-settings
October 12, 2026 09:37
garrett361
added a commit
that referenced
this pull request
Oct 12, 2026
…ith an fp32 router (#4037) Reverts #3925. With an fp32 router and activation checkpointing, #3925 changed checkpointed MoE blocks from `compile(AC(block))` to `AC(compile(block))`, which makes the checkpoint recompute re-enter Dynamo on the autograd thread. Since then, MoE RL runs with context parallelism, activation checkpointing and compile crash in an early backward with `aten.empty_like.default` or `aten.empty.memory_format encountered during backward but not found in storage`. That happens with both ring and ulysses CP, which shows that reverting #3925 removes the crash on the same batches). The runs in #3925 (no CP) never hit this, and the root cause is not yet understood. This PR restores the previous layout and the `AC -> Compile -> FSDP` order until it is. The cost is #3925's speedup: MoE blocks with an fp32 router and AC run eager again (GLM-4.5-Air about 5.2 to 6.2 s/step, Qwen3-30B-A3B 4.5 to 6.0 s/step in #3925's benchmarks). A follow-up will root-cause the crash and decide whether to re-land #3925 together with #3951. This conflicts with #4029, which edits the unwrap block removed here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Depends on #3951 and is stacked on
fix/ac-recompute-dynamo-settings. The diff contains only the remaining autotuning and checkpoint-boundary protections; #3951 supplies consistent forward/recompute compiler settings and dynamic ring-attention integers.Selective activation checkpointing can still fail when runtime autotuning executes under replay dispatch modes, or when a compiled forward is replayed eagerly. This change addresses those two cases:
apply_compile(RL and SFT). It filters dispatch modes opting out viaignore_compile_internals()aroundCachingAutotuner.bench,autotune_to_one_config, andcoordinate_descent_tuning, restoring the stack afterward. Installation is idempotent and rejects other Torch versions because the implementation uses private runtime APIs.CheckpointWrapperinside the compiled region rather than unwrapping it for nested FSDP blocks. This avoids an eager selective-checkpoint context spanning a compiled-to-eager replay transition while preserving AC → FSDP → compile setup order.Performance limitation: nested FSDP graph breaks can cause the checkpointed block to run eagerly. This is a correctness safeguard, not a claim to preserve all compilation throughput. Router precision-group changes and parameter-alias activation-offloading work are outside this PR.
Validation on Torch 2.13.0+cu130:
fix(trainer): recompile AC-recomputed compiled blocks with the forward's dynamo settings #3951 alone completes 12 varying-length reduced-GLM steps (CP2 Ulysses, EP2, FP32 router/master/reductions, full AC and activation offloading), including a cold-cache repeat. Its parent fails on the third backward with
aten.as_strided ... not found in storage.A synthetic forced compiled-forward/eager-replay transition still fails with fix(trainer): recompile AC-recomputed compiled blocks with the forward's dynamo settings #3951 contexts alone (
aten.empty_like ... not found in storage). Putting the checkpoint inside compilation passes 12 shapes with output/input-gradient checks.A controlled cold CUDA kernel launch during recomputation, using fix(trainer): recompile AC-recomputed compiled blocks with the forward's dynamo settings #3951 contexts, fails without the autotuning backport (
aten.empty.memory_format ... not found in storage). With the backport it executes real autotuning (2 benchmark calls) and passes the analytical gradient check. This deliberately induced path establishes coverage, not that ordinary fix(trainer): recompile AC-recomputed compiled blocks with the forward's dynamo settings #3951 training necessarily hits it.Combined branch: 12 reduced-GLM optimizer steps and state-dict roundtrip pass on both GPUs. The compiler records no compiled blocks in this nested-FSDP case: it runs eagerly, confirming the performance limitation above.
Combined branch: forced-fallback CUDA test passes 12 shapes with output/input-gradient checks; dispatch filtering, nesting, exception restoration and idempotency checks pass; existing checkpoint tests: 4 passed.
Ruff check, Ruff format check and
git diff --checkpass. Signed head:c520a6156420512ab092dfe9ac5e9d6f177cae33.Full-model validation of #3951 alone is queued as Slurm job 3809 (16 H200s, GLM-4.5-Air, 12 saved-batch replay steps); it is not counted as passed. No SFT end-to-end validation or full-model numerical-equivalence claim. No hosted-run changes.
Note
High Risk
Touches compiled training, SAC replay, and private Torch 2.13 Inductor/Dynamo APIs; misalignment here breaks backward or only surfaces on specific Torch versions.
Overview
Fixes backward failures when training with
torch.compile+ selective activation checkpointing (SAC) by keeping forward and recomputation aligned on which ATen ops run and which Dynamo settings apply.Adds a Torch 2.13-only backport (
compile_compat.py) that wraps InductorCachingAutotunerbench/autotune paths so dispatch modes that opt out of compiler internals are temporarily removed. That stops Triton autotuning from allocating or benchmarking under SAC modes during checkpoint replay (theaten.empty.memory_format/ missing-op mismatch class of bugs). The patch is applied once from sharedapply_compile.Activation checkpointing now routes SAC through
_checkpoint_contexts: on the autograd recompute thread it reapplies the forward pass’srecompile_limit,capture_scalar_outputs, anddynamic_sourcesso a compiled block doesn’t hit Dynamo’s recompile cap and fall back to eager during replay.Compile setup no longer unwraps
CheckpointWrapperaround nested FSDP blocks—layers are compiled in place with the wrapper inside the compiled region.DYNAMIC_INT_ARGSis extended for ring context-parallel (max_seqlen_q,max_seqlen_k,local_k_slice) so varying sequence metadata doesn’t force per-shape recompiles.Tradeoff: restoring correctness may mean some checkpointed blocks run more eagerly when FSDP graph breaks remain; this is not a general fix for every compile/eager boundary.
Reviewed by Cursor Bugbot for commit c520a61. Bugbot is set up for automated code reviews on this repo. Configure here.