Add sglang sglang check env compiler oserror - #5
Conversation
There was a problem hiding this comment.
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.
| @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"}) |
There was a problem hiding this comment.
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.
| @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"}) |
| @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"}) |
There was a problem hiding this comment.
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.
| @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
Summary
Validation
Review notes