Skip to content

检测真实 cucc 版本#17

Open
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/detect-real-cucc-version
Open

检测真实 cucc 版本#17
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/detect-real-cucc-version

Conversation

@ghangz

@ghangz ghangz commented Jun 8, 2026

Copy link
Copy Markdown

该 PR 改进 cucc 版本检测方式,优先读取实际可执行编译器输出,避免仅依赖路径推断造成工具链版本记录不准确。

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

已在沐曦算力环境中完成对应分支验证,验证记录包含真实运行日志、命令输出和失败路径检查,本地归档目录为:E:/Documents/muxi/测试报告/FlashMLA_real_maca_validation_20260608。提交分支:mengz/detect-real-cucc-version,目标仓库: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 refactors the CUDA compiler version detection by moving the logic from setup.py to a new build_tools/compiler_version.py module, adding support for both cucc and nvcc compilers, and introducing unit tests. The review feedback highlights compatibility issues with the | union type hint syntax on Python versions below 3.10, suggesting the use of typing.Union instead. Additionally, the reviewer recommends excluding the new build_tools directory in setup.py's find_packages to prevent it from being installed as a top-level package and polluting the user's environment.

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 +3 to +4
from pathlib import Path
from typing import Callable

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+,直接使用 str | Path 语法(PEP 604)在 Python 3.10 以下版本导入时会抛出 TypeError。建议在此处导入 Union 以支持低版本 Python。

Suggested change
from pathlib import Path
from typing import Callable
from pathlib import Path
from typing import Callable, Union

raise ValueError(f"Cannot parse compiler release version from output: {output!r}")


def _compiler_candidates(cuda_dir: str | Path) -> list[Path]:

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

使用 Union[str, Path] 代替 str | Path 以确保在 Python 3.7/3.8/3.9 环境下的兼容性。

Suggested change
def _compiler_candidates(cuda_dir: str | Path) -> list[Path]:
def _compiler_candidates(cuda_dir: Union[str, Path]) -> list[Path]:

Comment on lines +26 to +29
def get_cuda_bare_metal_version(
cuda_dir: str | Path,
check_output: Callable[..., str] = subprocess.check_output,
) -> tuple[str, Version]:

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

使用 Union[str, Path] 代替 str | Path 以确保在 Python 3.7/3.8/3.9 环境下的兼容性。

Suggested change
def get_cuda_bare_metal_version(
cuda_dir: str | Path,
check_output: Callable[..., str] = subprocess.check_output,
) -> tuple[str, Version]:
def get_cuda_bare_metal_version(
cuda_dir: Union[str, Path],
check_output: Callable[..., str] = subprocess.check_output,
) -> tuple[str, Version]:

Comment thread setup.py
CUDA_HOME,
)

from build_tools.compiler_version import get_cuda_bare_metal_version

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

新引入的 build_tools 目录中包含了 __init__.py,这使其被识别为一个 Python 包。由于 setup.py 中的 find_packages 调用没有将 "build_tools" 排除,这会导致在构建和安装 flash_mla 时,build_tools 会作为一个顶级的包被安装到用户的 site-packages 目录中。

这会污染用户的 Python 环境,并且由于 build_tools 是一个非常通用的名称,极易与其他库产生命名冲突。

建议在 setup.pyfind_packages(exclude=(...)) 中将 "build_tools" 排除。例如:

    packages=find_packages(
        exclude=(
            "build",
            "build_tools",  # 新增排除
            "csrc",
            ...
        )
    ),

由于 setup.py 在运行时处于项目根目录下,即使排除了该包,构建时依然可以正常导入并使用它。

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