Add Sparse MLA prefill/decode kernel#433
Open
wuxun-zhang wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Sparse MLA (DeepSeek V4–style) sparse attention support to the XPU FA2 extension, including configurable kernel generation, Python entrypoints, and correctness tests.
Changes:
- Introduces Sparse MLA prefill and FP8 decode kernels + runtime dispatch/registration in the FA2 extension.
- Adds build/config plumbing for sparse MLA kernel selection (
SPARSE_MLA_KERNELS_ENABLED,VLLM_SPARSE_MLA_CONFIG) and new preset config files. - Adds correctness tests for sparse MLA prefill and sparse FP8 decode, plus documentation updates for configuration.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| vllm_xpu_kernels/flash_mla_interface.py | Python interface wrappers for sparse MLA prefill + FP8 decode ops. |
| tests/flash_mla/test_mla_sparse_prefill.py | Correctness test for sparse MLA prefill (compares to reference). |
| tests/flash_mla/test_mla_sparse_decode_fp8.py | Correctness test for sparse MLA FP8 decode (compares to reference). |
| setup.py | Enables building _vllm_fa2_C when sparse MLA kernels are enabled; forwards sparse MLA config env var. |
| KERNEL_CONFIGURATION.md | Documents sparse MLA kernel category, configs, presets, and troubleshooting. |
| csrc/xpu/attn/mla/utils.hpp | Adds MLA-specific utilities/macros used by sparse kernels. |
| csrc/xpu/attn/mla/sparse_mla_prefill_kernel_template.cpp.in | Template for generated prefill instantiation units. |
| csrc/xpu/attn/mla/sparse_mla_prefill_fwd.hpp | Sparse MLA prefill kernel implementation + gather kernel. |
| csrc/xpu/attn/mla/sparse_mla_fwd.cpp | Torch/XPU-facing implementations for sparse MLA prefill + decode. |
| csrc/xpu/attn/mla/sparse_mla_decode_fp8_kernel_template.cpp.in | Template for generated FP8 decode instantiation units. |
| csrc/xpu/attn/mla/sparse_mla_decode_fp8_fwd.hpp | Sparse MLA FP8 decode implementation + gather/dequant kernel. |
| csrc/xpu/attn/mla/sparse_mla_configure.cmake | Parses sparse MLA config and generates instantiation sources/defines. |
| csrc/xpu/attn/mla/flash.h | Adds shared structs/constants for sparse MLA kernels. |
| csrc/xpu/attn/kernel_configs/sparse_mla_full.conf | “all” preset for building all sparse MLA variants. |
| csrc/xpu/attn/kernel_configs/sparse_mla_default.conf | Default sparse MLA preset targeting DeepSeek V4 (2 variants). |
| csrc/xpu/attn/kernel_configs/README.md | Lists sparse MLA config presets (counts/usage). |
| csrc/xpu/attn/attn_interface.h | Declares sparse MLA C++ interfaces exposed to registration. |
| csrc/xpu/attn/attn_interface.cpp | Implements sparse MLA interface forwarding to MLA implementations. |
| csrc/flash_attn/flash_api.cpp | Registers new torch.ops for sparse MLA prefill/decode. |
| CMakeLists.txt | Adds SPARSE_MLA_KERNELS_ENABLED and integrates sparse MLA generation/build into FA2 extension. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
118
to
+122
| | Model Family | head_size | Chunk Prefill | Paged Decode | | ||
| |--------------|-----------|---------------|--------------| | ||
| | Llama-2/3, Qwen, Mistral | 128 | `default` | `default` | | ||
| | DeepSeek-V2/V3/R1 (MLA) | 192 | `default` | `default` | | ||
| | Gemma-2 | 256 | `full` | `full` | | ||
| | Gemma-2 | 256 | `full` | `full` | n/a | |
jikunshang
reviewed
Jun 25, 2026
jikunshang
reviewed
Jun 25, 2026
wuxun-zhang
force-pushed
the
wuxun/sparse-mla
branch
from
June 25, 2026 05:55
7004f50 to
407283d
Compare
Contributor
Author
|
@xinyu-intel @pengzhao-intel please help review, thanks |
xinyu-intel
approved these changes
Jun 25, 2026
Signed-off-by: Zhang, Wuxun <wuxun.zhang@intel.com>
Signed-off-by: Zhang, Wuxun <wuxun.zhang@intel.com>
jikunshang
reviewed
Jul 1, 2026
jikunshang
left a comment
Member
There was a problem hiding this comment.
no much comments for kernels part.
one open is: will we add flash mla (not sparse one)in the future?
| #ifdef VLLM_XPU_ENABLE_XE2 | ||
| #include "csrc/xpu/attn/xe_2/fmha_xe2.h" | ||
| #include "csrc/xpu/attn/xe_2/paged_decode_xe2.h" | ||
| #ifdef VLLM_FA2_ATTN_ENABLED |
Member
There was a problem hiding this comment.
I feel we will always build FA2? better revert this part.
| } | ||
|
|
||
| // | ||
| // Convert int64_t stride to int32_t, with overflow check. |
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.
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.Purpose
This is to support DeepSeek V4 model running.
flash_mla_interface.pyTest Plan
python -m pytest tests/flash_mla/test_mla_sparse_prefill.py -v
python -m pytest tests/flash_mla/test_mla_sparse_decode_fp8.py -v
Test Result
all passed
(Optional) Documentation Update
BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)