Closed
[Bug-Report|缺陷反馈]: foreach inplace 系列 aclnn golden 整型标量转 float 导致 int32 用例精度假红 #8601
严明奎Add on 11 days agoClosed at 11 days ago
11 days ago Added label: bug-report
11 days ago Close issue
11 days ago changed custom state from 待办的 to 已完成
10 days ago Added label: resolved
Describe the current behavior / 问题描述 (Mandatory / 必填)
TTK aclnn 通路 golden 的
_tp_num()将整型标量统一转成 Python float,torch 类型提升会因此把 int32 张量抬到 fp32:_keep_dtype窄回 int32 时,越界 float→int 转换产生 INT32_MIN(-2147483648),导致精度假红。受影响算子(均为
tests/assets/golden.py,非算子实现):foreach_mul_scalar_inplace(int32 用例 8 个)foreach_sub_scalar_inplace(int32 用例 1 个,精度 0%)foreach_sub_list_inplace(int32 用例 3 个,精度 50%)根因:aclnn 通路 golden 的整型口径与 kernel 通路
_tp_scalar不一致。Environment Information / 环境信息 (Mandatory / 必填)
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
x=-1601190518, scalar=2;Describe the expected behavior / 预期结果 (Mandatory / 必填)
NPU 对 int32 溢出按二补码回绕,golden 应与之一致。例如
x=-1601190518, scalar=2时 NPU 输出 1092586260,修复前 golden 输出 -2147483648。Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
foreach_sub_list_inplace 的 compare 日志中 Expected 出现 2147482624、2147483136 等 256 倍量化值。
Special notes for this issue/备注 (Optional / 选填)
修复方式:aclnn golden 的
_tp_num()对整型返回 Python int(weak-typed,张量保持 int32,按二补码回绕),浮点仍返回 float,与 kernel 通路_tp_scalar口径一致;标量归一同样走_tp_bf16_carrier(np.asarray(v))。验证:三个算子原失败用例分别 8/8、1/1、3/3 PASS,完整 l0 用例集回归全 PASS(浮点无回归)。
关联 PR:https://gitcode.com/cann/ops-nn/merge_requests/14179