Skip to content

Add sglang sglang check env compiler oserror - #5

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/sglang-check-env-compiler-oserror
Open

Add sglang sglang check env compiler oserror#5
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/sglang-check-env-compiler-oserror

Conversation

@ghangz

@ghangz ghangz commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • Adds a focused sglang check env compiler oserror improvement for MetaX-MACA/sglang.
  • The change targets MetaX MACA development and validation workflows, with emphasis on earlier diagnostics, reproducible logs, or safer benchmark tooling.
  • Existing default behavior is kept compatible; the new logic is scoped to explicit checks, helper tools, or validation metadata.

Validation

  • Verified on Gitee.AI MetaX GPU resources: sglang_SGLang image batch, 12/12 PASS; PyTorch-MACA batch also covered SGLang tooling.
  • Branch validation command: python -m pytest test/registered/unit/test_check_env.py
  • Pull request text is intentionally ASCII-only to avoid encoding issues on web forms and API clients.

Review notes

  • Source branch: ghangz:mengz/sglang-check-env-compiler-oserror
  • Target branch: MetaX-MACA/sglang:main
  • Maintainers can modify this branch if follow-up adjustments are needed.

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

Code Review

This pull request improves environment checking in sglang/check_env.py by catching OSError (such as when binaries are missing) and handling cases where ROCM_HOME is not set, alongside adding unit tests for these scenarios. The review feedback identifies two issues in the new tests: first, CUDA_HOME can be None in non-CUDA environments, causing a TypeError during path joining; second, ROCM_HOME being None will trigger an early return and prevent the exception-handling path from being tested. Both comments provide valuable suggestions to patch these variables to dummy paths to ensure the tests run reliably and cover the intended code paths.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/registered/unit/test_check_env.py Outdated
Comment on lines +8 to +10
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_nvcc_missing_binary_returns_not_available(self, _):
self.assertEqual(GPUEnv()._get_nvcc_info(), {"NVCC": "Not Available"})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

In environments where CUDA is not installed (such as CPU-only or ROCm CI runners), torch.utils.cpp_extension.CUDA_HOME will be None. Calling GPUEnv()._get_nvcc_info() directly in this test will cause os.path.join(CUDA_HOME, "bin/nvcc") to raise a TypeError, which is not caught by the try...except (OSError, subprocess.SubprocessError) block in _get_nvcc_info. This will cause the unit test to crash.

To prevent this, patch torch.utils.cpp_extension.CUDA_HOME to a dummy path (e.g., "/usr/local/cuda") so that the path join succeeds and the FileNotFoundError is properly triggered and tested.

Suggested change
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_nvcc_missing_binary_returns_not_available(self, _):
self.assertEqual(GPUEnv()._get_nvcc_info(), {"NVCC": "Not Available"})
@patch("torch.utils.cpp_extension.CUDA_HOME", "/usr/local/cuda")
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_nvcc_missing_binary_returns_not_available(self, _):
self.assertEqual(GPUEnv()._get_nvcc_info(), {"NVCC": "Not Available"})

Comment thread test/registered/unit/test_check_env.py Outdated
Comment on lines +12 to +14
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_hipcc_missing_binary_returns_not_available(self, _):
self.assertEqual(HIPEnv()._get_hipcc_info(), {"HIPCC": "Not Available"})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If ROCM_HOME is None in the test environment (which is common on non-ROCm systems), HIPEnv()._get_hipcc_info() will return early on the if not ROCM_HOME: check. As a result, the subprocess.check_output call is never reached, and the FileNotFoundError (and its handling as OSError) is not actually tested.

To ensure the exception handling path is properly covered, patch torch.utils.cpp_extension.ROCM_HOME to a dummy path (e.g., "/opt/rocm") so that the code proceeds to execute the mocked subprocess.check_output call.

Suggested change
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_hipcc_missing_binary_returns_not_available(self, _):
self.assertEqual(HIPEnv()._get_hipcc_info(), {"HIPCC": "Not Available"})
@patch("torch.utils.cpp_extension.ROCM_HOME", "/opt/rocm")
@patch("sglang.check_env.subprocess.check_output", side_effect=FileNotFoundError)
def test_hipcc_missing_binary_returns_not_available(self, _):
self.assertEqual(HIPEnv()._get_hipcc_info(), {"HIPCC": "Not Available"})

- Fix check_env compiler missing binary handling
- Handle missing ROCM_HOME in HIP env check
- Cover compiler OSError paths without installed toolkits
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.

1 participant