Skip to content

[XPU][DeepSeekV4] Add fused_kv_compress_norm_rope_insert_indexer_mxfp…#443

Open
nc-BobLee wants to merge 3 commits into
vllm-project:mainfrom
nc-BobLee:deepseek_dev
Open

[XPU][DeepSeekV4] Add fused_kv_compress_norm_rope_insert_indexer_mxfp…#443
nc-BobLee wants to merge 3 commits into
vllm-project:mainfrom
nc-BobLee:deepseek_dev

Conversation

@nc-BobLee

Copy link
Copy Markdown

…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)

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.

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)

Copilot AI review requested due to automatic review settings June 30, 2026 10:17

Copilot AI 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.

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_attn SYCL 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants