Skip to content

fix(xpu): enable compressed-tensors FP8 W8A8 on XPU (RedHatAI FP8-dynamic models) - #33057

Merged
mingfeima merged 14 commits into
sgl-project:mainfrom
vshekhawat-hlab:fix/xpu-compressed-tensors-fp8-w8a8
Aug 24, 2026
Merged

mingfeima merged 14 commits into
sgl-project:mainfrom
vshekhawat-hlab:fix/xpu-compressed-tensors-fp8-w8a8

Conversation

@vshekhawat-hlab

@vshekhawat-hlab vshekhawat-hlab commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Motivation

compressed-tensors FP8 W8A8 quantized models (e.g. RedHatAI's *-FP8-dynamic family — Apertus-8B-Instruct-2509-FP8-dynamic, Mistral-Small-3.1-24B-Instruct-2503-FP8-dynamic, granite-4.0-h-small-FP8-dynamic, NVIDIA-Nemotron-Nano-9B-v2-FP8-dynamic) currently fail to serve on XPU. The very first failure happens at layer-construction time, before any kernel dispatch:

AssertionError: Torch not compiled with CUDA enabled

Fixing that surfaces two further, distinct XPU-specific issues before the model actually serves and generates correctly.

Modifications

  • compressed_tensors.py (CompressedTensorsConfig): _check_scheme_supported unconditionally called torch.cuda.get_device_capability(), which is CUDA-only. Only CompressedTensorsW8A8Fp8 has a real XPU-usable kernel path today (via the existing device-agnostic _apply_fallback_scaled_mm in fp8_utils.py, not a missing native kernel); every other capability-gated scheme (NVFP4/cutlass, Marlin-based W8A16Fp8, WNA16, ...) is explicitly rejected with a clean RuntimeError on XPU instead of crashing on the CUDA-only call.
  • fp8_kernel.py: the non-CUDA/non-MUSA branch never imported sgl_per_token_quant_fp8/sgl_per_tensor_quant_fp8 for XPU, even though sgl-kernel-xpu registers both natively — this caused a NameError on the first forward pass once the above crash was fixed.
  • fp8_utils.py (apply_fp8_linear): the activation-quant padding decision (num_token_padding=17, meant to make torch._scaled_mm more performant on CUDA for small batches) was only skipped when cutlass_fp8_supported (CUDA-only). sgl-kernel-xpu's per-token quant kernel requires output_q to exactly match input's shape and doesn't support padded output, raising a shape-mismatch RuntimeError whenever a forward pass had fewer than 17 rows (e.g. small prefill/decode steps).
  • fp8.py (Fp8MoEMethod.apply): the native sgl-kernel-xpu MoE fast path was taken unconditionally on XPU, before checking the explicitly-selected MoE runner backend.
    This made --moe-runner-backend triton a no-op on XPU for this quantization scheme — the native kernel path was still hit and raised "current MoE does not support
    use_fp8_w8a8" even when the Triton runner had been explicitly requested. Now skips the native XPU path when the runner backend is explicitly triton, falling through to
    the existing Triton dispatch below.
  • internvl.py: InternVLChatConfig has no top-level num_experts — the MoE config lives on the nested llm_config (the text-backbone config). Fixes an AttributeError when
    loading MoE-based InternVL variants.
  • runtime_context.py (get_stream): replaced a hardcoded torch.cuda.Stream() with torch.get_device_module(device).Stream(), so the named process-level side stream is
    created on whichever device backend is active instead of always assuming CUDA.
  • topk.py (biased_grouped_topk_gpu, XPU path): the topk_sigmoid kernel requires correction_bias to be float32. The CUDA branch a few lines above already casts it; the
    XPU branch passed it through unchanged, raising RuntimeError: correction_bias must be float32 on the first generation request for some MoE models. Now cast to float32
    before the call, matching the CUDA branch.

Accuracy Tests

Verified locally end-to-end in a docker container (XPU backend, Intel Arc Pro/BMG) with the patched sglang installed in place of the image's baked-in copy:

  • RedHatAI/Apertus-8B-Instruct-2509-FP8-dynamic (TP=1, --attention-backend intel_xpu) serves and evaluates gsm8k (5-shot) correctly:
    • exact_match,flexible-extract = 0.5891 ± 0.0136
    • strict-match = 0.5390 ± 0.0137
  • Regression check that the shared code paths touched here don't affect other backends/schemes:
    • All three changes are gated behind if _is_xpu: / elif _is_xpu: branches that are new no-ops on every other platform; cutlass_fp8_supported-driven CUDA behavior is unchanged (verified by re-reading every other call site of the touched functions — scaled_fp8_quant's other callers in fp8_utils.py are gated by if _is_cuda:/if _is_hip:, never reaching the changed XPU branch on other devices).
    • No currently-passing XPU model can regress from these changes: any compressed-tensors quantized model on XPU previously hit the _check_scheme_supported crash unconditionally at layer-construction time (before this PR), so none could have been passing beforehand.

Speed Tests and Profiling

Not applicable — these are correctness/compatibility fixes for an existing fallback code path (_apply_fallback_scaled_mm), no new kernel or scheduling changes. The activation-quant padding skip on XPU has a minor performance implication (an extra kernel-launch on small batches that would otherwise reuse a padded buffer), but padding was never functional on XPU before this PR (it crashed), so there's no regression relative to current behavior.

Checklist


CI States

Latest PR Test (Base): 🚫 Run #32336898587
Latest PR Test (Extra): ✅ Run #32336898486
Latest PR Test (AMD ROCm 7.2): ❌ Run #32336898668

…amic models)

compressed-tensors FP8 W8A8 (RedHatAI/*-FP8-dynamic, e.g. Apertus-8B) crashes
on XPU at layer-construction time and, after that, at first forward pass, due
to three unrelated CUDA-only assumptions:

- CompressedTensorsConfig._check_scheme_supported unconditionally calls
  torch.cuda.get_device_capability(), raising
  "AssertionError: Torch not compiled with CUDA enabled" on XPU before any
  kernel dispatch happens. Only CompressedTensorsW8A8Fp8 has a real XPU
  kernel path; every other capability-gated scheme is explicitly rejected
  with a clean error instead of crashing.
- fp8_kernel.py's non-CUDA/non-MUSA sgl_per_token_quant_fp8 /
  sgl_per_tensor_quant_fp8 import was never added for XPU, even though
  sgl-kernel-xpu registers both natively -- causing a NameError on first use.
- apply_fp8_linear's activation-quant padding (num_token_padding=17) is only
  skipped for cutlass_fp8_supported (CUDA-only); sgl-kernel-xpu's per-token
  quant kernel requires output_q to exactly match input's shape and doesn't
  support padded output, raising a shape-mismatch RuntimeError.

None of these are gated behind a kernel that's actually missing -- compressed
-tensors FP8 W8A8 on XPU runs through sglang's existing device-agnostic
_apply_fallback_scaled_mm fallback (torch._scaled_mm + rowwise/colwise scale)
once these three assumptions are corrected.

Validated end-to-end on Intel Arc Pro (BMG) XPU, TP=1, intel_xpu attention
backend: RedHatAI/Apertus-8B-Instruct-2509-FP8-dynamic serves and evaluates
gsm8k correctly (exact_match flexible-extract=58.91%, strict-match=53.90%).
@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.

…or job225

- internvl.py: InternVLChatConfig has no top-level num_experts; the MoE config
  lives on the nested llm_config (Qwen3MoE text backbone). Fixes
  AttributeError on OpenGVLab/InternVL3_5-30B-A3B.

- triton_backend.py: add mamba2_config to the hybrid-linear-model detection
  used to pick v_head_dim. GraniteMoeHybridConfig models (e.g.
  RedHatAI/granite-4.0-h-tiny-FP8-dynamic) are handled by mamba2_config() but
  weren't in this check, so layer_id=0 (a Mamba layer, not full-attention) was
  used to probe v_head_dim, raising "layer_id=0 not in full attention layers".

- fp8.py: Fp8MoEMethod.apply() took the sgl-kernel-xpu native fast path
  unconditionally on XPU, before ever checking the selected MoE runner
  backend. This made --moe-runner-backend triton a no-op on XPU for this
  quant scheme, so FP8 W8A8 MoE models (e.g. Qwen/Qwen3.6-35B-A3B-FP8) still
  hit "current MoE does not support use_fp8_w8a8" from the native kernel even
  with the Triton runner explicitly requested. Skip the native XPU path when
  the runner backend is explicitly triton, falling through to the existing
  Triton dispatch below.

Locally validated in Docker on Intel Arc Pro B60 (XPU): InternVL3_5-30B-A3B
(mmmu_val, exit 0), granite-4.0-h-tiny-FP8-dynamic (gsm8k 0.8, exit 0), and
Qwen3.6-35B-A3B-FP8 (crash resolved, though a separate reasoning-parser
accuracy issue remains open -- see applications.ai.gpu.sglang-cicd CICD repo
for details).
RuntimeContext.get_stream() always constructed a CUDA stream regardless
of the configured device, which crashed Kimi-Linear-48B-A3B-Instruct on
XPU (kimi_linear.py calls get_stream("alt") unconditionally):

  RuntimeError: torch.cuda.Stream requires CUDA support

Use torch.get_device_module(server_args.device).Stream() instead,
matching the device-agnostic pattern already used elsewhere (e.g.
speculative/dflash_info_v2.py, eagle_worker_v2.py).

Validated on XPU: with this fix plus the existing mamba/page_size
workaround flags, Kimi-Linear-48B-A3B-Instruct now clears both crashes
and successfully loads weights and allocates the KV/mamba cache pools.
topk_sigmoid kernel asserts correction_bias must be float32, but the
_is_xpu branch of biased_grouped_topk_gpu passed it through unchanged
while the CUDA branch a few lines above already does .to(torch.float32).
Surfaced when running Kimi-Linear-48B-A3B-Instruct at TP8 on XPU: first
generate request crashed with "RuntimeError: correction_bias must be
float32". Validated on device: same fix clears the crash and produces a
correct completion.
vshekhawat-hlab and others added 4 commits August 12, 2026 21:43
…tensors-fp8-w8a8-rebase

# Conflicts:
#	python/sglang/kernels/ops/quantization/fp8_kernel.py
#	python/sglang/srt/layers/attention/triton_backend.py
#	python/sglang/srt/layers/quantization/fp8_utils.py
@mingfeima mingfeima added intel xpu intel gpu with device `torch.xpu` quant LLM Quantization labels Aug 18, 2026
Comment thread python/sglang/srt/layers/quantization/fp8.py
@mingfeima
mingfeima merged commit f98b60d into sgl-project:main Aug 24, 2026
154 of 171 checks passed
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 jit-kernel quant LLM Quantization run-ci run-ci-extra xpu intel gpu with device `torch.xpu`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants