Repository navigation
Fix: synthesize segment_ids in TunixMaxTextAdapter to mask pad attention - #4016
Merged
Merged
Conversation
py4
requested review from
NicoGrande,
NuojCheng,
RissyRan,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
igorts-git,
jesselu-google,
jiangjy1982,
khatwanimohit,
richjames0,
suexu1025 and
vipannalla
as code owners
May 29, 2026 18:32
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
py4
force-pushed
the
pr/segment-ids-fix
branch
4 times, most recently
from
May 29, 2026 21:39
454f01f to
4dc2ecd
Compare
When tunix invokes the model with `decoder_segment_ids=None`, MaxText falls back to causal-only attention masking. With left/right-padded batches this silently lets queries at non-pad positions attend to pad-position keys, producing corrupted log-probs in the trainer forward (rollout-side vLLM is fine — its scheduler avoids padded sequences). Add an optional `pad_id` constructor arg to TunixMaxTextAdapter. When set AND tunix passes `decoder_segment_ids=None`, synthesize per-token segment_ids = (input_tokens != pad_id), so MaxText's segment-based mask blocks attention across pad/non-pad boundaries. Plumb the tokenizer's pad_token_id through model_creation_utils so the RL training path (train_rl.py) picks it up automatically. Behavior is opt-in: existing callers that omit `pad_id` see no change. Empirical impact (Qwen3-1.7B GRPO on GSM8K, GPU recipe LR=2e-6 beta=0.04): - with this fix: step-50 vtc_mean_reward 0.5601 -> 0.6970 (+0.137) - without this fix: step-50 vtc_mean_reward 0.5601 -> 0.5545 (-0.005) The fix is load-bearing for matching GPU's training trajectory.
SurbhiJainUSC
approved these changes
May 29, 2026
4 tasks done
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.
When tunix invokes the model with
decoder_segment_ids=None, MaxText falls back to causal-only attention masking. With left/right-padded batches this silently lets queries at non-pad positions attend to pad-position keys, producing corrupted log-probs in the trainer forward (rollout-side vLLM is fine — its scheduler avoids padded sequences).Add an optional
pad_idconstructor arg to TunixMaxTextAdapter. When set AND tunix passesdecoder_segment_ids=None, synthesize per-token segment_ids = (input_tokens != pad_id), so MaxText's segment-based mask blocks attention across pad/non-pad boundaries.Plumb the tokenizer's pad_token_id through model_creation_utils so the RL training path (train_rl.py) picks it up automatically.
Behavior is opt-in: existing callers that omit
pad_idsee no change.Empirical impact (Qwen3-1.7B GRPO on GSM8K, GPU recipe LR=2e-6 beta=0.04):
The fix is load-bearing for matching GPU's training trajectory.
Checklist
max_seq_mult_prob_errordrops from ~200k–1.4M to ~1.02 after fixpad_idsee no behavior changeTunixMaxTextAdapterintegration code touched)