Merged
fix(examples): reject non-finite FlatQuant references #492
fix(examples): reject non-finite FlatQuant references #492
Merged
tianjunAdd on Oct 12
tianjun
tianjun
Oct 12

描述

修复 FlatQuant 样例校验器把非有限 float32 参考数据判为 PASS 的问题。读取并 reshape golden_ref.bin 后检查全部值有限,异常时抛出明确的 ValueError;避免 NaN 比较被忽略而写出错误的通过指标。有限参考继续使用现有 scale、FP4 容差与输出尺寸规则。

新增 Host CLI 回归测试,现有 UT 不作修改。同步将被修改文件的许可证声明拼写纠正为仓库 OAT.xml 中的 Huawei 2026 / CANN 2.0 原文,许可证与审计策略保持一致。

关联的Issue

问题链接附于文末。

测试

  • 自测环境:DevEnvC_mmdv8,Ubuntu 20.04.5 LTS / aarch64,Python 3.11.4、NumPy 1.26.4、ml_dtypes 0.6.0。
  • python3 examples/flat_quant/tests/test_result_verifier.py -v:8 个测试方法、11 次真实校验 CLI 调用通过,无跳过。使用同一测试文件在未修复基线上验证,5 个非有限参考场景原先均误报 PASS:首个 NaN、后续 batch NaN、全 NaN、正 Inf 组和负 Inf 组。
  • 正常零参考、多 batch、正负 0.5 精确参考继续通过;有限值不匹配继续失败;截短 y/scale 文件继续报错。
  • 仓库原生 pre-commit 适用项全部通过;使用原始 OAT.xml 扫描两个改动文件,十类报告计数均为 0。
  • 验证范围:Host 校验器与合成二进制夹具。未调用 CANN、未执行 NPU Kernel、未编译或运行 Ascend950 样例,不能据此声称设备精度验证通过。

以 master dcc896ebb1d6eec780a1803708a8be115dc273b9 为基线,仅一个源提交。

文档更新

补充校验脚本 docstring 中的参考数据有限性检查说明。

类型标签

Closes https://gitcode.com/cann/ops-tensor/issues/296

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for tianjun's contribution.)
tianjuntianjun
Oct 12 Created pull request, commit 56e15f6f
tianjuntianjun
Oct 12 Associated issue: [Bug-Report|缺陷反馈]: FlatQuant 校验器将含 NaN/Inf 的参考数据误判为 PASS
atomgit-bot
atomgit-bot
Oct 12 Comments:

变更摘要

本 PR 修复 examples/flat_quant/scripts/verify_result.py 中校验器把非有限 float32 参考数据判为通过的问题:在读取并 reshape golden_ref.bin 后新增有限性检查,发现 NaN/Inf 时抛出明确的 ValueError,避免 NaN 比较被忽略而输出错误的 PASS 指标。有限参考仍沿用原有 scale、FP4 容差与输出尺寸规则。同时新增 Host CLI 回归测试文件,并纠正被修改文件的许可证声明拼写。

主要改动

  • 非有限参考数据校验: 在 verify 函数中对 reshape 后的 golden 数组执行 np.all(np.isfinite(golden)) 检查,非有限时抛出 ValueError("Golden reference contains non-finite values"),阻止非有限数据被写入通过指标。
  • 校验脚本文档补充: 在 verify_result.py 的 docstring Checks 列表中新增说明,明确 golden 的全部 float32 参考值在比较前必须有限。
  • 许可证声明修正: 将 verify_result.py 的 License 头调整为与仓库 OAT.xml 一致的原文(redistribute it and/or modify it under the terms and conditions of、the "License"). 及 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.)。
  • 新增 Host CLI 回归测试: 新增 examples/flat_quant/tests/test_result_verifier.py,通过 subprocess 调用校验器并合成 golden_ref.bin、npu_y.bin、npu_scale.bin 夹具,覆盖单一 NaN、后续 batch NaN、全 NaN、正负 Inf 等非有限场景被拒绝,以及零参考、多 batch、正负 0.5 精确参考通过、有限值不匹配失败、输出长度不足报错等用例。
  • 失败断言约定: 测试辅助方法 _assert_nonfinite_rejected 断言非零返回码、stderr 包含指定错误信息、stdout 不含 [PASS],并确认未生成 verify_metrics.json。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 12 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
tianjun
tianjun
Oct 12 Comments:

/compile

likedislike
tianjuntianjun
Oct 12 Pre merge succeeded (commit_id: 8a8744779d2f3b73acd015c074edd18110393634)
CANN-robotCANN-robotCollaborators
Oct 12 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 12 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
repo-cann/ops-tensor ✅ 唐玮玮, 林鹏翔 (2/2) ✅ 唐玮玮 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
Oct 12 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 12 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 12 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 12 Added label: ci-pipeline-passed
林鹏翔
林鹏翔Collaborators
Oct 23 Comments:

/lgtm

likedislike
tianjun
tianjun
Oct 27 Comments:

/compile

likedislike
tianjuntianjun
Oct 27 Pre merge succeeded (commit_id: 912b428307ccec7bff7f4768e70fdbe0e5808c7d)
CANN-robot
CANN-robotCollaborators
Oct 27 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 27 Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
Oct 27 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 27 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 27 Added label: ci-pipeline-passed
tianjun
tianjun
Oct 27 Comments:

审查(/lgtm): @LinPX
评审(/approve): @liubo75

CI 已经通过,麻烦检视。

当前唯一源提交 3690dc631cc0a64b0c95dcd236d26b5301ba1626,已核对当前源的成功流水线及有效期。

likedislike
chen-kang30
chen-kang30Collaborators
29 days ago Comments:

自动评审完成:纯 Python 样例修复,正确拒绝非有限参考数据,许可证文本与 OAT.xml 一致,测试充分覆盖正反例;无实质问题(BLAZE 规则因 PR 无 C++ 差异不启用)。

未发现需要修改的问题。


CANNBot 自动评审 · head 3690dc63 · cannbot/deepseek-v4-pro

likedislike
tianjun
tianjun
20 days ago Comments:

compile

likedislike
tianjuntianjun
20 days ago Pre merge succeeded (commit_id: 11c796c50301acde150a5bdb00aa02eb3a8c3184)
CANN-robot
CANN-robotCollaborators
20 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
20 days ago Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
20 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
20 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
20 days ago Added label: ci-pipeline-passed
tianjun
tianjun
20 days ago Comments:

@liubo75 @tangweiwei2 您好,这个 PR 当前没有未解决的行内评审意见。重新触发的 CI 已完成,当前状态通过。烦请您方便时检视;若无其他问题,请按模块权限给予 /approve 和 /lgtm。若仍需调整,我会继续跟进。谢谢!

likedislike
tangweiwei2
tangweiwei2Collaborators
18 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
18 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
18 days ago Merged pull request