Repository navigation
Fix mamba track-boundary seqlen under overlap scheduler - #31369
Merged
ispobock merged 2 commits intoJul 17, 2026
Merged
Conversation
_mamba_check_track_boundary detected the per-interval mamba tracking boundary (and recorded mamba_last_track_seqlen) from req.kv_committed_len. Under the overlap scheduler, prepare_for_decode for the next batch increments kv_committed_len before process_batch_result for the current batch runs, so it leads the true decode seqlen by a jittering lookahead (measured 0 or 1 depending on prefill interleaving). The boundary then fires one decode step early on most steps and the tracked mamba state is recorded against a seqlen it doesn't correspond to; a later request that reuses/donates that tracked prefix extends from a state a cold prefill recompute would not produce -> wrong logprobs for that request. Use the lookahead-invariant seqlen len(origin_input_ids)+len(output_ids)-1 (the just-decoded token is appended before this runs). Spec-decode branch already used req.seqlen-1 and is unchanged.
sshleifer
requested review from
Ying1123,
hnyls2002,
merrymercy and
xiezhq-hermann
as code owners
July 15, 2026 20:09
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
hanming-lu
approved these changes
Jul 16, 2026
hanming-lu
left a comment
Collaborator
There was a problem hiding this comment.
No concern as long as all ci pass
alisonshao
added a commit
that referenced
this pull request
Jul 18, 2026
Zhylkaaa
pushed a commit
to Zhylkaaa/sglang
that referenced
this pull request
Jul 29, 2026
2 tasks done
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 2026
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 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.
Motivation
SchedulerBatchResultProcessor._mamba_check_track_boundarydetects the per-interval mamba tracking boundary (and recordsmamba_last_track_seqlen) fromreq.kv_committed_len:Under the overlap scheduler,
prepare_for_decodefor batch N+1 runs beforeprocess_batch_resultfor batch N, and it incrementskv_committed_len. So when the boundary check runs for batch N,kv_committed_lenalready carries the next batch's increment — it leads the true decode seqlen by a jittering lookahead in (0,1).Instrumenting a hybrid (mamba + sliding-window + MoE) model over ~1000 decode-boundary samples,
kv_committed_len - true_seqlenwas 1 on ~85% of steps and 0 on ~15% (the split tracks whether a prefill batch interleaved).Consequences: the tracking boundary fires one decode step early on most steps, and
mamba_last_track_seqlenis recorded against a seqlen the tracked state doesn't correspond to. A later request that reuses (or donates) that tracked mamba prefix then extends from a state a cold prefill recompute would not reproduce → wrong logprobs for that request. It's episodic (only requests whose tracked prefix is later reused), so it surfaces as rare per-sequence output divergence under high concurrency with the mamba radix cache + overlap scheduler, while small/single-stream tests pass.Modification
Use the lookahead-invariant seqlen — a pure function of tokens the request has produced — matching what the forward's tracking mask used:
The just-decoded token is already appended to
output_idsbefore this runs (process_batch_result_decode), sooutput_idsis non-empty and this equals the forward-N tracking seqlen. The spec-decode branch already usedreq.seqlen - 1and is unchanged.Test
Validated in a downstream integration: a bitwise sampler↔recompute logprob-parity RL run on a d24 hybrid (sconv + SWA + MoE) model showed sustained episodic per-sequence divergence with the original code and exact parity with this fix, tracking still enabled, over multiple optimizer steps at ~1000-request concurrency. Single-file change, no interface change.
CI States
Latest PR Test (Base): ❌ Run #29476273055
Latest PR Test (Extra): ❌ Run #29476272767