Merged
fix(foreach): #7998 修复 foreach_log/log2 UT 判定门(参照 !13442 模式) #13918
Tian_1122Add on 13 days ago
fix(foreach): #7998 修复 foreach_log/log2 UT 判定门(参照 !13442 模式) #13918
Merged
Tian_1122Add on 13 days ago
Tian_1122
Tian_1122Collaborators
13 days ago

描述

本 PR 针对 Issue #7998,修复 foreach_log / foreach_log2 的 UT 判定门:此前 UT 使用 system(...) 调用 compare_data.py 却不检查返回值、且未实际调用算子内核,导致对比失败时用例仍能通过。改动在 C++ 用例中补上 ICPU_RUN_KF 执行内核,并将其返回值用 ASSERT_EQ 断言;同时改造 compare_data.py,使其在数据不一致时返回失败(sys.exit(1)),并新增 bf16 数据比对能力;gen_data.py 的 bf16 数据类型来源由 TensorFlow 替换为 ml_dtypes。

关联的Issue

#7998

测试

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Tian_1122's contribution.)
Tian_1122Tian_1122Collaborators
13 days ago Created pull request, commit 991dd0a5
atomgit-bot
atomgit-bot
13 days ago Comments:

变更摘要

本 PR 针对 Issue #7998,修复 foreach_log / foreach_log2 的 UT 判定门:此前 UT 使用 system(...) 调用 compare_data.py 却不检查返回值、且未实际调用算子内核,导致对比失败时用例仍能通过。改动在 C++ 用例中补上 ICPU_RUN_KF 执行内核,并将其返回值用 ASSERT_EQ 断言;同时改造 compare_data.py,使其在数据不一致时返回失败(sys.exit(1)),并新增 bf16 数据比对能力;gen_data.py 的 bf16 数据类型来源由 TensorFlow 替换为 ml_dtypes。

主要改动

  • UT 判定的有效性修复:test_foreach_log.cpp 与 test_foreach_log2.cpp 各用例新增 ICPU_RUN_KF(foreach_log/foreach_log2, blockDim, x1, x2, workspace, tiling) 调用内核,并将 compare_data.py 的执行结果保存为 cmpRc 后通过 ASSERT_EQ(cmpRc, 0) 断言,使比对失败能真正导致用例失败。
  • 比对脚本返回码语义:compare_data.py 的 process 改为返回 compare_data 结果,__main__ 中在结果为假时 sys.exit(1),为上层 UT 提供可判定门;同时 data_same 在检测到不一致时置为 False,PASSED! 仅在全部一致时打印。
  • bf16 比对支持:新增 load_bf16_as_fp32,以 uint16 读入后左移 16 位扩展为 float32 高位实现位级还原比对;compare_data 增加 bfloat16/bfloat16_t 分支,is_bf16 标志控制读取路径,精度阈值设为 1/100。
  • 失败信息输出:比对不一致时不再无条件打印 PASSED!,而是输出 FAILED! 及文件名、首个不匹配索引、期望值与实际值,便于定位;np.where(diff_res != True) 简化为 np.where(~diff_res)。
  • 数据生成依赖调整:log_data/gen_data.py 与 log2_data/gen_data.py 改用 ml_dtypes.bfloat16 替代 tensorflow 的 tf.bfloat16.as_numpy_dtype,移除对 TensorFlow 的依赖。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
13 days ago Comments:

代码审查

检视结论

本 PR 的核心方向正确:补上了原先缺失的 ICPU_RUN_KF(此前 kernel 根本没被调用)、把 system(compare_data.py) 的退出码纳入判定,并修正了 bf16 之前被当作 float32 误读的问题(改为按 uint16 移位还原 bf16 位模式,位级无损,实现正确),np.isclose(tmp_out, tmp_gold, precision, 0, True) 的参数顺序与 rtol 0.01(≈2.5 ulp)也与 bf16 尾数精度相符。主要问题是新判定门仍存在「无数据参与比对即判 PASS」的漏洞。

改动文件逐项确认

文件 结果
foreach/foreach_log/tests/ut/op_kernel/log_data/compare_data.py 1 个问题(P2:缺少金标/输出文件空与等长校验)
foreach/foreach_log/tests/ut/op_kernel/log_data/gen_data.py 1 个问题(P3:ml_dtypes 无兜底导入)
foreach/foreach_log/tests/ut/op_kernel/test_foreach_log.cpp 1 个问题(P3:gen_data 返回值未校验);其余改动(新增 RUN_KF、ASSERT_EQ 位置)无问题
foreach/foreach_log2/tests/ut/op_kernel/log2_data/compare_data.py 1 个问题(P2:同构缺陷)
foreach/foreach_log2/tests/ut/op_kernel/log2_data/gen_data.py 无独立新问题(与 log 版同构,已在上面合并说明)
foreach/foreach_log2/tests/ut/op_kernel/test_foreach_log2.cpp 无独立新问题(与 log 版同构,已在上面合并说明)

统计:P0 0 个,P1 0 个,P2 2 个,P3 2 个。

总体风险判断:无 P0/P1,变更不影响算子实现与线上行为,风险面局限于 UT 判定门本身。当前版本的判定门在「output/金标文件一个都没有」时仍会通过(zip 零迭代 → data_same=True → 退出码 0),建议合入前补上文件数量守卫,并同步校验 gen_data.py 的返回码,避免该修复再次退化为假绿。

类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
13 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
13 days ago Comments:

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
foreach ✅ 杨东, 陈昊文 (2/2) ✅ 杨东, 陈昊文 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Tian_1122, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
50 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
11 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
11 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike