增加 MACA 环境诊断工具#12
Conversation
There was a problem hiding this comment.
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.
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Any |
There was a problem hiding this comment.
| from typing import Any | ||
|
|
||
|
|
||
| def _path_status(path: str | None) -> dict[str, Any]: |
| } | ||
|
|
||
|
|
||
| def _command_output(command: list[str]) -> dict[str, Any]: |
| return {"command": command, "error": f"{type(exc).__name__}: {exc}"} | ||
|
|
||
|
|
||
| def collect_report(env: dict[str, str] | None = None) -> dict[str, Any]: |
| search_path = env.get("PATH", "") | ||
| cucc = shutil.which("cucc", path=search_path) | ||
| nvcc = shutil.which("nvcc", path=search_path) | ||
| report: dict[str, Any] = { |
| 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) |
There was a problem hiding this comment.
如果 importlib.util.spec_from_file_location 无法找到或加载模块规范,它可能会返回 None。在这种情况下,直接调用 module_from_spec(spec) 会在到达第 9 行的断言之前抛出 TypeError。我们应该在尝试加载模块之前,先断言 spec 不为 None。
| 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) |
该 PR 为 FlashMLA 增加面向沐曦环境的诊断工具,集中检查运行时、编译器和 Python 扩展依赖,降低算子编译和基准测试前的排障成本。
这个修改面向沐曦 GPU 适配场景中比较容易影响开发、构建或验证稳定性的环节,把原来需要人工排查的问题前移到工具链、运行前检查或基准脚本中处理。实现上保持对现有默认行为的兼容,只在检测到明确配置、输入或环境异常时给出更直接的诊断,避免引入额外运行依赖,也方便维护者独立审阅该分支。
已在沐曦算力环境中完成对应分支验证,验证记录包含真实运行日志、命令输出和失败路径检查,本地归档目录为:E:/Documents/muxi/测试报告/FlashMLA_real_maca_validation_20260608。提交分支:
mengz/add-maca-env-doctor,目标仓库:MetaX-MACA/FlashMLA。