Skip to content

[Feature][Mamba] Batched two-phase grouped prefill execution for hybrid GDN/Mamba (+7.58x) - #55876

Open
nicholaskh-ai wants to merge 4 commits into
vllm-project:mainfrom
nicholaskh-ai:feat/mamba-grouped-prefill-batched-kernel
Open

nicholaskh-ai wants to merge 4 commits into
vllm-project:mainfrom
nicholaskh-ai:feat/mamba-grouped-prefill-batched-kernel

Conversation

@nicholaskh-ai

@nicholaskh-ai nicholaskh-ai commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Purpose

Implements RFC #55697.

Part 3 of 3 for Application-Directed Mamba Prefix Checkpointing (depends on PR #55873 and PR #55875).

In hybrid GDN/Mamba models (such as Qwen3.5 35B-A3B), prefill batches containing shared prefixes (1 common Producer prompt + N distinct Consumer queries) previously required either sequential per-request execution or full prompt recomputation due to state recurrence.

This PR introduces batched two-phase grouped prefill execution in the worker and GDN layer:

  • Two-Phase Kernel Execution: Splits the grouped prefill forward into batched Producer and Consumer phases. In Phase 1, all Producers run in a single packed kernel invocation and populate shared checkpoint state rows. In Phase 2, Consumers read the shared checkpoint rows (index_select), copy them to private destination slots (index_copy_), and compute suffixes concurrently in a second packed kernel invocation.
  • Attention Metadata Builder: Automatically constructs prefix_producer_ranges, consumer_ranges, consumer_shared_state_sources, and private_final_state_destination to dispatch requests into packed phases.
  • Microbenchmark & Unit Tests: Validates numerical equivalence against the sequential baseline and provides a reproducible benchmark demonstrating up to 7.58x speedup.

Microbenchmark Results (NVIDIA L40S, PyTorch 2.11.0+cu130)

Measured on an NVIDIA L40S GPU using benchmarks/kernels/benchmark_grouped_gdn_prefill.py:

Workload (Producers, Consumers) Tokens Legacy Serial (us) Batched Phased (us) Speedup P10 ~ P90 (us)
1P + 1C (single candidate) 576 2,146.41 1,548.13 1.39x 1,534 ~ 1,562
1P + 2C 640 2,876.00 1,546.33 1.86x 1,532 ~ 1,569
1P + 4C 768 4,245.61 1,545.72 2.75x 1,532 ~ 1,565
1P + 8C (typical batch) 1,024 7,055.63 1,582.38 4.46x 1,569 ~ 1,594
1P + 16C (wide candidate batch) 1,536 12,698.95 1,674.81 7.58x 1,660 ~ 1,716

Performance Highlights:

  • Near-Flat Latency ($O(N) \to O(1)$): As consumers increase from 1 to 16, latency only increases from 1.54ms to 1.67ms (+8.4%), whereas serial execution scales linearly up to 12.7ms.
  • Substantial Throughput Gains: At 16 consumers, latency drops by 86.8%, yielding a 7.58x speedup.

Duplicate-work Check

Test Plan

  • Kernel split equivalence test:
    pytest tests/kernels/mamba/test_gdn_forward_core_split.py -v
  • Metadata builder test:
    pytest tests/v1/attention/test_gdn_metadata_builder.py -k "test_grouped_metadata" -v
  • CPU GDN ops alignment test:
    pytest tests/kernels/mamba/cpu/test_cpu_gdn_ops.py -v
  • Benchmark verification:
    python -m benchmarks.kernels.benchmark_grouped_gdn_prefill --num-producers 1 --num-consumers 1 2 4 8 16

AI assistance was used to prepare this change. The human submitter is responsible for reviewing the changed code and test results.

Generated with Devin

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: nizhang1 nizhang1@coupang.com

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added performance Performance-related issues cpu Related to CPU backends scheduler kv-cache-manager labels Sep 8, 2026
@mergify

mergify Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @nicholaskh-ai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify

mergify Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @nicholaskh-ai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@nicholaskh-ai

Copy link
Copy Markdown
Contributor Author

CC @mgoin @jeejeelee

Hi reviewers, this is Part 3 of the implementation stack for RFC #55697. It implements the batched two-phase grouped prefill execution in the GDN layer, cutting kernel launch overhead and delivering up to 7.58x speedup on NVIDIA L40S.

Whenever you have a moment, we would love your review and feedback. Thanks!

@nicholaskh-ai
nicholaskh-ai force-pushed the feat/mamba-grouped-prefill-batched-kernel branch from 35ba5d9 to 9b0301e Compare September 9, 2026 12:24
@mergify

mergify Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @nicholaskh-ai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Sep 9, 2026
@nicholaskh-ai
nicholaskh-ai force-pushed the feat/mamba-grouped-prefill-batched-kernel branch from 9b0301e to 2f53460 Compare September 9, 2026 12:47
@mergify mergify Bot removed the needs-rebase label Sep 9, 2026
@nicholaskh-ai
nicholaskh-ai force-pushed the feat/mamba-grouped-prefill-batched-kernel branch 2 times, most recently from b85dd45 to 24bff32 Compare September 9, 2026 16:10
@mergify

mergify Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @nicholaskh-ai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

nizhang1 added 2 commits September 10, 2026 13:45
…rker and input processing

- Add --enable-mamba-checkpoint and --mamba-checkpoint-token CLI & engine options
- Register <|mamba_checkpoint|> token into tokenizer dynamically in HF renderer
- Parse and strip mamba checkpoint token in InputProcessor with offset adjustments
- Add unit tests for HF renderer and InputProcessor token extraction

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: nizhang1 <nizhang1@coupang.com>
…1 scheduler

- Truncate Producer prefill chunks at mamba checkpoint boundary
- Support same-step Producer/Consumer pairing and prefix block inheritance
- Implement unready checkpoint locking in BlockPool and deferral in scheduler
- Add ready state wakeup on step completion
- Add unit tests for scheduler checkpoint coordination and chunk splitting

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: nizhang1 <nizhang1@coupang.com>
@nicholaskh-ai
nicholaskh-ai force-pushed the feat/mamba-grouped-prefill-batched-kernel branch from a25a2fa to c6463cd Compare September 10, 2026 05:53
…DN/Mamba

- Implement batched producer and consumer phases in GDN attention layer
- Add grouped prefill metadata builder packing prefix ranges and state destinations
- Add native MRv2 (ModelRunnerV2) and MRv1 compatibility for grouped checkpoint metadata
- Add graceful fallback for mixed batches and add MRv2 MambaHybridModelState unit tests
- Add kernel split verification tests and benchmark demonstrating up to 7.6x speedup

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: nizhang1 <nizhang1@coupang.com>
@nicholaskh-ai
nicholaskh-ai force-pushed the feat/mamba-grouped-prefill-batched-kernel branch from c6463cd to e9d21b1 Compare September 10, 2026 09:57
@mergify mergify Bot removed the needs-rebase label Sep 10, 2026
@mergify

mergify Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @nicholaskh-ai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Sep 10, 2026
KonnyakuMatcha added a commit to KonnyakuMatcha/vllm-HOT that referenced this pull request Sep 14, 2026
Document the exact single-session HOT design, relationship to existing
Mamba prefix-cache work (vllm-project#55697/vllm-project#55873/vllm-project#55875/vllm-project#55876, vllm-project#52959, vllm-project#45702),
TTFT evaluation, correctness status, and async-scheduling limitations.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: KonnyakuLC <1690982212@qq.com>
Signed-off-by: nicholaskh-ai <15652918035@163.com>
@mergify mergify Bot removed the needs-rebase label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpu Related to CPU backends kv-cache-manager mrv2 Model Runner V2 specific performance Performance-related issues scheduler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant