Skip to content

MUSA: route the Mamba2 SSD to FlashInfer for --mamba-backend flashinfer - #257

Draft
yeahdongcn wants to merge 3 commits into
v0.28.0-devfrom
codex/musa100034-flashinfer-ssd-route
Draft

yeahdongcn wants to merge 3 commits into
v0.28.0-devfrom
codex/musa100034-flashinfer-ssd-route

Conversation

@yeahdongcn

@yeahdongcn yeahdongcn commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

MUSA: route the Mamba2 SSD (chunk scan) to FlashInfer when --mamba-backend flashinfer

What this adds

Two build-time patch-series members that make --mamba-backend flashinfer cover the whole Mamba2
path on MUSA, not just its decode half:

member file it patches change
0170-MUSA-route-Mamba2-SSD-to-FlashInfer.patch vllm/model_executor/layers/mamba/ops/ssd_combined.py mamba_chunk_scan_combined_varlen gains a trailing backend=None parameter; on MUSA with backend == "flashinfer" it forwards to flashinfer.mamba.ssd_combined.ssd_combined_fwd_varlen
0171-MUSA-select-Mamba2-SSD-backend.patch vllm/model_executor/layers/mamba/mamba_mixer2.py the SSD call sites pass backend=self.mamba_config.backend.value

plus tests/test_mamba_ssd_flashinfer_route_source.py, a CPU-only source-contract test in the style of
the existing tests/test_mamba_*_source.py files. It pins the two things a reviewer cannot see by
running the suite: that the FlashInfer call forwards the ordering-hazard arguments by name, and
that every SSD call site passes the backend (two on the pinned revision - the autotune warmup and the
prefill scan - and the count is asserted so a future call site cannot silently keep using the stock
kernel).

Every argument is forwarded by name. That is not cosmetic: upstream FlashInfer orders
initial_states, dt_softplus, dt_limit while the MATE implementation orders dt_softplus, dt_limit, initial_states, and the names are identical in both, so a positional forward silently lands
dt_limit's tuple where the kernel reads initial_states.

Design notes: why a parameter, and why an import here

Why not follow the CUDA path? There is no CUDA FlashInfer route for the SSD to follow. On CUDA the
SSD is always vLLM's own Triton ssd_combined.py; --mamba-backend flashinfer has only ever changed the
SSU. And where upstream does route a Mamba-family operator to FlashInfer, it is closed to non-CUDA
platforms on purpose: _resolve_gdn_prefill_backend returns (requested, "triton") as soon as
not current_platform.is_cuda(), then requires SM90 or SM10x with cuda_runtime >= 13. Following
upstream literally would therefore never enable a FlashInfer kernel on MUSA - what this PR adds is the
MUSA-side equivalent of that platform probe.

The import-then-call shape is upstream's own mechanism one layer up: the FlashInfer SSU backend in
ops/ssu_dispatch.py does from flashinfer.mamba import selective_state_update as _fi_ssu inside its
__init__ and calls the result. And MATE works here precisely because it is the flashinfer package
that upstream imports.

Why does the mixer pass backend? Because on CUDA there is exactly one SSD implementation, the
question never arises and the parameter does not exist. This op module sees tensors, not engine config -
the config lives on the layer (self.mamba_config, set in MambaMixer2.__init__). Upstream solves the
same problem for the SSU with a module-global backend selected once by initialize_mamba_ssu_backend(),
which the two worker runners call, after which the mixer's imported selective_state_update needs no
argument at all.

So there are two ways to wire the SSD, and this PR takes the stateless one:

  1. as shipped here - a trailing backend=None plus the value passed at the two call sites. No global,
    no initialization order to get wrong, and the op's other callers (the kernel tests) keep the Triton
    default untouched.
  2. symmetric to ssu_dispatch - a new ops/ssd_dispatch.py holding an abstract backend plus Triton
    and FlashInfer implementations, initialized next to the SSU in the same two runners and imported by
    the mixer, leaving the op signature unchanged. More files, and it reintroduces the
    "backend not initialized" failure mode in any process that runs the model without the runner init.

Happy to switch to (2) if the symmetry with ssu_dispatch.py is preferred. Note that (2) is the shape
the earlier end-to-end harness used, while (1) is what this PR ships; (1) has since been measured in the
same harness and reproduces those numbers within noise, so the caveat that used to sit under this heading
is closed - see "This series as shipped" below.

Which entry point was measured. The runtime instrument used for the measurement resolved
flashinfer.mamba.mamba_chunk_scan_combined_varlen, and this patch calls
flashinfer.mamba.ssd_combined.ssd_combined_fwd_varlen. In the MATE package the former is a true alias
of the latter (mamba_chunk_scan_combined_varlen = ssd_combined_fwd_varlen), so the two names resolve to
the same object - the measured configuration and this patch reach identical code, which is what makes the
numbers above apply to it.

Why the SSD half is missing today

Upstream vLLM already has a backend abstraction for the SSU: ops/ssu_dispatch.py defines
MambaSSUBackend with a Triton and a FlashInfer implementation, selected by MambaBackendEnum, and
mamba_mixer2.py gets its selective_state_update from that module by import. There is no
equivalent for the SSD
- no ssd_dispatch.py - and mamba_mixer2.py calls
mamba_chunk_scan_combined_varlen directly at both call sites, with no backend branch. So the flag
changes the decode path and leaves prefill on vLLM's Triton kernels.

That asymmetry is not free. Measured on MUSA S5000, single-stream, Nemotron-3.5-Lightning-30B-A3B,
MTP6, --max-num-seqs 1, prefill 4096 tokens, 5 repeats:

served path TTFT median TPOT median
stock (no flag) 1745.98 ms 8.0872 ms
--mamba-backend flashinfer, SSU and SSD routed (the state this PR produces) 1248.04 ms (-28.5%) 8.0512 ms (-0.45%)

With only the decode half routed - the state this PR fixes - the same harness came out slower than
stock on both metrics (TTFT 1781.06 vs 1745.98 ms, TPOT 8.6094 vs 8.0872 ms). That reading is the
first attempt of the round and is a directional control rather than a matched five-request arm, so it
is quoted as such; it is the reason this change exists, because it says that enabling the flag
without routing the SSD costs performance instead of buying it.

Dependency

The kernels come from MATE, which exposes them behind the FlashInfer API surface as an importable
flashinfer package:

  • mate#4 - the native MUSA SSU/SSD kernels (MooreThreads/mate, ready for review).
  • mate#5 - the flashinfer adapter package that provides flashinfer.mamba.ssd_combined.ssd_combined_fwd_varlen
    and flashinfer.mamba.selective_state_update.selective_state_update (MooreThreads/mate, ready for review; needs mate#4).
    It carries the wrapper alone and states that dependency; without it, selecting flashinfer fails loudly at the
    first prefill rather than falling back silently.

This PR contains no dependency-pin change and does not consume an external FlashInfer build: the
provider is whichever flashinfer is importable in the environment, i.e. the package that ships with
MATE.

Rollback

--mamba-backend triton restores the previous behaviour exactly. No environment variable is
introduced; the backend flag is the single switch.

Evidence and test plan

  • Patch mechanics (this PR): from a pristine VLLM_COMMIT
    (2cf0a6915ce544dc493a0990f2ea38d81601128a, VLLM_TAG=v0.28.0), the full 171-member series applies
    through the build's own applier (build_apply.py) with 171 applied, 0 already-applied, 0 conflict,
    and an independent raw git apply --recount loop over the same 171 members reports
    applied=171 failed=0. Both new members reverse-check (git apply --reverse --check exit 0) on the
    fully patched tree, so the idempotent path in build_apply.py sees them as already-applied. The
    two patched files are byte-identical across three independently built trees.
  • The new source-contract test: python -m pytest tests/test_mamba_ssd_flashinfer_route_source.py -q
    → 4 passed.
  • Correctness: the routed SSD path was validated against vLLM's own Triton implementation -
    441 cases, 394 of them comparable to the Triton reference, 0 failures, 0 incomparable
    (see mate#4). MATE's own suite: 358 passed, 9 skipped, 1 xpassed; the two test-side failures named in
    the earlier revision of this description (a stale assertion about channel-wise D, and a fixture that built
    cu_seqlens on the CPU) are fixed on the branch. mate#5's adapter suite is green: 11 passed.
  • Performance: the table above; the streaming batched pair at 4 sequences reproduces the same
    direction (wall 19.19 s -> 12.84 s, -33%) with comparable per-step cost and a higher accepted
    length, so the win comes from fewer steps, not from a cheaper step.

This series as shipped, with its dependencies, in one container

mate#4 at 6d33e3a, mate#5 at d1aeba4, and these two members applied to the served tree with git apply
exactly as the series applies them - then asserted line by line rather than trusted to an exit status: all
29 and 2 added lines present, the gate before the Triton call (def=157 gate=208 call=236), both mixer call
sites carrying the backend (calls=2 tagged=2).

  • vllm serve with --mamba-backend flashinfer: six engine rounds, each starting a fresh server, all
    rc=0
    , one identical output hash across all six (ffbca8deab0cafa6), accepted length 4.18-4.53.
  • The numbers reproduce the earlier stand-in-route run within noise: TTFT 1079.26 ms (old) / 1080.94 ms
    (new) against 1079.57 / 1081.35 there; TPOT 7.7799 / 7.7862 against 7.7771 / 7.7834; kernel-level
    1.7711 / 1.7714 ms against 1.7705 / 1.7712. So shape (1) - the shape this PR ships - is now the measured
    shape, which is what the previous "not run through this series" caveat asked for.
  • mate's device suite on the same pair: 358 passed, 9 skipped, 1 xpassed. These source contracts:
    4 passed, on the host and inside the container. mate#5's adapter suite: 11 passed.

Still not run: an end-to-end regression slice on a second Mamba2 model.

Relation to #244

This supersedes the Mamba-routing part of #244 (its MUSA-route-Mamba2-SSD-to-FlashInfer and
MUSA-select-Mamba2-SSD-backend members). It deliberately does not carry:

  • the pin: chain that pointed the build at an external FlashInfer fork - the provider here is the
    package MATE ships;
  • the MTP/graph-capture fixes and the MoE/top-k/setup changes bundled in that branch, which are
    independent of this capability and have largely landed on v0.28.0-dev since;
  • the stochastic-rounding validation relaxation. That relaxation advertised
    --enable-mamba-cache-stochastic-rounding as supported on MUSA+FlashInfer, but the MATE SSU rejects
    rand_seed at runtime, so enabling it would fail late instead of failing at config time. It should
    land only together with an implementation.

Note on the existing series (pre-existing, unrelated to this change)

While validating the apply path: a repeat whole-series application is not fully idempotent on this
base - 34 of the 169 existing members do not reverse-check on a fully patched tree, and a strict repeat
run aborts on 0012. A 169-member control run on a separate pristine tree produces the identical
conflict set, none of the 34 touches either file this PR changes, and both new members report
already-applied. Fresh-clone builds are unaffected; re-running a build in place over an already
patched tree fails loudly rather than mis-applying.

Also on this base, member 0014's hunk headers disagree with its own body (it needs --recount, which
build_apply.py always passes) and 0163 carries no mail header, so the series cannot be replayed with
git am. That is why these two members were produced with the generator's own
git format-patch --no-signature --no-numbered --zero-commit flags, header-for-header identical to the
neighbouring members, instead of by re-running make -f Makefile.sync format-patches. Flagged, not
fixed: repairing legacy members is out of scope here.

Xiaodong Ye added 3 commits September 23, 2026 17:56
mamba_chunk_scan_combined_varlen gains a trailing `backend` keyword. On
MUSA with the flashinfer backend selected it returns the FlashInfer SSD
result instead of running the Triton pipeline, so --mamba-backend
flashinfer covers prefill as well as decode.

The arguments are forwarded by name: FlashInfer orders initial_states,
dt_softplus, dt_limit while MATE orders dt_softplus, dt_limit,
initial_states.
Both mamba_chunk_scan_combined_varlen call sites in MambaMixer2, the
autotune warmup and the prefill scan, now forward the configured backend
so the SSD route can select the FlashInfer implementation.
Guard the two series members: the backend keyword and the MUSA gate, the
by-name forwarding of the order-sensitive arguments, the absence of an
environment-variable switch, and the backend argument at both SSD call
sites.
@yeahdongcn
yeahdongcn marked this pull request as ready for review September 24, 2026 05:19
@yeahdongcn
yeahdongcn marked this pull request as draft September 28, 2026 09:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant