fix(te): pass pad_between_seqs explicitly for tail-padded THD under CP - #25
Merged
JackRao123 merged 1 commit intoAug 8, 2026
Merged
Conversation
JackRao123
force-pushed
the
jackrao/lps-1063-thd-cp-pad-between-seqs
branch
from
August 8, 2026 22:40
e43ae91 to
6e8e281
Compare
JackRao123
added a commit
to basetenlabs/Megatron-Bridge
that referenced
this pull request
Aug 8, 2026
…D under CP) Picks up basetenlabs/Megatron-LM#25 (e43ae913f): TEDotProductAttention now passes the tail-inclusive pad_between_seqs answer explicitly under context parallelism, engaging TE's exact get_cu_seqlens_on_cp_rank path. Fixes the LPS-1063 nondeterministic forward/gradients and silent boundary-row mis-attention caused by TE's cu_seqlens[:-1] auto-detect (NVIDIA/TransformerEngine#3331). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Released TE's pad_between_seqs auto-detect ignores padding after the last sequence; under context parallelism that silently corrupts chunk-boundary rows (nondeterministic forward/gradients + wrong attention). Compute the tail-inclusive answer at the call site and pass it explicitly. Details: #25. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
JackRao123
force-pushed
the
jackrao/lps-1063-thd-cp-pad-between-seqs
branch
from
August 8, 2026 22:47
6e8e281 to
2919b7d
Compare
JackRao123
added a commit
to basetenlabs/Megatron-Bridge
that referenced
this pull request
Aug 8, 2026
…D under CP) Picks up basetenlabs/Megatron-LM#25 (e43ae913f): TEDotProductAttention now passes the tail-inclusive pad_between_seqs answer explicitly under context parallelism, engaging TE's exact get_cu_seqlens_on_cp_rank path. Fixes the LPS-1063 nondeterministic forward/gradients and silent boundary-row mis-attention caused by TE's cu_seqlens[:-1] auto-detect (NVIDIA/TransformerEngine#3331). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jerryhong21
approved these changes
Aug 8, 2026
| qkv_format = packed_seq_kwargs.get('qkv_format', self.qkv_format) | ||
|
|
||
| # Released TE mis-detects tail-only padding as "no padding", which | ||
| # under context parallelism silently corrupts chunk-boundary rows. |
There was a problem hiding this comment.
lets clean up these comments # slop
JackRao123
added a commit
to basetenlabs/Megatron-Bridge
that referenced
this pull request
Aug 8, 2026
…D under CP) (#31) * build: bump Megatron-LM (explicit pad_between_seqs for tail-padded THD under CP) Picks up basetenlabs/Megatron-LM#25 (e43ae913f): TEDotProductAttention now passes the tail-inclusive pad_between_seqs answer explicitly under context parallelism, engaging TE's exact get_cu_seqlens_on_cp_rank path. Fixes the LPS-1063 nondeterministic forward/gradients and silent boundary-row mis-attention caused by TE's cu_seqlens[:-1] auto-detect (NVIDIA/TransformerEngine#3331). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * build: pin Megatron-LM to merged trainers-main HEAD (57efae08) --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
jerryhong21
pushed a commit
that referenced
this pull request
Aug 20, 2026
#25) Released TE's pad_between_seqs auto-detect ignores padding after the last sequence; under context parallelism that silently corrupts chunk-boundary rows (nondeterministic forward/gradients + wrong attention). Compute the tail-inclusive answer at the call site and pass it explicitly. Details: #25. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
jerryhong21
pushed a commit
that referenced
this pull request
Aug 20, 2026
#25) Released TE's pad_between_seqs auto-detect ignores padding after the last sequence; under context parallelism that silently corrupts chunk-boundary rows (nondeterministic forward/gradients + wrong attention). Compute the tail-inclusive answer at the call site and pass it explicitly. Details: #25. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
jerryhong21
pushed a commit
that referenced
this pull request
Aug 21, 2026
#25) Released TE's pad_between_seqs auto-detect ignores padding after the last sequence; under context parallelism that silently corrupts chunk-boundary rows (nondeterministic forward/gradients + wrong attention). Compute the tail-inclusive answer at the call site and pass it explicitly. Details: #25. Co-authored-by: Claude Fable 5 <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.
The bug
Packed (THD) batches describe sequence boundaries with two lists of running totals:
cu_seqlens— counting real tokens only. One 698-token sequence →[0, 698].cu_seqlens_padded— including padding. Padded to 704 →[0, 704].pad_between_seqs— a flag telling TE the two lists differ.True→ TE computes each CP rank's token counts exactly.False→ shortcut: divide the totals by the number of ranks.TE guesses the flag by comparing the lists without their last entry (
[:-1]). Padding at the end of the batch only shows in the last entry — so for our batches TE always guessesFalseand takes the shortcut, which miscounts whenever the real length doesn't divide evenly:The first failure mode is what broke the Nemotron nightly ckpt-roundtrip gate; the second ships silently in every CP>1 THD training run.
The fix
Don't let TE guess: we have both lists at the call site, so compare them fully (last entry included) and pass the flag explicitly. Scoped to CP because that's the only place the shortcut is wrong — setting the flag elsewhere would needlessly switch attention kernels.
Validation
trainersrepo,experiment_artefacts/lps1073/(LPS-1073, split from the original LPS-1063).Downstream bumps: basetenlabs/Megatron-Bridge#31 → basetenlabs/trainers#994.
🤖 Generated with Claude Code