Skip to content

Gate mamba extra-buffer predicates on uses_mamba_radix_cache - #37474

Merged
ispobock merged 7 commits into
sgl-project:mainfrom
sshleifer:mamba-extra-buffer-uses-gate
Sep 17, 2026
Merged

ispobock merged 7 commits into
sgl-project:mainfrom
sshleifer:mamba-extra-buffer-uses-gate

Conversation

@sshleifer

@sshleifer sshleifer commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

An explicitly passed --mamba-radix-cache-strategy extra_buffer on a model without mamba state steers the scheduler into the mamba-only tracking paths and crashes on the first prefill batch:

File "sglang/srt/managers/schedule_batch.py", in _mamba_radix_cache_v2_req_prepare_for_extend
    track_index = req.mamba_ping_pong_track_buffer[req.mamba_next_track_idx].item()
TypeError: 'NoneType' object is not subscriptable

auto is already arch-gated, so only an explicit misconfiguration reaches this state. We hit it when a shared test launcher started passing the strategy for every model in its zoo.

Modifications

  • handle_mamba_radix_cache (the unconditional call slot) fails fast when the resolved view has no uses_mamba_radix_cache but the extra-buffer predicate is armed: --mamba-radix-cache-strategy extra_buffer needs mamba state, got <arch>. The predicates themselves are unchanged. With the radix cache disabled the flag is genuinely inert everywhere, so that combination is left alone.
  • Inkling pins extra_buffer through its model override rather than the linear-attn registry, so the override now also declares uses_mamba_radix_cache=True; model overrides are collected before the unconditional slot runs, so an explicit extra_buffer on Inkling does not trip the check. With the leaf declared, the validation slot runs for Inkling, so _MAMBA_EXTRA_BUFFER_ARCHS accepts the Inkling archs.

Tests

test/registered/unit/test_model_overrides.py: LlamaForCausalLM with explicit extra_buffer raises with the message above; the same with --disable-radix-cache resolves without error. Existing mamba fixtures and the runtime-context parity test are untouched from main.

-Robot


CI States

Latest PR Test (Base): ❌ Run #35190739916
Latest PR Test (Extra): ❌ Run #35190740005
Latest PR Test (AMD ROCm 10): ⏳ Run #35190739931

An explicitly passed --mamba-radix-cache-strategy=extra_buffer steered
non-mamba models into the mamba scheduler tracking paths, crashing on
the first prefill batch (req.mamba_ping_pong_track_buffer is None).
Require the architecture-derived uses_mamba_radix_cache leaf in the
extra-buffer predicates so the strategy stays inert for models without
mamba state, and resolve the leaf in the Inkling overrides (which pin
extra_buffer outside the linear-attn registry).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012yzAauSvQdQD835r5feCFw
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-01T21:07:35.462825Z 170d14b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 170d14ba09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# The extra-buffer predicates also require the arch-derived leaf, which the
# generic resolution likewise never sets for Inkling.
if not cfg.disable_radix_cache:
overrides["uses_mamba_radix_cache"] = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow Inkling through the mamba extra-buffer validator

With radix caching enabled (the normal Inkling configuration), this marker makes the later unconditional handle_mamba_radix_cache() call treat Inkling as a generic mamba-cache architecture and invoke validate_mamba_extra_buffer(). That validator asserts supports_mamba_cache_extra_buffer(view, model_arch), but neither Inkling architecture is in _MAMBA_EXTRA_BUFFER_ARCHS, so default Inkling startup now fails during argument resolution with extra_buffer is not supported for InklingForConditionalGeneration. Either register Inkling as supported by that validator or avoid routing this model-specific marker through the generic validation path.

Useful? React with 👍 / 👎.

With uses_mamba_radix_cache now resolved for Inkling, the unconditional
mamba radix-cache validation slot runs _validate_mamba_extra_buffer for
these archs; supports_mamba_cache_extra_buffer must accept them or
default Inkling startup fails during argument resolution.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012yzAauSvQdQD835r5feCFw
@ispobock ispobock 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-fastfail labels Sep 2, 2026
@ispobock

Copy link
Copy Markdown
Collaborator

@sshleifer could you fix the conflict?

@ispobock

ispobock commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Since auto is already arch-gated, a non-mamba model only hits this via an explicit --mamba-radix-cache-strategy extra_buffer misconfig. Prefer failing fast with a clear error (extra_buffer needs mamba state, got <arch>) over silently making the flag inert.

@ispobock

Copy link
Copy Markdown
Collaborator

alternative to #39430

Instead of gating the extra-buffer predicates on uses_mamba_radix_cache,
handle_mamba_radix_cache raises when an explicit extra_buffer strategy
reaches a model without mamba state. Predicates and test fixtures return to
main.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ispobock

ispobock commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@sgl-project sgl-project deleted a comment from github-actions Bot Sep 16, 2026
@ispobock
ispobock merged commit 8ae4a39 into sgl-project:main Sep 17, 2026
77 of 94 checks passed
Leoyzen added a commit to Leoyzen/sglang that referenced this pull request Sep 17, 2026
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker.

Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72,
d52e749 — three of them merge-main commits whose only net effect on this
PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup:
with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and
broadcasts each layer to the other TP ranks instead of every rank reading the
same objects.

Files:
- python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup.
- python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker.
- python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new):
  LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the
  existing MLAHostDedupBroadcaster primitive.
- python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py:
  LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch
  logical-plan all_gather gate; rank-0-only load queueing; forward-stream
  broadcasts; broadcast-completion event tracking in num_completed_loads;
  reset/close teardown.
- test/registered/unit/server_args/test_server_args.py: flag validation test.

Manual merge notes:
- Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft
  revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes,
  idx-checksum probe, rank-key handling). All of it is preserved untouched;
  the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__
  broadcaster wiring, num_completed_loads, start_layer_wise_loading,
  load_thread_func, reset/close).
- The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are
  unrelated to this PR's files (verified by diffing the PR range against the
  merge base), so the squash is a faithful net port.
- Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in
  CacheInitParams, both already present in our base (upstream parent == ours).
Leoyzen added a commit to Leoyzen/sglang that referenced this pull request Sep 17, 2026
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker.

Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72,
d52e749 — three of them merge-main commits whose only net effect on this
PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup:
with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and
broadcasts each layer to the other TP ranks instead of every rank reading the
same objects.

Files:
- python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup.
- python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker.
- python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new):
  LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the
  existing MLAHostDedupBroadcaster primitive.
- python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py:
  LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch
  logical-plan all_gather gate; rank-0-only load queueing; forward-stream
  broadcasts; broadcast-completion event tracking in num_completed_loads;
  reset/close teardown.
- test/registered/unit/server_args/test_server_args.py: flag validation test.

Manual merge notes:
- Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft
  revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes,
  idx-checksum probe, rank-key handling). All of it is preserved untouched;
  the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__
  broadcaster wiring, num_completed_loads, start_layer_wise_loading,
  load_thread_func, reset/close).
- The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are
  unrelated to this PR's files (verified by diffing the PR range against the
  merge base), so the squash is a faithful net port.
- Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in
  CacheInitParams, both already present in our base (upstream parent == ours).
Leoyzen added a commit to Leoyzen/sglang that referenced this pull request Sep 18, 2026
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker.

Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72,
d52e749 — three of them merge-main commits whose only net effect on this
PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup:
with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and
broadcasts each layer to the other TP ranks instead of every rank reading the
same objects.

Files:
- python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup.
- python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker.
- python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new):
  LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the
  existing MLAHostDedupBroadcaster primitive.
- python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py:
  LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch
  logical-plan all_gather gate; rank-0-only load queueing; forward-stream
  broadcasts; broadcast-completion event tracking in num_completed_loads;
  reset/close teardown.
- test/registered/unit/server_args/test_server_args.py: flag validation test.

Manual merge notes:
- Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft
  revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes,
  idx-checksum probe, rank-key handling). All of it is preserved untouched;
  the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__
  broadcaster wiring, num_completed_loads, start_layer_wise_loading,
  load_thread_func, reset/close).
- The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are
  unrelated to this PR's files (verified by diffing the PR range against the
  merge base), so the squash is a faithful net port.
- Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in
  CacheInitParams, both already present in our base (upstream parent == ours).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apple-silicon 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.

2 participants