Closed
[Documentation|文档反馈]: aclnnKlDiv 资料错误码表缺少「reduction 取值非法」子项,实现实际返回 161002 #4332
liuhanwen8Add on  18 days agoClosed at  18 hours ago
liuhanwen8
liuhanwen8
18 days ago Create

一、文档链接 (必填)

https://gitcode.com/cann/ops-math/blob/master/math/kl_div_v2/docs/aclnnKlDiv.md

对应源码:math/kl_div_v2/op_api/aclnn_kl_div.cpp 的 CheckReduction()

二、问题文档片段 (必填)

「aclnnKlDivGetWorkspaceSize - 返回值」小节里 161002 的子项(表格为 rowspan="4",原文逐字复制):

| 返回值                  | 错误码 | 描述                                        |
| ACLNN_ERR_PARAM_INVALID | 161002 | self或target或out的数据类型不在支持的范围之内。 |
|                         | 161002 | self的shape不能与target broadcast。            |
|                         | 161002 | self或target不能转换成out的数据类型。          |
|                         | 161002 | self或target的shape dim大于8。                 |

同页「reduction(int64_t)」参数表只列了 0/1/2/3 四个合法取值,没有说明传入其它值时的行为与返回码。

💡 存在的问题(选填)

  1. 实现侧存在一条资料未声明的报错路径:CheckReduction() 对 reduction < 0 || reduction > 3 直接返回 ACLNN_ERR_PARAM_INVALID(161002)。板测(Ascend 910B2 / CANN 9.2.0):reduction=4 时第一段接口返回 161002,第二段未执行。
  2. 影响:调用方按资料错误码表做参数预校验或写错误处理分支时,无法覆盖「非法 reduction」这一实际存在的拒绝路径;也无法从资料判断该值是被钳位、被忽略还是被拒。
  3. 建议:在 161002 下补一条子项,例如「reduction 取值不在 0~3 范围内。」;或在 reduction 参数表里注明「传入其它值返回 161002」。

复现(在 ops-math 仓根目录执行,脚本对文档正文做文本断言,rc=1 即缺陷成立):

import re
import sys

PATH = "math/kl_div_v2/docs/aclnnKlDiv.md"
md = open(PATH, encoding="utf-8").read()
m = re.search(r"ACLNN_ERR_PARAM_INVALID(.{0,2000}?)</tbody>", md, re.S)
if not m:
    print("未找到 161002 错误码段落"); sys.exit(2)
cells = re.findall(r"<td[^>]*>(.*?)</td>", m.group(1), re.S)
subs = [re.sub(r"<[^>]+>", "", c).strip() for c in cells if re.sub(r"<[^>]+>", "", c).strip()]
print("161002 表内子项(%d 条):" % len(subs))
for s in subs:
    print("  -", s)
if any("reduction" in s for s in subs):
    print("[OK] 资料已声明 reduction 非法取值的报错子项"); sys.exit(0)
print("[DEFECT] 161002 表未声明 reduction 非法取值子项")
sys.exit(1)

实测输出:

161002 表内子项(5 条):
  - 161002
  - self或target或out的数据类型不在支持的范围之内。
  - self的shape不能与target broadcast。
  - self或target不能转换成out的数据类型。
  - self或target的shape dim大于8。
[DEFECT] 161002 表未声明 reduction 非法取值子项

板测侧证据(同一台机器):reduction=4 → phase1 rc=161002 ws=0。

likedislike
liuhanwen8liuhanwen8
18 days ago Added label: documentation
陈思
陈思Collaborators
17 days ago Comments:

您好,感谢反馈!核对 cann/ops-math 提交 212ce9d5460b1be26cfbee481aff1acbf5cc5c62 后,确认该错误码说明有遗漏:CheckReduction() 明确拒绝 reduction < 0 或 reduction > 3,CheckParams() 将其转换为 ACLNN_ERR_PARAM_INVALID,第一段接口直接返回该状态,即 161002。合法取值为 0(none)、1(mean)、2(sum)、3(batchmean)。校验实现、第一段返回路径

当前参数表只列出了合法值,161002 表也确实仅列四类场景,未覆盖非法 reduction。可行的修订是增加“reduction 取值不在 0~3 范围内”的子项,并同步将表格的两处 rowspan 从 4 调整为 5;参数说明也可补充“传入其他值时第一段返回 161002”。这与您报告的 reduction=4 结果一致。我们会继续跟踪这处文档说明的对齐。参数说明、错误码表

likedislike
陈思陈思Collaborators
17 days ago Assign chen_0715 as responsible person
陈思陈思Collaborators
17 days ago Added label: pending-confirmation
陈思陈思Collaborators
15 days ago Removed label: pending-confirmation
CANN-robotCANN-robotCollaborators
18 hours ago Close issue
CANN-robotCANN-robotCollaborators
18 hours ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
16 hours ago Added label: resolved