Skip to content

Add sglang sglang check env topology oserror - #8

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

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

Conversation

@ghangz

@ghangz ghangz commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • Adds a focused sglang check env topology 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-topology-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 FileNotFoundError when a command is missing) in addition to subprocess.SubprocessError across various GPU topology checks. It also adds unit tests to verify that an empty topology dictionary is returned when the underlying command is not found. The reviewer suggested improving the unit tests by asserting that subprocess.run is called with the correct commands and arguments to ensure the tests are robust.

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 on lines +1 to +22
import unittest
from unittest.mock import patch

from sglang.check_env import GPUEnv, HIPEnv, MUSAEnv, NPUEnv


class TestCheckEnv(unittest.TestCase):
@patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
def test_gpu_topology_missing_command_returns_empty_info(self, _):
self.assertEqual(GPUEnv().get_topology(), {})

@patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
def test_hip_topology_missing_command_returns_empty_info(self, _):
self.assertEqual(HIPEnv().get_topology(), {})

@patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
def test_npu_topology_missing_command_returns_empty_info(self, _):
self.assertEqual(NPUEnv().get_topology(), {})

@patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
def test_musa_topology_missing_command_returns_empty_info(self, _):
self.assertEqual(MUSAEnv().get_topology(), {})

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

The unit tests mock subprocess.run but do not assert that it was called with the correct command and arguments. Without these assertions, the tests could pass even if the underlying command is incorrect or if subprocess.run is not called at all. It is highly recommended to verify that the mock was called with the expected arguments.

import subprocess
import unittest
from unittest.mock import patch

from sglang.check_env import GPUEnv, HIPEnv, MUSAEnv, NPUEnv


class TestCheckEnv(unittest.TestCase):
    @patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
    def test_gpu_topology_missing_command_returns_empty_info(self, mock_run):
        self.assertEqual(GPUEnv().get_topology(), {})
        mock_run.assert_called_once_with(
            ["nvidia-smi", "topo", "-m"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            check=True,
        )

    @patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
    def test_hip_topology_missing_command_returns_empty_info(self, mock_run):
        self.assertEqual(HIPEnv().get_topology(), {})
        mock_run.assert_called_once_with(
            ["rocm-smi", "--showtopotype"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            check=True,
        )

    @patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
    def test_npu_topology_missing_command_returns_empty_info(self, mock_run):
        self.assertEqual(NPUEnv().get_topology(), {})
        mock_run.assert_called_once_with(
            ["npu-smi", "info", "-t", "topo"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            check=True,
        )

    @patch("sglang.check_env.subprocess.run", side_effect=FileNotFoundError)
    def test_musa_topology_missing_command_returns_empty_info(self, mock_run):
        self.assertEqual(MUSAEnv().get_topology(), {})
        mock_run.assert_called_once_with(
            ["mthreads-gmi", "topo", "-m"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            check=True,
        )

- Handle missing topology commands in check_env
- Assert topology probe commands in tests
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