Skip to content

[XPU] Use a fused GDN kernel from sgl-kernel for Qwen3.5 - #33354

Merged
mingfeima merged 29 commits into
sgl-project:mainfrom
Xia-Weiwen:qwen3.5_gdn_xpu_kernel
Aug 24, 2026
Merged

mingfeima merged 29 commits into
sgl-project:mainfrom
Xia-Weiwen:qwen3.5_gdn_xpu_kernel

Conversation

@Xia-Weiwen

@Xia-Weiwen Xia-Weiwen commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Motivation

To use a fused GDN kernel provided by sgl-kernel-xpu for better performance than what the existing triton kernels in SGLang produce.

Modifications

  • Added a subclass of GDNAttnBackend for XPU, which does some checks and calls the fused GDN kernel.
  • Added a simple dispatch mechanism for the fused GDN kernel on XPU with existing paths unchanged.

Accuracy Tests

Qwen3.5-9B, GSM8K, 200 samples

Fused GDN kernel from sgl-kernel-xpu

  • Accuracy: 0.910
  • Invalid: 0.000

Triton GDN in SGLang

  • Accuracy: 0.900
  • Invalid: 0.000

Speed Tests and Profiling

Qwen3.5-9B on a Intel Arc BMG60 machine

python -I -m sglang.bench_one_batch --batch-size 1 --input 4096 --output 1024 --model Qwen/Qwen3.5-9B --tp 1 --device xpu --mem-fraction-static 0.9 --attention-backend intel_xpu --linear-attn-backend intel_xpu --disable-radix-cache --profile --profile-stage all --profile-activities CPU XPU --chunked-prefill-size -1 --max-prefill-tokens 20480 --max-total-tokens 20480
Latency Old New
Prefill E2E 0.937 s 0.808 s
Prefill GDN 165 ms 59.17 ms
Decode E2E 0.0404 s 0.0402 ms
Decode GDN 0.522 ms 0.452 ms

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #32383609683
Latest PR Test (Extra): ⏳ Run #32688872423
Latest PR Test (AMD ROCm 7.2): ❌ Run #32383610036

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

Comment thread python/sglang/srt/layers/rotary_embedding/mrope.py Outdated
@Xia-Weiwen
Xia-Weiwen marked this pull request as ready for review August 4, 2026 05:43
@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.

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci label Aug 4, 2026
@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

Hi @mingfeima @airMeng Can you please review? Thanks.

Comment thread python/sglang/srt/models/qwen3_5.py Outdated
Comment on lines +640 to +647
core_attn_out = z = None
from sglang.srt.model_executor.forward_context import get_attn_backend

backend = get_attn_backend()
backend = getattr(backend, "linear_attn_backend", backend)
if hasattr(backend, "forward_fused_gdn") and backend.supports_fused_gdn(
self.attn, forward_batch
):

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.

doing such a backend chosen in a forward seems not appropriate.

how does the original code choose the backend? when it is settled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original path does not use a fused kernel (CUDA, CPU, etc.). So, they just go to the else branch. We need to intercept here because we call a fused kernel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Now we use a separate _forward_xpu.

@airMeng airMeng mentioned this pull request Aug 18, 2026
5 tasks
Comment thread python/sglang/srt/models/qwen3_5.py
@Xia-Weiwen
Xia-Weiwen requested a review from mingfeima August 19, 2026 01:36

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

some minor issues to address.

Comment thread test/registered/xpu/llm_models/test_xpu_qwen3_5_9b.py Outdated
Comment thread python/sglang/srt/layers/rotary_embedding/mrope.py Outdated
Comment thread python/sglang/srt/models/qwen3_5.py Outdated
Comment thread python/sglang/srt/models/qwen3_5.py Outdated
Comment thread python/sglang/srt/models/qwen3_5.py Outdated
Comment thread python/sglang/srt/models/qwen3_5.py Outdated
@mingfeima

Copy link
Copy Markdown
Collaborator

@Xia-Weiwen could you please check with validation team why xpu ci failed again?

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

@Xia-Weiwen could you please check with validation team why xpu ci failed again?

CI should be good now.

@mingfeima
mingfeima merged commit 5b5b29d into sgl-project:main Aug 24, 2026
137 of 150 checks passed
@mingfeima mingfeima added intel xpu intel gpu with device `torch.xpu` labels Aug 24, 2026
longxin9715 added a commit to longxin9715/sglang that referenced this pull request Aug 24, 2026
…n-transport1

* 'main' of https://github.com/sgl-project/sglang: (326 commits)
  [diffusion] feat: cache LoRA-merged weights in files the page cache can hold (sgl-project#36062)
  [diffusion] Speed up LingBot high-quality VAE decode (sgl-project#36024)
  [diffusion] Honor XDG cache for model overlays (sgl-project#36019)
  Support streaming session on NPU (sgl-project#32597)
  fix(xpu): read enable_deterministic_inference from the config bag (sgl-project#36149)
  xeon ci fail fast strategy change (sgl-project#36146)
  [diffusion] Fix Hunyuan QKV pack indexing at production video shapes (sgl-project#36009)
  [diffusion] Refresh quality and BCG benchmark skills (sgl-project#36016)
  [MoE] Gather the cutlass MoE activation and its scales in one launch (sgl-project#34915)
  [diffusion] feat: add plain component weight overrides (sgl-project#36086)
  [diffusion] feat: support loading mixed w4a8 text encoders (sgl-project#36037)
  [diffusion] Default Hunyuan VAE to tiled decode (sgl-project#36012)
  fix(xpu): enable compressed-tensors FP8 W8A8 on XPU (RedHatAI FP8-dynamic models) (sgl-project#33057)
  chore: move cuda_vmm_utils.py under srt/utils/ (sgl-project#36053)
  [Intel XPU] Add xpu pass for biased_topk and hash_topk (sgl-project#33323)
  [CPU] Fix NUMA/core binding for DP ranks (sgl-project#32856)
  [Fix] Harden FlashAttention CUDA graph metadata bounds (sgl-project#35454)
  [XPU] Use a fused GDN kernel from sgl-kernel for Qwen3.5 (sgl-project#33354)
  [diffusion] Fuse LongCat-Image QKNorm and interleaved RoPE (sgl-project#35995)
  [diffusion] Keep LongLive2 components resident on large GPUs (sgl-project#35993)
  ...

# Conflicts:
#	python/sglang/srt/multimodal/processors/base_processor.py
#	python/sglang/srt/server_args.py
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 31, 2026
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

intel run-ci xpu intel gpu with device `torch.xpu`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants