Repository navigation
[transformers_modeling_backend] Keep the Titan MoE output for HF's bare consumers - #5374
Merged
Merged
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
approved these changes
Oct 13, 2026
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.
Stack from ghstack (oldest at bottom):
The default remat policy saves the Titan MoE's last region:
combinewithEP,
shared_addwith shared experts, ortp_output_reductionwith TP and nosequence 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_residualadd, whichreplay 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-feedforwardnorm. transformers_modeling_backend_moe_fsdp+tp+ep+cp has failed in backward
since #4893:
_HFBatchedMoE.forwardis the boundary where the output leaves Titan code, soit declares the output with
remat.recompute_needs_tensor, as REMAT.mdprescribes 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_addoutput, so it reproduces the failure on one GPUwithout 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