Skip to content

[Bugfix][Core] Skip Mamba partial-tail stops after mid-block hits - #51763

Closed
ivanium wants to merge 1 commit into
vllm-project:mainfrom
ivanium:fix/mamba-sched-partial-hit
Closed

[Bugfix][Core] Skip Mamba partial-tail stops after mid-block hits#51763
ivanium wants to merge 1 commit into
vllm-project:mainfrom
ivanium:fix/mamba-sched-partial-hit

Conversation

@ivanium

@ivanium ivanium commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Credit: @ywang96 found this issue and authored the original fix. This PR ports his change onto current upstream main.

In Mamba "align" cache mode, a request resuming from a fine-grained prefix hit mid-block could still stop at the prompt's partial-tail hash boundary. That second off-grid cut leaves the SSM state misaligned and can corrupt the continuation.

The fix only uses the partial-tail stop when the chunk starts on a Mamba block boundary. The tradeoff is that, after a mid-block hit, vLLM no longer forces a stop at the prompt's final hash boundary. It therefore will not always materialize and cache the precise end of the prompt, which can reduce prefix-cache granularity and reuse. This prioritizes correct SSM state; aligned starts retain the existing cache behavior.

This is not duplicate work: no open PR addresses this condition. #51113 fixes the adjacent block-realignment stop, not this distinct partial-tail stop.

Test Plan

  • Run the prefix-cache tests.
  • Run pre-commit on both changed files.
  • Confirm the regression covers the production dimensions and that aligned starts still cache the partial tail.

Test Result

  • .venv/bin/python -m pytest tests/v1/core/prefix_cache/ -q — 33 passed.
  • .venv/bin/pre-commit run --files vllm/v1/core/sched/scheduler.py tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py — passed.
  • Model evaluation was not rerun for this draft port. The source change was motivated by observed Kimi-K3 output corruption; the unit regression uses that production configuration.

OpenAI Codex was used to port and validate this change. The human submitter must review every changed line and the test results before marking the PR ready.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results.
  • Documentation updates were considered; none are needed for this internal scheduler correctness fix.

BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)

In "align" mamba cache mode `_mamba_block_aligned_split` adds one extra stop
at the prompt's last hash boundary so the partial-tail entry can be
registered. That boundary is off the block grid by construction whenever
`hash_block_size < block_size`, which is fine when the chunk *starts* on the
grid -- the state at the start was materialized and the tail write is the only
unaligned one.

It is not fine when the request resumes mid-block. Then the block boundary
already crossed was never materialized, and the extra stop cuts the chunk at a
second unaligned position instead of re-aligning, leaving the SSM state wrong
for the rest of the prefill.

The production config that hit this is Kimi-K3: block_size 1536,
`--prefix-match-unit 128`, external prefix hit at 24960 = 16*1536 + 384, prompt
25297. The re-align stop 26112 is past `last_cache_position` (24576) so it is
suppressed; 24576 is behind the resume point; the tail boundary 25216 is left
as the only stop and prefill is cut 640 tokens off the grid. Observed
end-to-end as a silent HTTP 200 with `finish_reason: stop`, empty content, and
the model resuming from the middle of a structural marker it never opened.

Require a block-aligned start for that stop. Aligned starts keep registering
the partial tail, so the existing behaviour and its test are unchanged; a
mid-block resume now runs the fresh tail in one chunk, which is what the
measured-clean configurations already did.

Signed-off-by: Roger Wang <hey@rogerw.io>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
@mergify mergify Bot added the bug Something isn't working label Aug 11, 2026
@ivanium
ivanium marked this pull request as ready for review August 11, 2026 05:17

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@ivanium

ivanium commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

close as superseded by #51766 which is a better fix

@ivanium ivanium closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants