Skip to content

[XPU] Use SYCL kernels for DeepSeek V4 MHC on XPU - #32166

Merged
mingfeima merged 21 commits into
sgl-project:mainfrom
cyxlily:mhc
Aug 25, 2026
Merged

mingfeima merged 21 commits into
sgl-project:mainfrom
cyxlily:mhc

Conversation

@cyxlily

@cyxlily cyxlily commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Enable XPU-specific optimized kernels for the DeepSeek V4 MHC (Multi-Head Compression) path on Intel XPU hardware. The existing CUDA-path kernels (deep_gemm, CUDA-first device selection) are either unavailable or suboptimal on XPU, causing incorrect device dispatch or missing performance opportunities.

Modifications

deepseek_v4.py: On XPU, dispatch hc_head to sgl_kernel.mhc.fused_hc_head (SYCL kernel) instead of the Triton implementation; dispatch mhc_fused_post_pre to the XPU-specific kernel; fix device selection to avoid falling back to CUDA when XPU is available.

Accuracy Tests

Verified the accuracy of MHC kernels in sgl-kernel-xpu:

hc_head:
sgl-project/sgl-kernel-xpu#345

mhc_fused_post_pre:
sgl-project/sgl-kernel-xpu#302

All configurations pass accuracy tests.

Speed Tests and Profiling

Benchmarked fused_hc_head SYCL kernel vs Triton on Intel XPU (BMG), hc_mult=4, dtype=bfloat16 (median latency, 50 iterations):

Speedup (triton / sycl)

batch_size seq_len hidden_size dtype sycl_ms triton_ms speedup
1 1 4096 bfloat16 0.034528 0.103012 2.983
1 1 7168 bfloat16 0.057096 0.127816 2.239
1 64 4096 bfloat16 0.035568 0.06682 1.879
1 64 7168 bfloat16 0.05902 0.132236 2.241
1 256 4096 bfloat16 0.066092 0.085384 1.292
1 256 7168 bfloat16 0.111852 0.16276 1.455
1 1024 4096 bfloat16 0.204308 0.337064 1.65
1 1024 7168 bfloat16 0.367848 0.660764 1.796
4 1 4096 bfloat16 0.035048 0.063544 1.813
4 1 7168 bfloat16 0.058006 0.126516 2.181
4 64 4096 bfloat16 0.066144 0.085176 1.288
4 64 7168 bfloat16 0.112476 0.16276 1.447
4 256 4096 bfloat16 0.204308 0.336856 1.649
4 256 7168 bfloat16 0.3679 0.661232 1.797
4 1024 4096 bfloat16 0.736268 1.18173 1.605
4 1024 7168 bfloat16 1.30239 2.25446 1.731
64 1 4096 bfloat16 0.03562 0.066716 1.873
64 1 7168 bfloat16 0.059176 0.132132 2.233
64 64 4096 bfloat16 0.736398 1.18139 1.604
64 64 7168 bfloat16 1.30276 2.25108 1.728
64 256 4096 bfloat16 2.90222 4.89356 1.686
64 256 7168 bfloat16 5.11878 9.39708 1.836
64 1024 4096 bfloat16 11.6425 20.1541 1.731
64 1024 7168 bfloat16 20.3845 39.1621 1.921

CI States

Latest PR Test (Base): ❌ Run #32685541373
Latest PR Test (Extra): ❌ Run #32685541183
Latest PR Test (AMD ROCm 7.2): ❌ Run #32685541334

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cyxlily cyxlily closed this Jul 23, 2026
@cyxlily cyxlily reopened this Jul 23, 2026
Signed-off-by: Cui, Lily <lily.cui@intel.com>
@cyxlily cyxlily changed the title Use XPU mhc_fused_post_pre Use XPU mhc ops Jul 30, 2026
Signed-off-by: Cui, Lily <lily.cui@intel.com>
cyxlily added 3 commits July 31, 2026 19:25
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
@cyxlily

cyxlily commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Aug 4, 2026
@cyxlily

cyxlily commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci extra

@github-actions github-actions Bot added the run-ci-extra CI: also run the extra suite (requires run-ci) label Aug 4, 2026
@cyxlily cyxlily changed the title Use XPU mhc ops [XPU] Use SYCL kernels for DeepSeek V4 MHC on XPU Aug 4, 2026
@cyxlily

cyxlily commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@cyxlily

cyxlily commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

Comment thread python/sglang/srt/models/deepseek_v4.py Resolved
@polisettyvarma

Copy link
Copy Markdown
Contributor

@cyxlily please add intel and xpu labels also if you have permission

Signed-off-by: Cui, Lily <lily.cui@intel.com>
@mingfeima mingfeima added intel xpu intel gpu with device `torch.xpu` labels Aug 17, 2026
@cyxlily
cyxlily requested a review from HaiShaw as a code owner August 17, 2026 05:33

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

Don’t try/except + fall back to TileLang mhc_pre in python/sglang/kernels/ops/layernorm/mhc.py. That file is CUDA/TileLang-only.

Keep XPU dispatch in deepseek_v4.py: lazy-import from sgl_kernel inside _get_mhc_ops() / if _is_xpu: (same as hc_pre today) and fail if the op is missing.

Leave _prewarm_mhc_kernels returning early on XPU — no XPU prewarm in mhc.py.

Comment thread test/registered/xpu/test_hc_head.py Resolved
Comment thread test/registered/xpu/test_hc_head.py Resolved
Comment thread test/registered/xpu/test_hc_head.py Resolved
Comment thread test/registered/xpu/test_hc_head.py Resolved
Comment thread python/sglang/srt/models/deepseek_v4.py Resolved
Comment thread python/sglang/srt/models/deepseek_v4.py Resolved
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>

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

LGTM. some minors to fix.

Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
@mingfeima
mingfeima merged commit 1fa32d5 into sgl-project:main Aug 25, 2026
127 of 147 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek intel jit-kernel run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) xpu intel gpu with device `torch.xpu`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants