Add SGLang MACA check-env reporting - #3
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for MetaX MACA GPU environment checking by introducing the MACAEnv class and corresponding unit tests. The review feedback suggests removing redundant package definitions that mutate global state, adding timeouts to subprocess executions to prevent hanging, and replacing hardcoded values in the test suite with standard constants.
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.
| class MACAEnv(BaseEnv): | ||
| """Environment checker for MetaX MACA GPU.""" | ||
|
|
||
| EXTRA_PACKAGE_LIST = [ | ||
| "vllm", | ||
| "triton", | ||
| ] | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.package_list.extend(MACAEnv.EXTRA_PACKAGE_LIST) | ||
|
|
There was a problem hiding this comment.
在 PACKAGE_LIST(第 35 行和第 54 行)中已经包含了 "triton" 和 "vllm"。因此,这里的 EXTRA_PACKAGE_LIST 是多余的。此外,BaseEnv.__init__ 中 self.package_list = PACKAGE_LIST 是对全局列表的引用,直接调用 self.package_list.extend(...) 会在原地修改全局的 PACKAGE_LIST,导致重复元素和潜在的副作用。建议直接移除 EXTRA_PACKAGE_LIST 和 __init__ 方法。
| class MACAEnv(BaseEnv): | |
| """Environment checker for MetaX MACA GPU.""" | |
| EXTRA_PACKAGE_LIST = [ | |
| "vllm", | |
| "triton", | |
| ] | |
| def __init__(self): | |
| super().__init__() | |
| self.package_list.extend(MACAEnv.EXTRA_PACKAGE_LIST) | |
| class MACAEnv(BaseEnv): | |
| """Environment checker for MetaX MACA GPU.""" |
| cucc_output = ( | ||
| subprocess.check_output( | ||
| [cucc, "--version"], stderr=subprocess.STDOUT | ||
| ) |
There was a problem hiding this comment.
为了防止在工具链或驱动出现异常(例如 GPU 卡死、锁死)时导致 check_env 脚本无限期挂起,建议为 subprocess.check_output 调用添加 timeout 参数(例如 timeout=10)。
| cucc_output = ( | |
| subprocess.check_output( | |
| [cucc, "--version"], stderr=subprocess.STDOUT | |
| ) | |
| cucc_output = ( | |
| subprocess.check_output( | |
| [cucc, "--version"], | |
| stderr=subprocess.STDOUT, | |
| timeout=10, | |
| ) |
| output = subprocess.check_output( | ||
| [mx_smi, "--show-version"], | ||
| stderr=subprocess.STDOUT, | ||
| text=True, | ||
| ).strip() |
There was a problem hiding this comment.
同样地,建议为 mx-smi 的 subprocess.check_output 调用添加 timeout=10 参数,以防止在驱动或工具链挂起时导致脚本卡死。
| output = subprocess.check_output( | |
| [mx_smi, "--show-version"], | |
| stderr=subprocess.STDOUT, | |
| text=True, | |
| ).strip() | |
| output = subprocess.check_output( | |
| [mx_smi, "--show-version"], | |
| stderr=subprocess.STDOUT, | |
| text=True, | |
| timeout=10, | |
| ).strip() |
| result = subprocess.run( | ||
| [mx_smi, *args], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| text=True, | ||
| check=True, | ||
| ) |
There was a problem hiding this comment.
建议为 subprocess.run 添加 timeout=10 参数,防止获取拓扑信息时因 GPU 响应超时而导致脚本挂起。
| result = subprocess.run( | |
| [mx_smi, *args], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True, | |
| check=True, | |
| ) | |
| result = subprocess.run( | |
| [mx_smi, *args], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True, | |
| check=True, | |
| timeout=10, | |
| ) |
| mock_check_output.assert_called_once_with( | ||
| [os.path.join("/opt/cucc", "bin", "cucc"), "--version"], | ||
| stderr=-2, | ||
| ) |
There was a problem hiding this comment.
避免硬编码 stderr=-2,建议使用 self.check_env.subprocess.STDOUT。同时,如果我们在 check_env.py 中为 subprocess.check_output 增加了 timeout=10 参数,测试中的断言也需要同步加上 timeout=10。
| mock_check_output.assert_called_once_with( | |
| [os.path.join("/opt/cucc", "bin", "cucc"), "--version"], | |
| stderr=-2, | |
| ) | |
| mock_check_output.assert_called_once_with( | |
| [os.path.join("/opt/cucc", "bin", "cucc"), "--version"], | |
| stderr=self.check_env.subprocess.STDOUT, | |
| timeout=10, | |
| ) |
?? API ?? 2 ??????
- Report MACA toolchain in check_env - Refine MACA environment checks
Summary
Validation
Review notes