Skip to content

[Fix] mamba: Release consumed lazy Mamba prefix locks before donation retry - #43559

Merged
ispobock merged 6 commits into
sgl-project:mainfrom
alphabetc1:fix/mamba-lazy-peak-slot-budget
Oct 18, 2026
Merged

ispobock merged 6 commits into
sgl-project:mainfrom
alphabetc1:fix/mamba-lazy-peak-slot-budget

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Dependency

Depends on #43567, now merged and included in this branch. Releasing the prefix lock alone can expose stale in-place checkpoint donation under slot pressure.

Problem and change

With lazy overlap, the next decode can consume the temporary tracking slot before the previous prefill donates its checkpoint. Donation then needs a replacement slot while the consumed prefix state is still locked, exhausting the pool and asserting.

On a failed lazy donation allocation, release this request's consumed Mamba prefix reference before eviction/retry. Preserve KV locks and other requests' references; record the release to avoid a double decrement. Keep the allocation assertion and existing capacity formulas unchanged.

The CPU regression covers full 3-slot and 4-slot per-request pools and the subsequent normal unlock. A registered GPU regression additionally uses exactly 4 Mamba slots and 1 running request: warm a 128-token prefix, then extend it to 255 tokens and generate 32 tokens with overlap and decode CUDA graphs enabled. The first decode takes the fourth slot before prefill donation, which must reclaim the consumed prefix instead of requiring a fifth slot. It reuses the existing Mamba KL test server and CI registration. Checkpoint invalidation is handled separately in #43567.

Validation

  • Exact base/head red-green check with the same new testcase on GB300: base f05da43d44067e4e4f95302b6d3bd40f7deb3b1d plus the testcase fails in prepare_for_caching_req -> _alloc_mamba_slot with AssertionError: Can not alloc mamba cache (exit 1); PR head c29503969e33f5c8e103cde6abb1caba209abd99 passes (exit 0). The base run uses the unmodified base runtime, not a selectively reverted fix.

  • Added GPU regression validated on GB300 with Qwen3.5-0.8B: both tests in test_mamba_cache_kl.py pass (49.7 seconds), including the existing checkpoint-reuse test with KL=0.

  • Negative control: remove only this PR's prefix-lock release block while retaining [Unified Radix] Invalidate lazy Mamba checkpoints before in-place tracking #43567; the new test fails in prefill checkpoint donation with AssertionError: Can not alloc mamba cache.

  • Pre-commit passed for the added test.

  • This branch independently: 14 CPU tests and 12 subtests passed; pre-commit passed.

  • The two PRs merge without conflicts. Their combined runtime files are identical to the previously validated combined fix (43d6c96).

  • Combined E2E on GB300 with overlap and decode CUDA graphs: Qwen3.5-0.8B passes 24 requests with 1 running request / 4 slots and 96 with 4 / 16; Qwen3.5-4B + NEXTN passes 24 with 1 / 4. Original main asserts in these cases. Both single-request 4-slot runs exactly match their 8-slot references in output tokens and logprobs. Ordinary and NEXTN 3-slot runs also complete 24 requests each.

The earlier combined GPU results cover both fixes together. The new negative control isolates the prefix-lock release change while retaining checkpoint invalidation.


CI States

Latest PR Test (Base): ✅ Run #39032574328
Latest PR Test (Extra): ❌ Run #39032574243
Latest PR Test (AMD ROCm 10): ❌ Run #39032574315

@alphabetc1 alphabetc1 changed the title [Fix] Budget lazy Mamba slots for the overlap checkpoint peak [Fix] Release consumed lazy Mamba prefix locks before donation retry Oct 10, 2026
@alphabetc1 alphabetc1 changed the title [Fix] Release consumed lazy Mamba prefix locks before donation retry [Fix] Preserve lazy Mamba checkpoint validity under slot pressure Oct 10, 2026
@alphabetc1
alphabetc1 marked this pull request as draft October 10, 2026 14:49
@alphabetc1
alphabetc1 force-pushed the fix/mamba-lazy-peak-slot-budget branch from 43d6c96 to 9245134 Compare October 10, 2026 14:49
@alphabetc1 alphabetc1 changed the title [Fix] Preserve lazy Mamba checkpoint validity under slot pressure [Fix] Release consumed lazy Mamba prefix locks before donation retry Oct 10, 2026
@alphabetc1 alphabetc1 changed the title [Fix] Release consumed lazy Mamba prefix locks before donation retry [Fix] mamba: Release consumed lazy Mamba prefix locks before donation retry Oct 14, 2026
@alphabetc1
alphabetc1 marked this pull request as ready for review October 16, 2026 09:41
@alphabetc1 alphabetc1 added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) labels Oct 16, 2026
@ispobock
ispobock merged commit ba3fc94 into sgl-project:main Oct 18, 2026
200 of 214 checks passed
@alphabetc1
alphabetc1 deleted the fix/mamba-lazy-peak-slot-budget branch October 18, 2026 09:08
finnff added a commit to finnff/sglang that referenced this pull request Oct 19, 2026
…fresh

Conflict in mamba.py: upstream sgl-project#43559's lazy lock release (req.lock, TreeLock) moved into _try_alloc_mamba_slot(req), so the donation callers pass req and skip the stash on None.

Claude-Session: https://claude.ai/code/session_019zFzB8crbELHdkhezNhjU4
detain added a commit to detain/sglang that referenced this pull request Oct 19, 2026
…sumed lazy Mamba prefix locks before donation retry

Hand-port: our fork renamed _alloc_mamba_slot -> _try_alloc_mamba_slot
(entry 197/sgl-project#37943, Optional return + _record_skipped_checkpoint) and folded
upstream's three donation call sites into one needs_new_slot branch, so the
release-before-evict block lands inside _try_alloc_mamba_slot(req=None) and
the single donation call site passes req.

Upstream's new donated-ratio test targets the old name; retargeted to
_try_alloc_mamba_slot. The entry-197 exhaustion test needed the exec bag
published (mamba_radix_cache_strategy="extra_buffer", lazy off => the new
block is inert) because the release block reads get_exec().

(cherry picked from commit ba3fc94, hand-ported)
(cherry picked from commit fb0cdfdccbd8b9fc1f0cc4d82f934fbedf352024)
nanjiangwill pushed a commit to modal-projects/sglang that referenced this pull request Oct 29, 2026
nanjiangwill pushed a commit to modal-projects/sglang that referenced this pull request Oct 29, 2026
nanjiangwill pushed a commit to modal-projects/sglang that referenced this pull request Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants