Repository navigation
Conversation
6 tasks
jhaotingc
force-pushed
the
nano35-pr3-flashinfer
branch
from
October 15, 2026 17:59
8bcc805 to
3f5edc8
Compare
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
…laySSM rounding seed per step Add an opt-in FlashInfer SSD scan for Mamba2 prefills. Mamba2 prefills run the chunked SSD scan as five Triton launches per layer (cumsum, chunk state, state passing, bmm, chunk scan), and the initial states of continued prefills take a gather plus torch.where on top. FlashInfer's fused SSD (SSDCombined, Cake backend) runs the scan in two launches from the packed-varlen cu_seqlens, deriving its chunk metadata on the device. --mamba-prefill-backend flashinfer (MambaConfig.prefill_backend, a MambaBackendEnum parsed like --mamba-backend, default triton) selects it for prefills without Mamba checkpoints; prefills that store checkpoints need every chunk state and keep the Triton scan. mamba_chunk_scan_flashinfer() (ops/ssd_flashinfer.py): - gathers the initial states with gather_initial_states() (one launch, zero rows for sequences without a state) only when some sequence has one, and otherwise starts from zero state; - runs one SSDCombined runner per (stream, heads, groups, state dtype, initial states); the state dtype is the cache's, so final states come out in the cache dtype even without initial states; - writes each final state into its cache slot with scatter_states(). The prefill query_start_loc is Optional in the metadata; it is set whenever the step has prefills, and the FlashInfer call asserts it. _gather_initial_states_kernel and _scatter_states_kernel: the FlashInfer scan gathers initial states and scatters final states through state_indices_tensor_p, the block-table column that starts after the decode rows, so its alignment varies with the step's decode row count. Do not specialize indices_ptr on alignment, or mixed steps compile new variants while serving. FlashInfer takes D in the activation dtype, so the mixer keeps a bfloat16 copy of D that is refreshed when the parameter changes. The backend needs SM100/SM103, bfloat16 activations, head dim 64 and state size 128 (the shapes FlashInfer compiles); MambaConfig and MambaMixer2 reject other setups. The SSD warmup also runs both FlashInfer variants. On a B200 host (Nano35 TP1 shapes, 1069-token prefill, fp16 state cache) one scan takes 97 us of host time instead of 174 us (125 vs 214 us with initial states); GPU time is 54 vs 46 us without initial states and 56 vs 92 us with them. Seed ReplaySSM stochastic rounding once per step. With --enable-mamba-cache-stochastic-rounding, every FlashInfer ReplaySSM layer drew its Philox seed with its own torch.randint launch, 23 launches per step on Nano35. In a mixed prefill+decode step these run eagerly, each behind its own host-side launch overhead; in decode steps they are 23 extra kernels in the FULL graph. share_replayssm_ring_trackers() now gives each such layer a one-element slot of a shared int64 buffer, and the first layer refreshes the whole buffer with a single random_() launch per step. The FlashInfer kernel reads the seed through its pointer, so each layer still gets an independent seed every step. selective_state_update_replayssm_flashinfer() takes the seed as rand_seed and falls back to drawing one when none is given. test_replayssm_mixer_selects_mtp_layout builds the mixer with __new__, so it sets the two new attributes to None (no shared seed buffer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jhao-Ting Chen <jhaotingc@nvidia.com>
jhaotingc
force-pushed
the
nano35-pr3-flashinfer
branch
from
October 21, 2026 00:14
3f5edc8 to
4e9b35c
Compare
This was referenced Oct 21, 2026
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.
Overview
Adds an opt-in FlashInfer fused SSD scan for Mamba2 prefills (
--mamba-prefill-backend flashinfer)and draws the ReplaySSM stochastic-rounding seed once per step instead of once per layer. This PR is
part of a series that brings piecewise CUDA graphs to Mamba2 prefill steps, and it is stacked on
#61497. Tested with #61293 applied, but it does not depend on it. Requires a FlashInfer build with
flashinfer-ai/flashinfer#6100, which is not in a release yet.
Claims
Nemotron-3.5-Lightning-NVFP4-W4A4 and MTP=2: 1.06-1.11x at concurrency 8-32, 1.05-1.06x at 64-128
and 1.03x at 1-4.
us to 97 us (214 us to 125 us for continued prefills with initial states).
mixed steps and the decode CUDA graph.
Validation
End-to-end serving throughput, before vs after, on the same node, served back-to-back with identical
flags except the new one:
main+ [MoE] Shape-based padding for FlashInfer TRT-LLM MXFP8 experts (gated and non-gated) #61293 + [Perf][Mamba] Reduce host overhead in the Mamba2 Triton SSD prefill path #61497. After: the same, plus this PR, with--mamba-prefill-backend flashinfer.2a2cceab0, which includes feat(cake_ssd_combined): <128-token calls, seq_idx guard, grouped epilogue loads, any chunk_size via cu_seqlens (SM100 / SM103) flashinfer-ai/flashinfer#6100(
cu_seqlenssupport) and perf(cake_ssd_combined): preprocess, exact-scan and chunk-parallel prefill improvements (SM100 / SM103) flashinfer-ai/flashinfer#6206 (Cake SSD prefill performance).throughput_1k,low_entropycategory (512 prompts),max_tokens200, served through aiperf.Values are OTPS/gpu (output tokens/s per GPU):
Mid concurrencies have the most prefill and mixed-batch interruptions, so they gain the most; the
effect is smaller at low and high concurrency.
Accuracy: GPQA-diamond through NeMo Gym on 1x GB300, TP1, MTP=2 (198 questions x 8 repeats, thinking on,
temperature 1.0, top_p 0.95), with the serve command below plus
--max-model-len 262144 --reasoning-parser nemotron_v3. pass@1, mean over the 8 repeats ± standard error:--enable-prefix-caching --mamba-cache-mode align, no ReplaySSM): 76.58 ± 0.93%Serve and client commands
--mamba-prefill-backend flashinferselects this PR's scan for prefills;--mamba-backend flashinferonly selects the decode state update. The Before run used the same command without--mamba-prefill-backend.Client, run once per concurrency level:
Details
Mamba2 prefills run the chunked SSD scan as 5 Triton launches per layer (cumsum, chunk state, state
passing, bmm, chunk scan). Continued prefills add a gather and a
torch.wherefor their initialstates. In eager prefill and mixed steps, these launches and their host overhead add directly to
step latency. FlashInfer's fused SSD (
SSDCombined, Cake backend) runs the scan in 2 launches fromthe packed-varlen
cu_seqlensand derives its chunk metadata on the device.Changes:
--mamba-prefill-backend {triton,flashinfer}(MambaConfig.prefill_backend, defaulttriton).Prefills that store Mamba checkpoints need every chunk state, so they keep the Triton scan.
mamba_chunk_scan_flashinfer()(ops/ssd_flashinfer.py):a zero state;
SSDCombinedrunner per (stream, heads, groups, state dtype, initial states), so finalstates come out in the cache dtype;
indices_ptron alignment. Its alignment changeswith the number of decode rows, so this avoids new compiles while serving.
Dfor FlashInfer, refreshed when the parameter changes.FlashInfer compiles).
MambaConfigandMambaMixer2reject other setups, and the SSD warm-up runsboth FlashInfer variants.
--enable-mamba-cache-stochastic-rounding, each FlashInfer ReplaySSM layerdrew its Philox seed with its own
torch.randint. The layers now read their seeds from slots ofone shared buffer, which the first layer refreshes with a single
random_()per step. Every layerstill gets an independent seed each step.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.