fix(replay): align BSHD data with Megatron token order - #2798
Open
Shikhargupta wants to merge 1 commit into
Open
fix(replay): align BSHD data with Megatron token order#2798Shikhargupta wants to merge 1 commit into
Shikhargupta wants to merge 1 commit into
Conversation
Shikhargupta
requested review from
Shi-Dong,
Zhichenzzz,
fzyzcjy,
maocheng23 and
yueming-yuan
as code owners
August 28, 2026 19:24
Rollout replay arrives batch-major, while Megatron flattens BSHD hidden states in sequence-major order. Transpose before flattening and sequence-parallel slicing so routes stay attached to their tokens. Signed-off-by: Shikhar <guptashikhar20@gmail.com>
Shikhargupta
force-pushed
the
fix/bshd-replay-order
branch
from
August 28, 2026 19:25
6b4fad1 to
eddb75f
Compare
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.
Summary
[B, S, ...]order to Megatron[S, B, ...]order before flatteningWhy this is needed
For
B=2, S=4, a replay tensor containing:was flattened directly as
[0, 1, 2, 3, 4, 5, 6, 7]. Megatron's BSHD hidden states are flattened from[S, B, ...], so the corresponding route order is[0, 4, 1, 5, 2, 6, 3, 7]. With multiple samples, the old order can therefore replay a token's routing decision onto a different token.For sequence parallelism with TP=2, slicing the already-flattened tensor also selected all of sample 0 on rank 0. The correct rank-local layouts are
[0, 4, 1, 5]and[2, 6, 3, 7].Validation
pytest tests/fast/backends/training_utils/test_replay_data.py -q— 6 passedgit diff --check— passedRelated work
#2698 changes per-sample BSHD padding in the same path. This PR is independent: it fixes token ordering after padding/CP slicing and adds focused ordering tests.