Skip to content

[2/N][Attention] Enable masked MHA for sparse MLA prefills - #48770

Merged
vllm-bot merged 28 commits into
vllm-project:mainfrom
MatthewBonanni:fa4_masked_mha_remainder
Jul 31, 2026
Merged

[2/N][Attention] Enable masked MHA for sparse MLA prefills#48770
vllm-bot merged 28 commits into
vllm-project:mainfrom
MatthewBonanni:fa4_masked_mha_remainder

Conversation

@MatthewBonanni

@MatthewBonanni MatthewBonanni commented Jul 15, 2026

Copy link
Copy Markdown
Member

Depends on vllm-project/flash-attention#155

Purpose

For pure prefills, there is a threshold of sequence length below which a masked MHA pathway is faster than sparse MQA. The DeepSeek V3.2 paper mentions this:

Note that for short-sequence prefilling, we specially implement a masked MHA mode to
simulate DSA, which can achieve higher efficiency under short-context conditions.

#47327 implemented a dense MHA shortcut for when seq_len < topk. This PR extends that optimization by implementing the masked MHA pathway.

Test Plan

Test Result

mha_vs_mqa_dp_heads128 mha_vs_mqa_tp8_heads16 speedup_heatmap_tp1_tp2_tp4_tp8
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.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Build on the dense-MHA shortcut from vllm-project#47327 and route eligible pure prefills through FA4 masked attention.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify

mergify Bot commented Jul 16, 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, @MatthewBonanni.

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 16, 2026
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Jul 16, 2026
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify

mergify Bot commented Jul 16, 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, @MatthewBonanni.

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 16, 2026
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Jul 17, 2026
@MatthewBonanni
MatthewBonanni marked this pull request as ready for review July 17, 2026 16:30

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

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify

mergify Bot commented Jul 22, 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, @MatthewBonanni.

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 22, 2026
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Jul 23, 2026

@LucasWilkinson LucasWilkinson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall looks pretty good to me; left some comments for cleanup/simplification

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Jul 28, 2026
@MatthewBonanni MatthewBonanni added ready ONLY add when PR is ready to merge/full CI is needed needs-rebase labels Jul 29, 2026
@mergify mergify Bot removed the needs-rebase label Jul 29, 2026
@MatthewBonanni MatthewBonanni changed the title [2/N][Attention] Enable masked MHA for sparse MLA prefills [Do Not Merge][2/N][Attention] Enable masked MHA for sparse MLA prefills Jul 29, 2026
@MatthewBonanni

Copy link
Copy Markdown
Member Author

Marking as [Do Not Merge] because we still need to land FA once CI is green

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@MatthewBonanni
MatthewBonanni enabled auto-merge (squash) July 30, 2026 13:57
@MatthewBonanni MatthewBonanni changed the title [Do Not Merge][2/N][Attention] Enable masked MHA for sparse MLA prefills [2/N][Attention] Enable masked MHA for sparse MLA prefills Jul 30, 2026
@vllm-bot
vllm-bot merged commit 82ae416 into vllm-project:main Jul 31, 2026
247 of 249 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build performance Performance-related issues 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.

4 participants