[XPU][DeepSeekV4] Add fused_kv_compress_norm_rope_insert_indexer_mxfp…#443
Open
nc-BobLee wants to merge 3 commits into
Open
[XPU][DeepSeekV4] Add fused_kv_compress_norm_rope_insert_indexer_mxfp…#443nc-BobLee wants to merge 3 commits into
nc-BobLee wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new XPU/SYCL fused attention-side kernel targeting DeepSeek-V4’s indexer MXFP4 path by combining KV compression (online softmax) + RMSNorm + RoPE + KV cache insert + MXFP4 quantization into a single launch, and wires it into the extension with accompanying tests and a benchmark.
Changes:
- Introduces
fused_kv_compress_norm_rope_insert_indexer_mxfp4_attnSYCL kernel implementation (including a small-CR specialization). - Registers/binds the new op in the XPU extension and integrates it into the build.
- Adds a byte-exact pytest accuracy test and a standalone benchmark script.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
csrc/xpu/sycl/fused_kv_compress_norm_rope_insert_indexer_mxfp4_attn.cpp |
New fused SYCL kernel implementation + dispatch for CR/overlap variants. |
csrc/xpu/torch_bindings.cpp |
Exposes the new op through the Torch library registration for XPU. |
csrc/xpu/ops.h |
Declares the new op in the public XPU ops header. |
CMakeLists.txt |
Adds the new SYCL source to the XPU-specific build list. |
tests/test_fused_kv_compress_norm_rope_insert_indexer_mxfp4_attn.py |
Adds accuracy coverage (byte-by-byte) across multiple compress ratios/configs. |
benchmark/benchmark_compress_insert_mxfp4.py |
Adds throughput benchmarking and optional correctness invocation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+507
to
+512
| q.submit([&](sycl::handler& cgh) { | ||
| cgh.parallel_for( | ||
| sycl::nd_range<2>({global0, (size_t)SMALL_SG_SIZE}, | ||
| {(size_t)SMALL_TOKENS_PER_WG, (size_t)SMALL_SG_SIZE}), | ||
| kernel); | ||
| }).wait(); |
Comment on lines
+904
to
+909
| q.submit([&](sycl::handler& cgh) { | ||
| cgh.parallel_for( | ||
| sycl::nd_range<2>({global0, (size_t)SG_SIZE}, | ||
| {(size_t)TOKENS_PER_WG, (size_t)SG_SIZE}), | ||
| kernel); | ||
| }).wait(); |
Comment on lines
+932
to
+943
| TORCH_CHECK(state_cache.is_xpu() && state_cache.dtype() == at::kBFloat16); | ||
| TORCH_CHECK(rms_norm_weight.is_xpu() && rms_norm_weight.dtype() == at::kBFloat16); | ||
| TORCH_CHECK(cos_sin_cache.is_xpu() && cos_sin_cache.dtype() == at::kFloat); | ||
| TORCH_CHECK(kv_cache.is_xpu() && kv_cache.dtype() == at::kByte); | ||
| TORCH_CHECK(head_dim == 128 && rope_head_dim == 64 && quant_block == 32); | ||
| // block2d loaders now handle arbitrary state_width via fallback path | ||
|
|
||
| const int num_tokens = static_cast<int>(positions.numel()); | ||
| if (num_tokens == 0) return; | ||
|
|
||
| auto& queue = c10::xpu::getCurrentXPUStream().queue(); | ||
|
|
Comment on lines
+171
to
+172
| // 16 was found to be the occupancy sweet spot on the target XPU (see sweep: | ||
| // it beats 8 and 32 across most token counts / compress ratios). |
| // ============================================================================ | ||
| // FusedMxfp4SmallKernel: Specialized kernel for small compress ratios (CR <= 8) | ||
| // Key optimizations: | ||
| // - Higher tokens per work-group (16 vs 8) for better EU occupancy |
Comment on lines
+100
to
+104
| # Compute effective bandwidth | ||
| # Read: num_tokens * n_gather * 2 * state_width * 2 bytes (kv+score, bf16) | ||
| # Write: num_tokens * (TOKEN_STRIDE + SCALE_DIM) bytes | ||
| read_bytes = num_tokens * n_gather * 2 * state_width * 2 | ||
| write_bytes = num_tokens * (TOKEN_STRIDE + SCALE_DIM) |
…4_attn SYCL kernel Add optimized SYCL kernel for DeepSeek-V4 fused KV compress + RMSNorm + RoPE + insert + indexer + MXFP4 quantization pipeline. Key features: - Fused pipeline: RMSNorm -> RoPE -> KV insert -> MXFP4 quantization - Optimized block2d loader with contiguous fast path - Supports compress ratios: 4, 8, 16, 32, 64, 128 - Uses sub-group (SIMD32) for efficient data movement Components: - SYCL kernel implementation - Op registration (ops.h + torch_bindings.cpp) - CMakeLists.txt integration - Pytest accuracy tests (7 configs) - Benchmark script (throughput measurement) Signed-off-by: nc-BobLee <bo.o.li@intel.com>
Signed-off-by: Bo <bo.o.li@intel.com>
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.
…4_attn SYCL kernel
Add optimized SYCL kernel for DeepSeek-V4 fused KV compress + RMSNorm + RoPE + insert + indexer + MXFP4 quantization pipeline.
Key features:
Components:
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS ABOVE HAVE BEEN CONSIDERED.
Purpose
Test Plan
Test Result
(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)