Skip to content

[v1] - Mamba1 Attention Metadata - #21249

Merged
simon-mo merged 44 commits into
vllm-project:mainfrom
Josephasafg:main
Aug 7, 2025
Merged

simon-mo merged 44 commits into
vllm-project:mainfrom
Josephasafg:main

Conversation

@Josephasafg

@Josephasafg Josephasafg commented Jul 20, 2025 •

Copy link
Copy Markdown
Contributor

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

Add full v1-style attention-metadata support to Mamba-1 models. The following was added

  1. Mamba1AttentionMetadataBuilder to create the attention metadata for mamba-1 models
  2. MambaStateShapeCalculator aggregated mamba state shape calculation logic for all mamba models under the same static class for better readability and navigation
  3. Updated selective_scan_fwd to support V1 memory layout

Test Plan

Updated the following tests -
test_hybrid.py - Now tests Mamba1 and Jamba in V1
test_oracle.py - Removed Mamba1 from unsupported V1 model
Running all tests in test_hybrid.py, test_oracle.py and test_mamba_ssm.py (due to kernel change) pass.

Running mamba1 in main branch would raise an error

lm_eval results with state-spaces/mamba-130m-hf

vLLM V0 with Mamba1

VLLM_USE_V1=0 HF_ALLOW_CODE_EVAL=1  lm_eval --model vllm \
    --model_args pretrained=state-spaces/mamba-130m-hf,enforce_eager=True,enable_prefix_caching=False,tensor_parallel_size=1 \
    --tasks humaneval \
    --batch_size auto \
    --confirm_run_unsafe_code
|  Tasks  |Version|  Filter   |n-shot|Metric|   |Value |   |Stderr|
|---------|------:|-----------|-----:|------|---|-----:|---|-----:|
|humaneval|      1|create_test|     0|pass@1|   |0.0244|±  |0.0121|

vLLM V1 with Mamba1

VLLM_USE_V1=1 HF_ALLOW_CODE_EVAL=1  lm_eval --model vllm \
    --model_args pretrained=state-spaces/mamba-130m-hf,enable_prefix_caching=False,tensor_parallel_size=1 \
    --tasks humaneval \
    --batch_size auto \
    --confirm_run_unsafe_code
|  Tasks  |Version|  Filter   |n-shot|Metric|   |Value |   |Stderr|
|---------|------:|-----------|-----:|------|---|-----:|---|-----:|
|humaneval|      1|create_test|     0|pass@1|   |0.0244|±  |0.0121|

This PR now enables this vLLM V1 to work with models that use Mamba1 like Mamba1 and Jamba

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify Bot added the v1 label Jul 20, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces v1-style attention metadata support for Mamba-1 models and refactors the Mamba state shape calculation into a centralized MambaStateShapeCalculator class. The refactoring improves code organization and maintainability. The v1 support is well-integrated, with clear logic separation based on the VLLM_USE_V1 environment variable.

@heheda12345 heheda12345 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the great job.

Some questions:

  1. Do we need enforce-eager to run mamba1? I'm OK with supporting cuda graph in a future PR.
  2. Can you show some lm-eval result on mamba1 model?
  3. Please update tests/models/language/generation/test_hybrid.py and tests/v1/test_oracle.py
  4. Is Jamba supported now?
  5. Please update the doc like https://docs.vllm.ai/en/latest/usage/v1_guide.html#mamba-models and https://docs.vllm.ai/en/latest/usage/v1_guide.html#mamba-models

Comment thread vllm/v1/kv_cache_interface.py Resolved
Comment thread vllm/v1/worker/gpu_model_runner.py Resolved
Comment thread vllm/v1/worker/gpu_model_runner.py Resolved
@mergify

mergify Bot commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

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

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

Comment thread vllm/attention/mamba_selectors.py Resolved
Comment thread vllm/model_executor/models/mamba.py Resolved
Comment on lines 29 to 38

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How different is the Mamba1AttentionMetdata to the Mamba2AttentionMetadata? Do we really need two separate classes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question. I think we should keep both since Mamba2AttentionMetadata contains fields that aren't relevant for mamba1 like chunk_indices, chunk_offsets and triton kernels related fields that mamba1 doesn't need which would add overhead to the class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I prefer to keep mamba1 and mamba2 as seperate metadata classes. Comparing with one metadata class with many optional entry and branches for different types of layers, I prefer this pluggable design. We can extract common logic to a parent class if we find some after more models like minimax are added. @tdoublep WDYT?

@tdoublep tdoublep Aug 6, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@heheda12345 Sorry I missed this question. Yes I agree let's keep the metadata classes separate and then factor the common things into a CommonMambaAttentionMetadata or something once it is clear what is truly common. This one is ready and we have the LFM2 and MiniMax-Text ones nearly there too, so we should be able to look at that soon.

Comment thread vllm/v1/worker/gpu_model_runner.py Resolved
Comment on lines 29 to 38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I prefer to keep mamba1 and mamba2 as seperate metadata classes. Comparing with one metadata class with many optional entry and branches for different types of layers, I prefer this pluggable design. We can extract common logic to a parent class if we find some after more models like minimax are added. @tdoublep WDYT?

Comment thread vllm/v1/worker/gpu_model_runner.py Resolved
@mergify

mergify Bot commented Jul 26, 2025

Copy link
Copy Markdown
Contributor

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

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 Jul 26, 2025
@mergify mergify Bot removed the needs-rebase label Jul 26, 2025
@heheda12345 heheda12345 mentioned this pull request Jul 27, 2025
4 tasks done
@mergify

mergify Bot commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

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

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 Jul 29, 2025
Signed-off-by: asafg <asafg@ai21.com>
@tlrmchlsmth

Copy link
Copy Markdown
Member

PR looks good. Thanks for adding Jamba and Mamba1 to V1!

@tlrmchlsmth tlrmchlsmth added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 6, 2025
@tlrmchlsmth
tlrmchlsmth enabled auto-merge (squash) August 6, 2025 15:17
@tdoublep

tdoublep commented Aug 6, 2025

Copy link
Copy Markdown
Member

V1 test failure is known flaky test (see #22385), and the quantization test and blackwell tests look unrelated. This one is good to merge imo.

@simon-mo
simon-mo disabled auto-merge August 7, 2025 00:03
@simon-mo
simon-mo merged commit 46a1394 into vllm-project:main Aug 7, 2025
jinzhen-lin pushed a commit to jinzhen-lin/vllm that referenced this pull request Aug 9, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
Signed-off-by: Jinzhen Lin <linjinzhen@hotmail.com>
noamgat pushed a commit to noamgat/vllm that referenced this pull request Aug 9, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
Signed-off-by: Noam Gat <noamgat@gmail.com>
wuhang2014 pushed a commit to wuhang2014/vllm that referenced this pull request Aug 12, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
paulpak58 pushed a commit to paulpak58/vllm that referenced this pull request Aug 13, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
Signed-off-by: Diego-Castan <diego.castan@ibm.com>
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
Signed-off-by: Xiao Yu <xiao.yu@amd.com>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
my-other-github-account pushed a commit to my-other-github-account/vllm that referenced this pull request May 15, 2026
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
0826joyce pushed a commit to 0826joyce/vllm-serving-optimization that referenced this pull request May 19, 2026
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
philippesic pushed a commit to philippesic/vllm-semantic-cache that referenced this pull request Jul 19, 2026
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
plasticchris pushed a commit to plasticchris/vllm that referenced this pull request Jul 20, 2026
Signed-off-by: asafg <asafg@ai21.com>
Co-authored-by: asafg <asafg@ai21.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants