Skip to content

[transformers_modeling_backend] Keep the Titan MoE output for HF's bare consumers - #5374

Merged
anijain2305 merged 2 commits into
mainfrom
gh/anijain2305/71/head
Oct 13, 2026
Merged

anijain2305 merged 2 commits into
mainfrom
gh/anijain2305/71/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The default remat policy saves the Titan MoE's last region: combine with
EP, shared_add with shared experts, or tp_output_reduction with TP and no
sequence parallelism. A saved region is skipped during checkpoint replay and
its output is a placeholder unless a consumer declares that it needs the data.
Titan blocks consume the MoE output with the retained ffn_residual add, which
replay also skips, but HF decoder layers read it with bare ops that replay
re-runs: Qwen3 MoE's residual + hidden_states, and Gemma4's post-feedforward
norm. transformers_modeling_backend_moe_fsdp+tp+ep+cp has failed in backward
since #4893:

RuntimeError: layers.3::mlp.routed_experts.token_dispatcher.combine.out
is a placeholder for the output of remat.region
'layers.3::mlp.routed_experts.token_dispatcher.combine' (recompute=False)

_HFBatchedMoE.forward is the boundary where the output leaves Titan code, so
it declares the output with remat.recompute_needs_tensor, as REMAT.md
prescribes for consumers outside the owning module. The output is now kept
from the forward to the backward, which a bare HF consumer requires. The
backend wraps HF linears and attention without Titan regions, so the MoE output
is the only saved Titan output that HF code reads.

Test: a tiny HF DeepSeek-V3 model through the real probe, swap and module
conversion path, under the default policy. Its shared experts make the MoE
output the saved shared_add output, so it reproduces the failure on one GPU
without EP; with the fix, loss and gradients match no checkpointing bitwise.
transformers_modeling_backend_moe_fsdp+tp+ep+cp (8 GPUs) now passes, and over
5 seeded deterministic steps its loss and grad_norm match a run without
activation checkpointing bitwise.

Fixes #5363

[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 13, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 13, 2026
@anijain2305
anijain2305 changed the base branch from gh/anijain2305/71/base to main October 13, 2026 23:39
@anijain2305
anijain2305 merged commit ee3b997 into main Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] HF Qwen3 MoE residual consumes a saved-combine placeholder during SelectiveAC (#4893)

2 participants