[Bugfix][Attention] Guard sparse MLA masked MHA workspace - #50906
MatthewBonanni merged 6 commits into
Conversation
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: yimdev <5779256+yimdev@users.noreply.github.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
MatthewBonanni
left a comment
There was a problem hiding this comment.
Made some tweaks, otherwise LGTM, thanks!
Thanks |
Purpose
Sparse MLA masked-MHA builds a bit-packed top-k mask whose size is approximately:
The existing workspace was fixed at 64 MiB, while the routing matrix allows a
single 32K prefill to enter masked-MHA. Such a request requires exactly 128 MiB.
Heterogeneous batches can require even more despite staying within
max_num_batched_tokens.Attempting to reshape the fixed workspace for an oversized mask can cause a CUDA
runtime error. Because CUDA execution is asynchronous, the API may have already
returned HTTP 200 before the worker reports the failure.
This PR:
supported single-request 32K boundary to continue using masked-MHA;
mask for the current prefill batch;
The workspace allocation increases by 64 MiB on workers where sparse masked-MHA
is available. Oversized batches do not trigger additional allocation.
Duplicate-work check
No open PR was found that addresses this masked-MHA top-k mask overflow.
Commands checked:
Related work is different in scope:
mask allocation.
Test Plan
Run the workspace sizing and adjacent chunk-splitting tests:
.venv/bin/python -m pytest \ tests/v1/attention/test_sparse_mla_backends.py \ -k 'masked_mha_workspace_fits or split_prefill_chunks' -qRun existing sparse prefill correctness coverage:
Run staged pre-commit hooks:
Hardware serving validation:
nvidia/DeepSeek-V3.2-NVFP4max_num_batched_tokens=32768Cases:
256 MiB batch mask.
[16384, 4096, 4096, 4096, 4095]behind a 32K blocker, forcing anapproximately 160 MiB masked-MHA candidate while the blocker remains active.
status.
Test Result
for the workspace and chunk-splitting tests.
for sparse prefill correctness, covering:
All staged pre-commit hooks passed.
Hardware serving results:
REGRESSION_OKThe final server state reported
Running: 0andWaiting: 0.No full model evaluation was run because this change does not alter attention
math for batches that fit. Oversized batches are redirected to the existing MQA
implementation instead of entering an invalid masked-MHA launch. Numerical
coverage is provided by the existing sparse prefill correctness tests, and
end-to-end output was validated on B300 hardware.
AI Assistance
OpenAI Codex was used.