Skip to content

[Feat] unified_cache: Support hybrid SWA + Mamba models in the Mooncake direct linker - #41343

Merged
hnyls2002 merged 16 commits into
sgl-project:mainfrom
alphabetc1:feat/linker-mamba
Oct 17, 2026
Merged

hnyls2002 merged 16 commits into
sgl-project:mainfrom
alphabetc1:feat/linker-mamba

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The unified-cache external linker (direct L3, no host tier) supports Full and SWA tree components only. Hybrid SWA + Mamba models such as Inkling are rejected at startup by both the Python wrapper and the Rust tree core, and the Mamba component's linker hooks raise.

Depends on #44220: Inkling replays the Full prefill CUDA graph by default, and without #44220 a loading batch can replay before its layer-wise load lands.

Modifications

Device pool group for FULL + SWA + MAMBA (linker_pool_assembler.py, hybrid_pool_assembler.py)

  • _MambaSwaStrategy.build_direct_linker_pool_group: the full-attention and SWA MHA pools each pack a layer's K and V into one page object; the Mamba pool is slot-addressed (one row per state slot; the empty temporal state of conv-only models is skipped).
  • Rejected at startup with a clear error: --enable-unified-memory, int8 Mamba checkpoints, Mamba side states (short conv / ngram), and scaled KV caches.

Mamba component (components/mamba.py)

  • OFFLOAD: one state per checkpoint node, keyed by the node's last page hash under TRAILING_PAGES, so a prefix is restorable only where a stored state ends.
  • LOOKUP / LOAD: the state of the restorable prefix's last page. LOAD allocates the slot the state is loaded into (_alloc_mamba_slot, evicting if needed, same sizing contract as HiCache's prepare_load_back).
  • PREPARE binds the loaded slot as the request's own state (freeing a slot it already held, e.g. from a shorter device CoW match) and drops the deferred CoW/clear and the ReplaySSM cursor, shared with the HiCache buffer load-back via _adopt_loaded_state. The forward then reads the state layer by layer through the linker's layer counter, already registered on req_to_token_pool for Mamba pools. ABORT frees the loaded slot.

Wrapper (unified_cache_linker.py)

  • Accept ComponentType.MAMBA.

Mooncake keys (mooncake_store.py)

  • A linker DevicePoolEntry always maps to one object per page per pool (_k for KV, _{pool} otherwise); the layer-wise load reads one key per location. Without this, the MHA SWA entry has no key scheme (Unsupported Mooncake hybrid pool name: swa). Keys for the existing DeepSeek-V4 / DSA linker pools are unchanged: those groups are rank-replicated and already took the single-object branch.

Rust tree core

  • Drop the Mamba rejection in set_enable_external_cache_linker and add MambaComponent::build_external_linker_offload_transfer (without it the Rust core never offloads a Mamba state, so it never restores one).

Tests

  • test_unified_cache_linker.py (Python and Rust tree cores): test_mamba_state_round_trips_only_at_its_checkpoint (offload keys, restorable only at a stored state, LOAD/PREPARE binding, insert), test_mamba_load_supersedes_a_shorter_device_cow (a shorter device CoW must not overwrite the loaded state or leak its slot).
  • test_linker_pool_assembler.py::test_mamba_swa_uses_hybrid_assembler_strategy: K/V packing offsets, slot-addressed Mamba rows, empty temporal state skipped.
  • Linker, pool-assembler and Mooncake unit tests: 89 passed; cargo test --lib: 930 passed.

Accuracy Tests

Temporary CI skip: test_unified_cache_linker_kl_inkling.py is disabled in CI until #44220 is merged and included in the tested branch (tracking deadline: 2026-10-29). Re-enable its CI registration after that fix lands. This lets dependent PRs proceed, but does not remove the runtime correctness dependency on #44220: Full prefill graph replay can read incomplete layer-wise loads without it. The measured results below are unchanged.

New test_unified_cache_linker_kl_inkling.py (tiny thinkingmachines/Inkling --revision test, Mooncake, --enable-deterministic-inference, default Full prefill CUDA graph). This checkpoint scores every token identically in prefill and decode, so the threshold is a 1e-9 floor, not a tolerance. Turn 1 offloads, /flush_cache drops the device tree, turn 2 restores from Mooncake alone (asserts cached_tokens_details.host == cached_tokens) and is replayed against recomputed logprobs.

Measured on 1x GB300 (Mooncake over TCP), with #44220 applied:

Run avg KL
This PR, 4 runs (one at the current head) 0.0 each
This PR, 0.2 s injected delay per loaded layer 0.0
Without #44220 2.5e-3 (fails)
Linker disabled (cold recompute, oracle check) 0.0
Negative control: loaded Mamba state cleared before the forward 8.0e-5 (fails)

Known limitations

  • Not covered: FULL + Mamba without SWA, the UMBP (mori) backend, unified memory, scaled KV, int8 Mamba checkpoints, Mamba side states.
  • A Mamba checkpoint attached to a node that is already stored externally (e.g. a split / branching point) is not offloaded again; this loses a hit but does not affect correctness.

Related: #39511 (FULL + Mamba on UMBP for Kimi K3); the pool group, UMBP and DCP parts there are complementary to this PR.

Checklist

  • Format your code according to the Code Formatting with Pre-Commit.
  • Add unit tests.
  • Provide accuracy evaluation results.

CI States

Latest PR Test (Base): ✅ Run #38998794952
Latest PR Test (Extra): ✅ Run #38998794915
Latest PR Test (AMD ROCm 10): ❌ Run #38998794906

@github-actions github-actions Bot added hicache Hierarchical Caching for SGLang unified-radix-cache labels Sep 26, 2026
@hzh0425 hzh0425 self-assigned this Sep 28, 2026
@stmatengss stmatengss self-assigned this Sep 28, 2026
@alphabetc1
alphabetc1 marked this pull request as draft October 12, 2026 16:22
@alphabetc1
alphabetc1 force-pushed the feat/linker-mamba branch 2 times, most recently from 5724394 to 10730ce Compare October 13, 2026 01:18
@alphabetc1
alphabetc1 marked this pull request as ready for review October 13, 2026 14:18
@alphabetc1 alphabetc1 changed the title [Unified Cache] Support hybrid SWA + Mamba models in the Mooncake direct linker [Feat] unified_cache: Support hybrid SWA + Mamba models in the Mooncake direct linker Oct 14, 2026
@alphabetc1

Copy link
Copy Markdown
Collaborator Author

/rerun-test -c

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/linker/test_unified_cache_linker_kl_inkling.py

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_unified_cache_linker.py

@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 15, 2026
@alphabetc1 alphabetc1 added the highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed label Oct 17, 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) hicache Hierarchical Caching for SGLang highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed 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.

5 participants