Skip to content

[BugFix] Handle CPU-only and XPU environments in check_env - #37037

Open
CharlesXu-HQ wants to merge 1 commit into
sgl-project:mainfrom
CharlesXu-HQ:fix/check-env-no-accelerator
Open

CharlesXu-HQ wants to merge 1 commit into
sgl-project:mainfrom
CharlesXu-HQ:fix/check-env-no-accelerator

Conversation

@CharlesXu-HQ

@CharlesXu-HQ CharlesXu-HQ commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

python -m sglang.check_env leaves env undefined when no existing accelerator predicate matches. This crashes on CPU-only installations and on Intel XPU hosts because the dispatcher has neither a CPU fallback nor an XPU branch.

Related to #35144, which reports the XPU form of this failure.

The closed, unmerged draft #29568 previously proposed the CPU fallback. This PR carries that fallback forward and additionally adds Intel XPU selection and device reporting, with tests following the current CustomTestCase requirement.

Modifications

  • Add CPUEnv to report CPU architecture and logical CPU count.
  • Add XPUEnv to report XPU availability, device count, and grouped device names.
  • Reuse the existing is_xpu() platform predicate in environment selection.
  • Move backend selection into _get_env() and always return a checker, falling back to CPUEnv.
  • Add CPU CI regression coverage for CPU-only fallback and mocked XPU selection/device enumeration.

Accuracy Tests

N/A. This only changes environment diagnostics and does not affect model outputs.

Speed Tests and Profiling

N/A. No inference or performance-critical path is changed.

Tests

  • CPU regression test file: 2 tests passed with dependency-isolated imports.
  • python3 -m py_compile python/sglang/check_env.py test/registered/unit/test_check_env.py
  • ruff check --select=F401,F821,UP037 python/sglang/check_env.py test/registered/unit/test_check_env.py
  • black --check python/sglang/check_env.py test/registered/unit/test_check_env.py
  • isort --check-only --settings-path .isort.cfg python/sglang/check_env.py test/registered/unit/test_check_env.py
  • CI registration parser: base-a-test-cpu, main entry present.
  • git diff origin/main...HEAD --check

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 #33253812907
Latest PR Test (Extra): ❌ Run #33253812700
Latest PR Test (AMD ROCm 7.2): ❌ Run #33253812977

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

#38873 is open on this file and fixes the same NameError, from the XPU side. It landed 2026-09-10,
twelve days after this one, adds an XPUEnv with its own package lists and an elif is_xpu() in the same
chain, and ends it with else: raise RuntimeError. Neither pull request mentions the other. This one is
the earlier and the wider of the two: it covers CPU as well, moves the selection into _get_env(), and
carries test/registered/unit/test_check_env.py, which #38873 has no equivalent of.

Both are 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. Sixteen days of red checks here are
that label.

One confirmation for the CPU half: on origin/main a CPU-only host raises NameError: name 'env' is not defined at check_env.py:594, and the bug template asks every reporter for that command's output.

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.

2 participants