Skip to content

XPU: Enable GLM5.1 (GlmMoeDsaForCausalLM) DSA Attention - #24959

Merged
mingfeima merged 73 commits into
sgl-project:mainfrom
Xia-Weiwen:glm5.1_enabling
Sep 7, 2026
Merged

mingfeima merged 73 commits into
sgl-project:mainfrom
Xia-Weiwen:glm5.1_enabling

Conversation

@Xia-Weiwen

@Xia-Weiwen Xia-Weiwen commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GLM5.1 uses Dynamic Sparse Attention (DSA/NSA) with an FP8 indexer that scores KV pages before sparse attention. This PR enables the path on XPU.

Modifications

1. server_args.py
When GLM5.1 (or any DSA model) runs on XPU, automatically set:

  • decode_attention_backend = "dsa" — puts DeepseekSparseAttnBackend as the decode backend inside HybridAttnBackend, so it can manage the DSA index K-cache and FP8 logit scoring.
  • prefill_attention_backend = "dsa" — We use the dense version of prefill MLA for now since no XPU sparse prefill kernel exists yet in sgl-kernel-xpu.
  • Disable SGLANG_OPT_USE_TOPK_V2 — the v2 topk uses TileLang/TVM JIT compilation which requires CUDA.

2. hybrid_attn_backend.py
In HybridAttnBackend, when the selected backend is not the decode backend (i.e. during prefill when Triton is selected), also call decode_backend.init_forward_metadata() and get_indexer_metadata() from the decode backend. This ensures the DSA decode backend (DeepseekSparseAttnBackend) remains responsible for the DSA indexer even during prefill passes.

3. dsa_backend.py
Guard flashmla_metadata computation with not _is_xpu. The get_mla_metadata function is from sgl_kernel.flash_mla which is CUDA-only.

4. dsa/dsa_indexer.py
Replace torch.cuda.get_device_properties and torch.cuda.mem_get_info with XPU-aware equivalents in _get_mqa_logits_budget_bytes.

5. rotary_embedding/base.py
In forward_xpu, handle 2D input tensors (N, head_size) for the fallback sgl_kernel.rotary_embedding kernel which expects 3D (N, num_heads, head_size). The DSA indexer passes a single-head k_rope as 2D.

6. jit_kernel/dsa/init.py
Guard the CuteDSL import (NVIDIA CUDA DSL) on XPU, matching the existing ROCm guard.

Accuracy Tests

N/A since the original model is too big for BMG.

Speed Tests and Profiling

N/A since the original model is too big for BMG.

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 #33839554583
Latest PR Test (Extra): ❌ Run #33839554508
Latest PR Test (AMD ROCm 7.2): ❌ Run #33839554544

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

Hi @mingfeima Could you please review the PR? Thanks.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces XPU support to the KV cache mixin by updating the model runner's pool initialization logic. Specifically, it modifies the conditions for selecting the KV pool class and updates assertions to accommodate NSA models on XPU hardware. I have no feedback to provide.

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

# Conflicts:
#	python/sglang/srt/layers/rotary_embedding/base.py
# Conflicts:
#	python/sglang/kernels/ops/attention/dsa/index_buf_accessor.py
#	python/sglang/srt/layers/attention/dsa/dsa_indexer.py
#	python/sglang/srt/mem_cache/memory_pool.py
@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@mingfeima

Copy link
Copy Markdown
Collaborator

memory_hook.py:260: 2 GB XPU reservation causes the current stage-b failure.

DeepSeek-OCR receives mem_fraction_static=0.5016, below the measured minimum 0.523, and fails startup twice.
Please scope this reservation to the affected workload or derive it from measured scratch requirements.

dsa_indexer.py:1430: XPU-reachable context-parallel path still allocates tensors on cuda and calls deep_gemm.fp8_mqa_logits. Add an XPU implementation or reject XPU DSA context parallelism during argument resolution, with a focused test.

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Xia-Weiwen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek intel jit-kernel memory-pool run-ci CI: run the baseline test suite on this PR xpu intel gpu with device `torch.xpu`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants