Closed
[Bug-Report|缺陷反馈]: aclnnNLLLoss2dBackward 的 totalWeight 资料写「输出」实为「输入」,mean 结果依赖调用方传入值 #7165
liuhanwen8Add on Oct 22Closed at 8 days ago
yuning_chen
Oct 22 Comments:
Oct 22 Comments:
Oct 22 Assign huang-qiang as responsible person
yuning_chen
Oct 22 Comments:
Oct 22 Comments:
您好,该问题已收到,当前问题 @huang-qiang 处理中


16 days ago Assign caorenlei as responsible person
16 days ago Removed responsible person huang-qiang
16 days ago Removed responsible person caorenlei
10 days ago Associated pull request
yuning_chen
10 days ago Comments:
10 days ago Comments:
感谢反馈,问题成立且与源码一致。
核实结论:op_host/nll_loss_grad_def.cpp 只注册了 x_grad 一个输出;op_api/aclnn_nll_loss2d_backward.cpp 的 CheckShape/CheckDtypeValid 把 totalWeight 声明为 const aclTensor*。即实现侧把 totalWeight 当输入,而资料写的是输出,二者相反。
影响:调用方按资料准备未初始化/占位 totalWeight 时,mean 分支的分母直接取自这块内存(NaN 会传播到 out),全程返回 0,属于静默错值,比报错更难发现。
修复建议(二选一):
- 资料改为输入,并明确 mean 场景必须由调用方传入
Σw(推荐:不改接口、兼容性最好); - 实现按资料计算并写出
totalWeight:需新增输出并同步改 GE 原型 / ACLNN 两段接口签名,属破坏性变更。
建议同时为 mean 分支补一条 totalWeight=NaN 的用例,把当前行为固定下来。


10 days ago Assign yu-xinjie62 as responsible person
yuning_chen
10 days ago Comments:
10 days ago Comments:
已指派给 @yu-xinjie62 跟进。
指派依据:NLLLoss 责任田 arch22 接口人黄鑫当前不可指派,回退到 vfusion/loss 领域同代际 committer


10 days ago Assign ji-songyuan as responsible person, remove original responsible person: yu-xinjie62
10 days ago Assign ji-songyuan as responsible person, remove original responsible person: yu-xinjie62
yuning_chen
10 days ago Comments:
10 days ago Comments:
更正指派:loss 类 arch22(A2/A3) 的统一责任人为 @ji-songyuan,本条改派给他,此前指派给 @yu-xinjie62 的通知作废。


8 days ago changed custom state from 进行中 to 已完成
8 days ago Close issue
chenjiayi_
4 days ago Comments:
4 days ago Comments:
补充说明本问题的后续处理:
资料已把 totalWeight 明确为输入,并与实现口径对齐。
处理结果:
loss/nll_loss_grad/docs/aclnnNLLLoss2dBackward.md的参数表把totalWeight标为“输入”,说明改为“reduction 为 mean 时,调用方必须传入按 target、weight 和 ignoreIndex 计算得到的权重和;其他 reduction 下该参数不参与计算”。- 实现侧保持原状:
op_host/nll_loss_grad_def.cpp只注册x_grad一个输出,op_api/aclnn_nll_loss2d_backward.cpp以const aclTensor*接收totalWeight。 - PR:!14323。
验证:
- master 文档
loss/nll_loss_grad/docs/aclnnNLLLoss2dBackward.md:145当前为“totalWeight是输入…”。 - 中英文两份资料同步修改。
说明:该修复随资料 PR 合入关闭。
如果还有后续需要,请重新提 issue。


现象
aclnnNLLLoss2dBackward的资料把totalWeight列为输出:「仅当 reduction 为 mean 时,totalWeight 是通过 target 取相应位置的 weight,然后去掉 ignoreIndex 对应的 weight,
将剩下的 weight 求和;当 reduction 为其他值时,该参数默认不处理。」
实测(两段均返回 0):
totalWeight预填totalWeightout前 6 元素1.01.0(未变)[0, -0.84404, -0.84404, 0, 0, 0]NaNNaN(未变)[0, nan, nan, 0, 0, 0]1.01.0(未变)⇒ ①
totalWeight从未被写出;② mean 的分母取自调用方传入的totalWeight。按资料传未初始化/占位 tensor 时,
mean的结果直接取决于垃圾值(NaN 传播),且无任何报错。源码侧佐证(master):
op_host/nll_loss_grad_def.cpp只注册一个输出x_grad;op_api/aclnn_nll_loss2d_backward.cpp的CheckShape/CheckDtypeValid把totalWeight声明为const aclTensor*,即实现侧按输入处理。复现
执行后
out出现 NaN,totalWeight仍为 NaN。期望
二者取一并保持文档与实现一致:要么按资料计算并写出
totalWeight;要么在资料里把它标为输入并说明 mean 场景必须由调用方给出
Σw。当前形态下调用方按文档使用必然静默出错。