Skip to content

Fix mamba track-boundary seqlen under overlap scheduler - #31369

Merged
ispobock merged 2 commits into
sgl-project:mainfrom
sshleifer:fix-mamba-track-boundary-overlap
Jul 17, 2026
Merged

ispobock merged 2 commits into
sgl-project:mainfrom
sshleifer:fix-mamba-track-boundary-overlap

Conversation

@sshleifer

@sshleifer sshleifer commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

SchedulerBatchResultProcessor._mamba_check_track_boundary detects the per-interval mamba tracking boundary (and records mamba_last_track_seqlen) from req.kv_committed_len:

if req.kv_committed_len % interval == 0:
    return True, req.kv_committed_len

Under the overlap scheduler, prepare_for_decode for batch N+1 runs before process_batch_result for batch N, and it increments kv_committed_len. So when the boundary check runs for batch N, kv_committed_len already 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_seqlen was 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_seqlen is 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:

seq_len = len(req.origin_input_ids) + len(req.output_ids) - 1
if seq_len % interval == 0:
    return True, seq_len

The just-decoded token is already appended to output_ids before this runs (process_batch_result_decode), so output_ids is non-empty and this equals the forward-N tracking seqlen. The spec-decode branch already used req.seqlen - 1 and 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

_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.
@gemini-code-assist

Copy link
Copy Markdown
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 hanming-lu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concern as long as all ci pass

@ispobock ispobock added run-ci CI: run the baseline test suite on this PR bypass-fastfail run-ci-extra CI: also run the extra suite (requires run-ci) labels Jul 16, 2026
@ispobock
ispobock merged commit 0675d30 into sgl-project:main Jul 17, 2026
242 of 305 checks passed
@ispobock ispobock mentioned this pull request Aug 8, 2026
2 tasks done
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants