Repository navigation
MUSA: route the Mamba2 SSD to FlashInfer for --mamba-backend flashinfer - #257
Draft
yeahdongcn wants to merge 3 commits into
Draft
yeahdongcn wants to merge 3 commits into
yeahdongcn wants to merge 3 commits into
Conversation
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
marked this pull request as ready for review
September 24, 2026 05:19
yeahdongcn
marked this pull request as draft
September 28, 2026 09:11
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MUSA: route the Mamba2 SSD (chunk scan) to FlashInfer when
--mamba-backend flashinferWhat this adds
Two build-time patch-series members that make
--mamba-backend flashinfercover the whole Mamba2path on MUSA, not just its decode half:
0170-MUSA-route-Mamba2-SSD-to-FlashInfer.patchvllm/model_executor/layers/mamba/ops/ssd_combined.pymamba_chunk_scan_combined_varlengains a trailingbackend=Noneparameter; on MUSA withbackend == "flashinfer"it forwards toflashinfer.mamba.ssd_combined.ssd_combined_fwd_varlen0171-MUSA-select-Mamba2-SSD-backend.patchvllm/model_executor/layers/mamba/mamba_mixer2.pybackend=self.mamba_config.backend.valueplus
tests/test_mamba_ssd_flashinfer_route_source.py, a CPU-only source-contract test in the style ofthe existing
tests/test_mamba_*_source.pyfiles. It pins the two things a reviewer cannot see byrunning 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_limitwhile the MATE implementation ordersdt_softplus, dt_limit, initial_states, and the names are identical in both, so a positional forward silently landsdt_limit's tuple where the kernel readsinitial_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 flashinferhas only ever changed theSSU. And where upstream does route a Mamba-family operator to FlashInfer, it is closed to non-CUDA
platforms on purpose:
_resolve_gdn_prefill_backendreturns(requested, "triton")as soon asnot current_platform.is_cuda(), then requires SM90 or SM10x withcuda_runtime >= 13. Followingupstream 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.pydoesfrom flashinfer.mamba import selective_state_update as _fi_ssuinside its__init__and calls the result. And MATE works here precisely because it is theflashinferpackagethat upstream imports.
Why does the mixer pass
backend? Because on CUDA there is exactly one SSD implementation, thequestion 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 inMambaMixer2.__init__). Upstream solves thesame 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_updateneeds noargument at all.
So there are two ways to wire the SSD, and this PR takes the stateless one:
backend=Noneplus 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.
ssu_dispatch- a newops/ssd_dispatch.pyholding an abstract backend plus Tritonand 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.pyis preferred. Note that (2) is the shapethe 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 callsflashinfer.mamba.ssd_combined.ssd_combined_fwd_varlen. In the MATE package the former is a true aliasof the latter (
mamba_chunk_scan_combined_varlen = ssd_combined_fwd_varlen), so the two names resolve tothe 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.pydefinesMambaSSUBackendwith a Triton and a FlashInfer implementation, selected byMambaBackendEnum, andmamba_mixer2.pygets itsselective_state_updatefrom that module by import. There is noequivalent for the SSD - no
ssd_dispatch.py- andmamba_mixer2.pycallsmamba_chunk_scan_combined_varlendirectly at both call sites, with no backend branch. So the flagchanges 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:--mamba-backend flashinfer, SSU and SSD routed (the state this PR produces)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
flashinferpackage:MooreThreads/mate, ready for review).flashinferadapter package that providesflashinfer.mamba.ssd_combined.ssd_combined_fwd_varlenand
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
flashinferfails loudly at thefirst 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
flashinferis importable in the environment, i.e. the package that ships withMATE.
Rollback
--mamba-backend tritonrestores the previous behaviour exactly. No environment variable isintroduced; the backend flag is the single switch.
Evidence and test plan
VLLM_COMMIT(
2cf0a6915ce544dc493a0990f2ea38d81601128a,VLLM_TAG=v0.28.0), the full 171-member series appliesthrough the build's own applier (
build_apply.py) with171 applied, 0 already-applied, 0 conflict,and an independent raw
git apply --recountloop over the same 171 members reportsapplied=171 failed=0. Both new members reverse-check (git apply --reverse --checkexit 0) on thefully patched tree, so the idempotent path in
build_apply.pysees them asalready-applied. Thetwo patched files are byte-identical across three independently built trees.
python -m pytest tests/test_mamba_ssd_flashinfer_route_source.py -q→
4 passed.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 inthe earlier revision of this description (a stale assertion about channel-wise
D, and a fixture that builtcu_seqlenson the CPU) are fixed on the branch. mate#5's adapter suite is green:11 passed.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 atd1aeba4, and these two members applied to the served tree withgit applyexactly 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 callsites carrying the backend (
calls=2 tagged=2).vllm servewith--mamba-backend flashinfer: six engine rounds, each starting a fresh server, allrc=0, one identical output hash across all six (ffbca8deab0cafa6), accepted length 4.18-4.53.old) / 1080.94 ms(
new) against 1079.57 / 1081.35 there; TPOT 7.7799 / 7.7862 against 7.7771 / 7.7834; kernel-level1.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.
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-FlashInferandMUSA-select-Mamba2-SSD-backendmembers). It deliberately does not carry:pin:chain that pointed the build at an external FlashInfer fork - the provider here is thepackage MATE ships;
MTP/graph-capture fixes and the MoE/top-k/setup changes bundled in that branch, which areindependent of this capability and have largely landed on
v0.28.0-devsince;--enable-mamba-cache-stochastic-roundingas supported on MUSA+FlashInfer, but the MATE SSU rejectsrand_seedat runtime, so enabling it would fail late instead of failing at config time. It shouldland 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 identicalconflict 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 alreadypatched tree fails loudly rather than mis-applying.
Also on this base, member
0014's hunk headers disagree with its own body (it needs--recount, whichbuild_apply.pyalways passes) and0163carries no mail header, so the series cannot be replayed withgit am. That is why these two members were produced with the generator's owngit format-patch --no-signature --no-numbered --zero-commitflags, header-for-header identical to theneighbouring members, instead of by re-running
make -f Makefile.sync format-patches. Flagged, notfixed: repairing legacy members is out of scope here.