Pull Request已成功合入, 合并人@CANN-robot
(感谢 wangqi_ai 的贡献)变更摘要
该 PR 主要修复 TTK 在 GEIR 与 ACLNN 模式下因命名导入错误和缺失 dtype 别名导致的崩溃,并从 PR #173 迁移了插件模块预加载逻辑以消除验证阶段的误报失败。具体包括:将 geir/profiling.py 中的 numpy.dtype() 修正为 np.dtype()(该文件以 numpy as np 方式导入,原写法在处理 FP4 输出时会触发 NameError);在 utilities/dtypes.py 的 DATA_TYPE_DICT 中为 torch 使用的 dtype 名称 float8_e8m0fnu 增加别名(值为 37,与 float8_e8m0 一致),避免 ACLNN 模式下创建 aclTensor 时抛出 KeyError;并在 cli/bridge.py 中新增 _preload_plugin_modules(),在测试用例校验前提前导入 --plugin 目录下的 .py 模块,确保 golden.py 中的 FrameworkApiInfoKeeper().register() 在验证前完成 API 参数信息注册,避免因插件延迟加载导致的 INPUT_COUNT_EXCEEDED 误报。
主要改动
- GEIR numpy 导入修复:
geir/profiling.py中将numpy.dtype("uint8")改为np.dtype("uint8"),消除处理 FP4 输出时的NameError: name numpy is not defined崩溃。 - 新增
float8_e8m0fnudtype 别名:在utilities/dtypes.py的DATA_TYPE_DICT中加入"float8_e8m0fnu": 37,使其与现有float8_e8m0映射一致,避免 ACLNN 模式为 mxscale 输出创建 aclTensor 时的KeyError。 - 插件模块预加载:在
cli/bridge.py中新增_preload_plugin_modules(sw),在run_with_switches的测试用例校验前遍历sw.plugin_path下的所有非下划线开头.py模块并执行导入,同时以logging.debug记录失败模块,从而保证插件注册信息在验证前生效。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ops-test-kit | ✅ 王瑞, 王林木 (2/2) | ✅ 王瑞, 王林木 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wangqi_ai, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/lgtm
/approve


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
汤平川


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
汤平川


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
汤平川


问题背景
本次修改解决四个独立问题:
GEIR 模式 FP4 输出处理报错:
ttk/core_modules/geir/profiling.py中使用numpy.dtype("uint8"),但该文件导入的是import numpy as np,直接引用numpy会导致NameError: name 'numpy' is not defined,影响 GEIR 模式下 FP4 输出的处理。ACLNN 模式 mxscale 输出报错:PyTorch 使用
float8_e8m0fnu作为 E8M0 的 dtype 名称,但 TTK 的DATA_TYPE_DICT只包含float8_e8m0,缺少float8_e8m0fnu映射。这会导致在 ACLNN 模式下为 mxscale 输出创建 aclTensor 时抛出KeyError: 'float8_e8m0fnu'。插件懒加载导致校验误报:golden.py 模块在导入时调用
FrameworkApiInfoKeeper().register()声明 OpOverloadPacket API 的参数信息。若插件未预先加载,用例校验会在插件懒加载之前执行,导致INPUT_COUNT_EXCEEDED误报。CI 静态检查失败:本 PR 触碰
dtypes.py后,CI pre-commit 增量检查暴露了该文件预存的 ruff B904(except 内 raise 缺from None)和 F841(未使用变量)违规,导致/compile触发的 CodeCheck 阶段失败。修改内容
commit a4e7bd0
ttk/core_modules/geir/profiling.py:将numpy.dtype("uint8")修正为np.dtype("uint8"),与文件已有的import numpy as np保持一致。ttk/utilities/dtypes.py:在DATA_TYPE_DICT中新增"float8_e8m0fnu": 37,与 PyTorch 的 dtype 命名对齐。ttk/cli/bridge.py:新增_preload_plugin_modules()函数(自 PR #173 迁移)。该函数在用例校验前导入--plugin目录下的所有.py模块,确保 golden.py 中声明的 API 参数信息在校验前已注册。commit c32f03a
ttk/utilities/dtypes.py修复 ruff 违规:10 处 except 内raise补from None(B904);移除 4 处未使用变量(F841),包括_mx_calculate_share_exp_nv中的FP32_EXPONENT_BIAS/FP32_MIN_NORMAL/ele_emax(copy-paste 残留死码,该函数用位操作算法不需要它们)以及trans_np_fp4_e1m2_tensor_to_bfloat16/trans_np_fp4_e2m1_tensor_to_bfloat16中的out_tensor;并应用 pre-commit 安全修复(import 排序、无占位符 f-string 转普通字符串)。commit a774858
ttk/cli/bridge.py与ttk/core_modules/geir/profiling.py:应用 pre-commit--fix自动生成的安全风格修复,包括 import 排序、open()冗余"r"参数移除、多行调用折叠,使本 PR 触碰的文件通过 CI 静态检查。验证情况
NameError,能正常完成 profiling。KeyError。--plugin的用例不再出现INPUT_COUNT_EXCEEDED误报,校验流程正常通过。ruff format --check全部已格式化。pytest tests/utilities/ tests/core_modules/comparison/ tests/core_modules/testcase_manager/test_normalize.py共 227 个用例通过。dtypes.py无 error;模块导入、DATA_TYPE_DICT['float8_e8m0fnu']==37、trans_np_fp4_*与_mx_calculate_share_exp_nv运行正常。关联
_preload_plugin_modules()实现迁移自 PR #173。