Repository navigation
[Fix] gdn: Keep a mixed batch's decode tail on the decode kernels under deterministic inference - #46525
Open
MarinaMackay wants to merge 1 commit into
Open
[Fix] gdn: Keep a mixed batch's decode tail on the decode kernels under deterministic inference#46525MarinaMackay wants to merge 1 commit into
MarinaMackay wants to merge 1 commit into
Conversation
…er deterministic inference With --enable-mixed-chunk, the eager runner runs a MIXED batch as EXTEND, so GDN layers process each running request's decode token with the chunked prefill kernel instead of the recurrent decode kernel. The two agree only up to rounding, and the difference stays in the recurrent state, so greedy output depended on whether a prefill happened to be mixed in. ForwardBatch now carries the number of mixed-in decode rows. Under --enable-deterministic-inference, GDNAttnBackend cuts those rows off once per forward and runs them through forward_decode, and the prefill rows through the unchanged extend path. Fixes sgl-project#46446 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarinaMackay
requested review from
Fridge003,
Ying1123,
hanming-lu,
hebiao064,
hnyls2002,
ispobock,
merrymercy,
yizhang2077 and
yuan-luo
as code owners
October 26, 2026 06:29
This branch has not been deployed
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.
Motivation
Fixes #46446. With
--enable-deterministic-inferenceand--enable-mixed-chunk, Qwen3.5-9B's greedy output for a request changes when another request's prefill is mixed into one of its decode steps.EagerRunner.executeruns a MIXED batch as EXTEND, so the GDN layers process each running request's decode token as a 1-token sequence through the chunked prefill kernel (chunk_gated_delta_rule). Without mixed chunk, the same token goes through the recurrent decode kernel. The two are mathematically equal but not bitwise equal, and the difference stays in the recurrent state. In the issue's repro only one step is mixed (the 255-token intruder plus the target's 1-token tail at prefix 4120), and that step is enough to flip the target's greedy token about 100 tokens later. The full-attention layers (Triton, deterministic) do not need a change: with only the GDN layers fixed, the outputs match exactly.Modifications
ForwardBatch.num_mixed_decode_reqs: the number of running requests thatmix_with_runningappended to a MIXED batch, set ininit_newfrommix_running_indices_cpu. This is needed because the eager runner relabels the batch as EXTEND before the attention backends see it. TBO children set it toNone.GDNAttnBackend: under deterministic inference,init_forward_metadatacuts a mixed batch once per forward into its prefill rows and its decode tail (build_gdn_mixed_decode_split).forward_extendthen runs the prefill rows through the unchanged extend path and the tail throughforward_decode, the same path a decode step takes. The tails are untracked in a mixed step (as inmix_with_running), so no state tracking changes.Accuracy Tests
1x H200 NVL (SM90), main
d7f832d30a, the issue's engine settings (portable/repro.pyfrom the issue: Triton attention and linear attention, deterministic, eager, fp32 lm_head, seed 42).The issue's two-request repro (
pair_T3.jsonl, fresh engine per run):a99c7d05(reported revision)Each arm is stable across trials on main, so the difference is between the two scheduling paths, not run-to-run noise. With this PR the mixed-chunk outputs are token-identical to main's mixed-chunk-off outputs.
Client concurrency 1 vs 8, mixed chunk on (32 prompts of 300-3000 tokens cut from the repro's prompt, 64 greedy tokens each, script below). Number of prompts whose outputs differ between the two runs:
This PR and #45545 fix different things. #45545 aligns where chunked prefill cuts a GDN sequence, which removes the concurrency differences that remain with mixed chunk off. This PR fixes the mixed-in decode tail, which #45545 does not touch, and which the issue's two-request repro needs. (#45545 conflicts with
8252e3af63inschedule_policy.py. For these runs I kept #45545's side of both hunks, which is equivalent without DCP.) The remaining 1/32 with both fixes only appears with radix cache on, and I have not looked into it. It is out of scope here.Concurrency script
Speed Tests and Profiling
The default path is unchanged: the split only runs under
--enable-deterministic-inference, and only for a mixed batch. There it adds two shallowForwardBatchcopies and two metadata copies per forward (shared by all GDN layers), and splits each GDN layer's call into one extend launch for the prefill rows and one decode launch for the tail.Checklist
Tests run (1x H200 NVL):
test_deterministic_mixed_batch_decode_tail_matches_decodeintest/registered/attention/unittests/gdn/test_triton.py: a mixed batch (one 40-token prefill plus two decode tails at prefixes 24 and 31) must give the tails the same output, SSM state, and conv state, bit for bit, as a decode step for the same requests; the whole batch is also checked against the kit's PyTorch reference. It fails on main (tail output differs) and passes with this change.test/registered/attention/unittests/gdn/test_triton.py: 14 passed, 26 subtests passed.pre-commit run --files <changed files>: all hooks passed.Review and Merge Process
Developed with AI assistance (Claude Code); I reviewed the change and the test results.
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #40280095968
Latest PR Test (Extra): ❌ Run #40280096033
Latest PR Test (AMD ROCm 10): ❌ Run #40280096144