Skip to content

[XPU] Add XPU support to check_env.py - #38873

Open
SKRohit wants to merge 18 commits into
sgl-project:mainfrom
SKRohit:feat/xpu_check_env_support
Open

SKRohit wants to merge 18 commits into
sgl-project:mainfrom
SKRohit:feat/xpu_check_env_support

Conversation

@SKRohit

@SKRohit SKRohit commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

python3 -m sglang.check_env crashes on Intel XPU machines:

Traceback (most recent call last):
  File "python/sglang/check_env.py", line 594, in <module>
    env.check_env()
    ^^^
NameError: name 'env' is not defined

The dispatch block at the bottom of check_env.py only handles CUDA, HIP, NPU,
MUSA and MPS. There is no XPU branch and no else, so on an XPU host every
condition is false, env is never bound, and the script dies with a NameError
that gives the user no clue what went wrong.

Modifications

1. Fix the NameError

Added an is_xpu() branch to the dispatch chain, plus a final else that raises
a descriptive RuntimeError instead of falling through to an unbound name on any
future unsupported platform.

2. New XPUEnv(BaseEnv)

Reports XPU-native information rather than CUDA-shaped fields:

  • Device properties (from torch.xpu.get_device_properties, grouped by device
    name): device id, architecture, vendor, SYCL platform, compute-runtime version,
    backend version, UUID, total memory, compute units, EU count, Xe-core (subslice)
    count, max work-group size, sub-group sizes, SLM size, memory bus width/clock.
  • Capability flags that gate kernel selection in SGLang:
    fp16, fp64, atomic64, bf16_conversions, XMX (dpas), XMX tf32, 2d_block_io.
  • Torch XPU build info: torch.version.xpu (SYCL version), AOT arch list and
    gencode flags, bf16/tf32 support. An arch-list mismatch is the most common cause
    of XPU-only kernel failures, so surfacing it here saves a round-trip.
  • Toolchain and driver: ONEAPI_ROOT/CMPLR_ROOT, icpx --version,
    sycl-ls, and the kernel-mode driver in use (xe vs i915) with its version.
  • sgl_kernel health: whether the extension imports and how many ops it
    registered — an importable-but-opless build is the usual symptom of an arch
    mismatch.
  • Relevant env vars (only those actually set): ZE_AFFINITY_MASK,
    ZE_FLAT_DEVICE_HIERARCHY, ONEAPI_DEVICE_SELECTOR, SYCL_CACHE_*, UR_L0_*,
    CCL_*, TORCH_LLM_ALLREDUCE, SGLANG_ATTENTION_BACKEND, etc.
  • Topology: xpu-smi topology -m and xpu-smi discovery (PCI BDF, DRM device,
    SOC UUID) — the Intel analogue of nvidia-smi topo -m.

3. XPU-appropriate package list

Drops CUDA-only entries that are always Module Not Found on XPU
(flashinfer_python, flashinfer_cubin, flashinfer_jit_cache, triton,
sglang-kernel) and adds the XPU stack: sgl-kernel/sgl-kernel-xpu,
triton-xpu, intel-sycl-rt, intel-cmplr-*, intel-opencl-rt, intel-pti,
dpcpp-cpp-rt, umf, tcmlib, the oneMKL SYCL libs, oneccl, and impi-rt.

sgl-kernel-xpu is aliased to the sgl-kernel distribution, since the XPU
kernels ship under that distribution name.

All external commands (icpx, sycl-ls, xpu-smi) are wrapped so a missing
binary degrades to Not Available or an omitted section rather than failing the
whole report.

No behavioural change for CUDA/HIP/NPU/MUSA/MPS — those paths are untouched.

Accuracy

Verified on 2 x Intel Arc Pro B70 and 8 x Intel Arc Pro B60. Sample output:

Python: 3.12.13 (main, Jun  2 2026, 22:27:15) [Clang 22.1.3 ]
XPU available: True
XPU count: 8
XPU 0,1,2,3,4,5,6,7: Intel(R) Arc(TM) Pro B60 Graphics
XPU 0,1,2,3,4,5,6,7 Device ID: 0xe211
XPU 0,1,2,3,4,5,6,7 Architecture: 0x500400400
XPU 0,1,2,3,4,5,6,7 Vendor: Intel(R) Corporation
XPU 0,1,2,3,4,5,6,7 SYCL Platform: Intel(R) oneAPI Unified Runtime over Level-Zero V2
XPU 0,1,2,3,4,5,6,7 Device Type: gpu
XPU 0,1,2,3,4,5,6,7 Compute Runtime (driver_version): 1.15.38308+4
XPU 0,1,2,3,4,5,6,7 Backend Version: 20.1.0
XPU 0,1,2,3,4,5,6,7 UUID: 868011e2-0000-0000-1700-000000000000
XPU 0,1,2,3,4,5,6,7 Total Memory: 23.91 GiB
XPU 0,1,2,3,4,5,6,7 Max Compute Units: 160
XPU 0,1,2,3,4,5,6,7 EU Count: 160
XPU 0,1,2,3,4,5,6,7 Subslice Count (Xe cores): 20
XPU 0,1,2,3,4,5,6,7 Max Work Group Size: 1024
XPU 0,1,2,3,4,5,6,7 Max Sub Groups: 64
XPU 0,1,2,3,4,5,6,7 Sub Group Sizes: 16,32
XPU 0,1,2,3,4,5,6,7 Local (SLM) Memory: 128 KiB
XPU 0,1,2,3,4,5,6,7 Memory Bus Width: 64 bit
XPU 0,1,2,3,4,5,6,7 Memory Clock: 2400 MHz
XPU 0,1,2,3,4,5,6,7 Capabilities: fp16, fp64, atomic64, bf16_conversions, XMX (dpas), 2d_block_io
SYCL Version (torch.version.xpu): 20250302
Torch XPU Arch List: pvc, bmg, dg2, arl-h, mtl-h, lnl-m, ptl-h, ptl-u
Torch XPU Gencode Flags: -device pvc,bmg,dg2,arl-h,mtl-h,lnl-m,ptl-h,ptl-u
bf16 Supported: True
tf32 Supported: True
ONEAPI_ROOT: Not Set
DPC++ (icpx): Not Available
Intel KMD: xe (loaded)
sgl_kernel XPU ops: 5 registered
PyTorch: 2.12.0+xpu
sglang: 0.5.20.dev367+gdfd9b5c2a
transformers: 5.12.1
torchao: Module Not Found
numpy: 2.3.5
aiohttp: 3.14.3
fastapi: 0.141.1
huggingface_hub: 1.30.0
interegular: 0.3.3
modelscope: 1.39.1
orjson: 3.12.0
outlines: 0.1.11
packaging: 26.3
psutil: 7.2.2
pydantic: 2.13.5
python-multipart: 0.0.32
pyzmq: 27.2.0
uvicorn: 0.52.4
uvloop: 0.22.1
vllm: Module Not Found
xgrammar: 0.1.33
openai: 2.6.1
tiktoken: 0.14.0
anthropic: 1.4.0
litellm: Module Not Found
torchcodec: 0.12.0
sgl-kernel: 0.11.0
sgl-kernel-xpu: 0.11.0
triton-xpu: 3.7.1
torchvision: 0.27.0+xpu
torchaudio: 2.11.0+xpu
intel-sycl-rt: 2025.3.2
intel-cmplr-lib-rt: 2025.3.2
intel-cmplr-lib-ur: 2025.3.2
intel-cmplr-lic-rt: 2025.3.2
intel-opencl-rt: 2025.3.2
intel-openmp: 2025.3.2
intel-pti: 0.16.0
dpcpp-cpp-rt: 2025.3.2
umf: 1.0.3
tcmlib: 1.4.1
mkl: 2025.3.1
onemkl-sycl-blas: 2025.3.1
onemkl-sycl-dft: 2025.3.1
onemkl-sycl-lapack: 2025.3.1
onemkl-sycl-rng: 2025.3.1
onemkl-sycl-sparse: 2025.3.1
oneccl: 2021.17.2
oneccl-devel: 2021.17.2
impi-rt: 2021.17.2
XPU Topology: 
GPU 0/0  GPU 1/0  GPU 2/0  GPU 3/0  GPU 4/0  GPU 5/0  GPU 6/0  GPU 7/0  CPU Affinity
GPU 0/0  S        NODE     NODE     NODE     SYS      SYS      SYS      SYS      0-127,256-383
GPU 1/0  NODE     S        NODE     NODE     SYS      SYS      SYS      SYS      0-127,256-383
GPU 2/0  NODE     NODE     S        NODE     SYS      SYS      SYS      SYS      0-127,256-383
GPU 3/0  NODE     NODE     NODE     S        SYS      SYS      SYS      SYS      0-127,256-383
GPU 4/0  SYS      SYS      SYS      SYS      S        NODE     NODE     NODE     128-255,384-511
GPU 5/0  SYS      SYS      SYS      SYS      NODE     S        NODE     NODE     128-255,384-511
GPU 6/0  SYS      SYS      SYS      SYS      NODE     NODE     S        NODE     128-255,384-511
GPU 7/0  SYS      SYS      SYS      SYS      NODE     NODE     NODE     S        128-255,384-511
XPU Discovery: 
+-----------+--------------------------------------------------------------------------------------+
| Device ID | Device Information                                                                   |
+-----------+--------------------------------------------------------------------------------------+
| 0         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-0017-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:17:00.0                                                        |
|           | DRM Device: /dev/dri/card1                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 1         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-002c-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:2c:00.0                                                        |
|           | DRM Device: /dev/dri/card2                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 2         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-003d-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:3d:00.0                                                        |
|           | DRM Device: /dev/dri/card3                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 3         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-004e-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:4e:00.0                                                        |
|           | DRM Device: /dev/dri/card4                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 4         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-0097-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:97:00.0                                                        |
|           | DRM Device: /dev/dri/card5                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 5         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-00a9-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:a9:00.0                                                        |
|           | DRM Device: /dev/dri/card6                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 6         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-00ba-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:ba:00.0                                                        |
|           | DRM Device: /dev/dri/card7                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
| 7         | Device Name: Intel(R) Arc(TM) Pro B60 Graphics                                       |
|           | Vendor Name: Intel(R) Corporation                                                    |
|           | SOC UUID: 00000000-0000-00cb-0000-0000e2118086                                       |
|           | PCI BDF Address: 0000:cb:00.0                                                        |
|           | DRM Device: /dev/dri/card8                                                           |
|           | Function Type: physical                                                              |
+-----------+--------------------------------------------------------------------------------------+
ulimit soft: 524288

CI States

Latest PR Test (Base): ❌ Run #34936881811
Latest PR Test (Extra): ❌ Run #34936881789
Latest PR Test (AMD ROCm 10): ❌ Run #34936881782

@SKRohit SKRohit changed the title Feat/xpu check env support [XPU] Add XPU support to check_env.py Sep 10, 2026

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

#37037 is open on this file and fixes the same NameError. It landed 2026-08-29, twelve days before
this, moves the selection into a _get_env() with a CPU fallback, gives CPUEnv a real body with
os.cpu_count() rather than an empty dict, and adds test/registered/unit/test_check_env.py. Neither
pull request mentions the other. Whichever goes first, the second is a rebase rather than a rewrite,
since your XPU branch and its CPU branch sit in the same if chain.

Both are also stuck on the same thing, and it is not the code. pr-gate exits on the label:

PR Labels: []
...
Missing required label 'run-ci'. See https://docs.sglang.io/developer_guide/contribution_guide.html#how-to-trigger-ci-tests

/tag-and-rerun-ci adds it, from any account in .github/CI_PERMISSIONS.json. Neither of us is among
those 251, so somebody who is has to say it before any suite starts. lint is the one check that did
run, and it passed.

One confirmation from the outside: on origin/main a CPU-only host raises your exact
NameError: name 'env' is not defined at check_env.py:594, with no XPU present. is_xpu() returns
False there and no other branch matches, so the unbound env is not Intel-specific. is_cpu() is not
the branch for it either: srt/utils/common.py:218 returns False unless SGLANG_USE_CPU_ENGINE=1.

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correcting myself on the overlap: #37037 is not the CPU half of this file. It adds its own
XPUEnv(BaseEnv) with torch.xpu.is_available(), device_count() and get_device_name(), and
if is_xpu(): return XPUEnv() inside _get_env(). So the two collide on the class name and on the whole
dispatch block, not only at the tail, and whichever goes second is a rewrite rather than a rebase.

On the ordering: #37037 was opened 2026-08-29, covers CPU as well as XPU and carries
test/registered/unit/test_check_env.py. This one is the fuller XPU report, 314 lines against 114, with
the package lists and the SYCL runtime detail. #29568 proposed the CPU fallback before either and its own
author closed it, so no maintainer has turned that idea down.

On this host the new else is the branch that runs, so the crash becomes the RuntimeError. Better, and
still no output for the Environment field the bug template requires.

For the label: @Kangyan-Zhou merged the MPS and MUSA additions to this same chain, #20753 and #16959, and
is listed in .github/CI_PERMISSIONS.json. /tag-and-rerun-ci here and on #37037 would start the suites.

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

duplicate with #39571?

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

can you include the necessary tests that I can replace #37037 with this PR in #40664

@chrikrah

Copy link
Copy Markdown

@airMeng on the duplicate question, with today's state.

#39571 is closed unmerged, so it is not the overlap. #37037 is still open and is, on this file: it adds its own XPUEnv(BaseEnv) with torch.xpu.is_available(), device_count() and get_device_name(), plus if is_xpu(): return XPUEnv() inside _get_env(). This pull request and #37037 collide on the class name and on the whole dispatch, so they cannot both land unchanged.

#37037 already ships test/registered/unit/test_check_env.py, which is what you would be replacing in #40664.

I read the state today and have not run either branch.

This branch has not been deployed

No deployments
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.

3 participants