Skip to content

fix(trainer): preserve checkpoint replay across autotuning and compile fallback - #4029

Closed
hallerite wants to merge 1 commit into
fix/ac-recompute-dynamo-settingsfrom
fix/checkpoint-compile-replay
Closed

hallerite wants to merge 1 commit into
fix/ac-recompute-dynamo-settingsfrom
fix/checkpoint-compile-replay

Conversation

@hallerite

@hallerite hallerite commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

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:

  • Install a PyTorch 2.13.0-only backport in shared apply_compile (RL and SFT). It filters dispatch modes opting out via ignore_compile_internals() around CachingAutotuner.bench, autotune_to_one_config, and coordinate_descent_tuning, restoring the stack afterward. Installation is idempotent and rejects other Torch versions because the implementation uses private runtime APIs.
  • Keep CheckpointWrapper inside 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:

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 Inductor CachingAutotuner bench/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 (the aten.empty.memory_format / missing-op mismatch class of bugs). The patch is applied once from shared apply_compile.

Activation checkpointing now routes SAC through _checkpoint_contexts: on the autograd recompute thread it reapplies the forward pass’s recompile_limit, capture_scalar_outputs, and dynamic_sources so a compiled block doesn’t hit Dynamo’s recompile cap and fall back to eager during replay.

Compile setup no longer unwraps CheckpointWrapper around nested FSDP blocks—layers are compiled in place with the wrapper inside the compiled region. DYNAMIC_INT_ARGS is 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.

@hallerite
hallerite marked this pull request as ready for review October 11, 2026 20:18
@hallerite
hallerite force-pushed the fix/checkpoint-compile-replay branch from 5784fa8 to c520a61 Compare October 12, 2026 09:37
@hallerite
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>
@samsja samsja closed this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants