Skip to content

增加 MACA 环境诊断工具#12

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/add-maca-env-doctor
Open

增加 MACA 环境诊断工具#12
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/add-maca-env-doctor

Conversation

@ghangz

@ghangz ghangz commented Jun 8, 2026

Copy link
Copy Markdown

该 PR 为 FlashMLA 增加面向沐曦环境的诊断工具,集中检查运行时、编译器和 Python 扩展依赖,降低算子编译和基准测试前的排障成本。

这个修改面向沐曦 GPU 适配场景中比较容易影响开发、构建或验证稳定性的环节,把原来需要人工排查的问题前移到工具链、运行前检查或基准脚本中处理。实现上保持对现有默认行为的兼容,只在检测到明确配置、输入或环境异常时给出更直接的诊断,避免引入额外运行依赖,也方便维护者独立审阅该分支。

已在沐曦算力环境中完成对应分支验证,验证记录包含真实运行日志、命令输出和失败路径检查,本地归档目录为:E:/Documents/muxi/测试报告/FlashMLA_real_maca_validation_20260608。提交分支:mengz/add-maca-env-doctor,目标仓库:MetaX-MACA/FlashMLA

@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 introduces a new diagnostics tool tools/maca_env_doctor.py to collect FlashMLA MACA environment diagnostics, along with its corresponding unit tests in tests/test_maca_env_doctor.py. The review feedback highlights compatibility issues with Python 3.7 and 3.8 due to the use of PEP 585/604 type annotations (such as dict, list, and |), suggesting the use of typing.Dict, typing.List, and typing.Optional instead. Additionally, there is a recommendation to check if the module specification spec is None before loading the module in the test file to prevent potential runtime errors.

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 tools/maca_env_doctor.py
import subprocess
import sys
from pathlib import Path
from typing import Any

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

为了保持与 Python 3.7 和 3.8 的兼容性(如 setup.py 中指定的 python_requires=">=3.7"),我们应该从 typing 导入 DictListOptional,而不是使用 PEP 585/604 风格的类型注解(如 dict[...]list[...]|),因为这些特性分别在 Python 3.9+ 和 3.10+ 中才被支持。

Suggested change
from typing import Any
from typing import Any, Dict, List, Optional

Comment thread tools/maca_env_doctor.py
from typing import Any


def _path_status(path: str | None) -> dict[str, Any]:

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

更新类型注解以使用 OptionalDict,从而确保与 Python 3.7 和 3.8 的兼容性。

Suggested change
def _path_status(path: str | None) -> dict[str, Any]:
def _path_status(path: Optional[str]) -> Dict[str, Any]:

Comment thread tools/maca_env_doctor.py
}


def _command_output(command: list[str]) -> dict[str, Any]:

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

更新类型注解以使用 ListDict,从而确保与 Python 3.7 和 3.8 的兼容性。

Suggested change
def _command_output(command: list[str]) -> dict[str, Any]:
def _command_output(command: List[str]) -> Dict[str, Any]:

Comment thread tools/maca_env_doctor.py
return {"command": command, "error": f"{type(exc).__name__}: {exc}"}


def collect_report(env: dict[str, str] | None = None) -> dict[str, Any]:

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

更新类型注解以使用 OptionalDict,从而确保与 Python 3.7 和 3.8 的兼容性。

Suggested change
def collect_report(env: dict[str, str] | None = None) -> dict[str, Any]:
def collect_report(env: Optional[Dict[str, str]] = None) -> Dict[str, Any]:

Comment thread tools/maca_env_doctor.py
search_path = env.get("PATH", "")
cucc = shutil.which("cucc", path=search_path)
nvcc = shutil.which("nvcc", path=search_path)
report: dict[str, Any] = {

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

更新变量类型注解以使用 Dict,从而确保与 Python 3.7 和 3.8 的兼容性。

Suggested change
report: dict[str, Any] = {
report: Dict[str, Any] = {

Comment on lines +7 to +10
spec = importlib.util.spec_from_file_location("maca_env_doctor", DOCTOR_PATH)
maca_env_doctor = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(maca_env_doctor)

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

如果 importlib.util.spec_from_file_location 无法找到或加载模块规范,它可能会返回 None。在这种情况下,直接调用 module_from_spec(spec) 会在到达第 9 行的断言之前抛出 TypeError。我们应该在尝试加载模块之前,先断言 spec 不为 None

Suggested change
spec = importlib.util.spec_from_file_location("maca_env_doctor", DOCTOR_PATH)
maca_env_doctor = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(maca_env_doctor)
spec = importlib.util.spec_from_file_location("maca_env_doctor", DOCTOR_PATH)
assert spec is not None and spec.loader is not None
maca_env_doctor = importlib.util.module_from_spec(spec)
spec.loader.exec_module(maca_env_doctor)

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