Closed
[Documentation|文档反馈]: aclnnL1Loss 资料声明 self/target/out 支持 INT64,但未注明仅 reduction=none 可用(mean/sum 实测 161002) #8204
liuhanwen8Add on  16 days agoClosed at  9 days ago
liuhanwen8
liuhanwen8
16 days ago Create

[Documentation|文档反馈] aclnnL1Loss 资料声明 self/target/out 支持 INT64,但未注明仅 reduction=none 可用(mean/sum 实测 161002)

现象

资料 loss/lp_loss/docs/aclnnL1Loss.md 的参数说明三处(:101 self、:111 target、:131 out)dtype 列都写「FLOAT、FLOAT16、BFLOAT16、INT64」,未附任何 reduction 条件;实测 INT64 三个张量只在 reduction=none 下被接受,mean / sum 均返回 161002。

用例(self/target/out 全 INT64,shape {2,3}) reduction 第一段 wsSize
缺陷·none 0 0(接受) 1024
缺陷·mean 1 161002 0
缺陷·sum 2 161002 0
对照·FLOAT 基线 0 0 16777728

期望

资料既然把 INT64 列进支持列表,就应写清适用条件;实测的限制来自实现 aclnn_l1_loss.cpp:67-84 的 CheckDtypeValid(注释「与Cuda行为保持一致」:reduction=none 时非浮点 self 不允许配浮点 target;reduction=mean 时 self 与 target 不能同时非浮点)。这类 reduction 相关的 dtype 限制在资料里完全没有体现,调用方按 dtype 列选 INT64 后,换一个 reduction 就会拿到 161002。

建议二选一:① 在参数说明的 dtype 列或「约束说明」注明「INT64 仅 reduction=none 支持;reduction=mean/sum 要求浮点 dtype」;② 在错误码表补一条 161002 子项说明该组合。

环境

  • 硬件 Ascend950PR_9579(A5);软件 CANN 9.3.0(B020),libopapi.so 构建 2026-10-28
  • 仓库 cann/ops-nn 分支 9.3.0-beta.1 @ 99a37ee3e2c3fb57048cd1628ed7042bba70c697(2026-11-04);master 同三行仍写 INT64
  • R1b 核查:<!-- npu="950" id1 --> 段写明「Ascend 950PR&950DT系列产品:支持」,所引参数行不受其它产品分段限定

复现步骤

  1. OFF=/usr/local/Ascend/ascend-toolkit/latest; source $OFF/set_env.sh; export ASCEND_RT_VISIBLE_DEVICES=<空闲卡号>
  2. 把 ## 复现脚本 的代码存为 probe.cpp
  3. g++ -std=c++17 -O2 -o probe probe.cpp -I$OFF/include -I$OFF/include/aclnnop -I$OFF/include/aclnnop/level2 -L$OFF/lib64 -lopapi -lnnopbase -lascendcl
  4. LD_LIBRARY_PATH=$OFF/lib64:$LD_LIBRARY_PATH ./probe
  5. 看三行 INT64 结果:none=0、mean=161002、sum=161002;FLOAT 基线=0

复现脚本

实测输出(A5 / CANN 9.3.0.B020,aclnn 两段式直调):

[INT64 全同 reduction=none] reduction=0 GetWorkspaceSize = 0 wsSize=1024
[INT64 全同 reduction=mean] reduction=1 GetWorkspaceSize = 161002 wsSize=0
[INT64 全同 reduction=sum] reduction=2 GetWorkspaceSize = 161002 wsSize=0
[FLOAT 基线 reduction=none] reduction=0 GetWorkspaceSize = 0 wsSize=16777728
// aclnnL1Loss:INT64 是否真的被拒 —— 按 reduction 三态分别实测(文档 L101/L111/L131 声明 self/target/out 支持 INT64)
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <vector>
#include "acl/acl.h"
#include "aclnnop/aclnn_l1_loss.h"
static void* Dev(int64_t b) { void* p = nullptr; aclrtMalloc(&p, b, ACL_MEM_MALLOC_HUGE_FIRST); if (p) aclrtMemset(p, b, 0, b); return p; }
static aclTensor* T(std::vector<int64_t> d, aclDataType dt, void* p) {
    std::vector<int64_t> s(d.size(), 1);
    for (int i = static_cast<int>(d.size()) - 2; i >= 0; --i) s[i] = s[i + 1] * d[i + 1];
    return aclCreateTensor(d.data(), d.size(), dt, s.data(), 0, ACL_FORMAT_ND, d.data(), d.size(), p);
}
static void Run(int64_t reduction, aclDataType sdt, aclDataType tdt, aclDataType odt, const char* tag) {
    void* ds = Dev(6 * 8); void* dt = Dev(6 * 8); void* doo = Dev(6 * 8);
    aclTensor* self = T({2, 3}, sdt, ds); aclTensor* target = T({2, 3}, tdt, dt);
    aclTensor* out = T({2, 3}, odt, doo);
    uint64_t ws = 0; aclOpExecutor* ex = nullptr;
    int rc1 = int(aclnnL1LossGetWorkspaceSize(self, target, reduction, out, &ws, &ex));
    printf("[%s] reduction=%lld GetWorkspaceSize = %d wsSize=%llu\n", tag, (long long)reduction, rc1, (unsigned long long)ws);
    aclDestroyTensor(self); aclDestroyTensor(target); aclDestroyTensor(out);
}
int main() {
    aclInit(nullptr); aclrtSetDevice(0);
    Run(0, ACL_INT64, ACL_INT64, ACL_INT64, "INT64 全同 reduction=none");
    Run(1, ACL_INT64, ACL_INT64, ACL_INT64, "INT64 全同 reduction=mean");
    Run(2, ACL_INT64, ACL_INT64, ACL_INT64, "INT64 全同 reduction=sum");
    Run(0, ACL_FLOAT, ACL_FLOAT, ACL_FLOAT, "FLOAT 基线 reduction=none");
    aclrtResetDevice(0); aclFinalize();
    return 0;
}

影响

调用方按 dtype 列判断「L1Loss 支持 INT64」并在 mean/sum 场景使用,会拿到 161002;而同一份文档没给出该组合非法的依据,排查会先怀疑 shape/broadcast 而绕过真正原因(reduction 与 dtype 的耦合)。属文档未披露实现限制,不是实现缺陷。

建议

优先在资料补一句 reduction 条件说明(改动最小、风险最低);若产品口径认为 INT64 本就只该在 none 下用,则把 dtype 列改为「FLOAT、FLOAT16、BFLOAT16(INT64 仅 reduction=none)」。

likedislike
yuning_chenyuning_chenCollaborators
16 days ago Assign yourealize as responsible person
yuning_chen
yuning_chenCollaborators
16 days ago Comments:

初步分析

感谢反馈,我们已开始核对这个问题。

现象理解:[Documentation|文档反馈]: aclnnL1Loss 资料声明 self/target/out 支持 INT64,但未注明仅 reduction=none 可用(mean/sum 实测 161002)。

当前判断:初步判断,待复现确认,还不能当成已确认根因。

涉及范围:根据标题与描述,先对照对应算子的实现/资料/校验路径排查。

下一步:我们会按描述构造用例复现,并对照代码与资料给出修复或文档修正方向。

likedislike
yuning_chen
yuning_chenCollaborators
16 days ago Comments:

您好,该问题已收到,当前问题 @yourealize 正在处理中

likedislike
yuning_chenyuning_chenCollaborators
12 days ago Assign yu-xinjie62 as responsible person, remove original responsible person: yourealize
yuning_chen
yuning_chenCollaborators
12 days ago Comments:

您好,该问题已收到,当前问题 @yu-xinjie62 正在处理中

likedislike
yuning_chenyuning_chenCollaborators
11 days ago Assign ji-songyuan as responsible person, remove original responsible person: yu-xinjie62
yuning_chen
yuning_chenCollaborators
11 days ago Comments:

您好,该问题已收到,当前问题 @ji-songyuan 正在处理中

likedislike
CANN-robotCANN-robotCollaborators
9 days ago Close issue
CANN-robotCANN-robotCollaborators
9 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
8 days ago Added label: resolved
chenjiayi_chenjiayi_Collaborators
3 days ago Assign chenjiayi_ as responsible person
chenjiayi_
chenjiayi_Collaborators
3 days ago Comments:

补充说明本问题的跟进安排:

该 issue 已关闭,已补充 assign 给 @chenjiayi_ 复核关闭结论,原责任人 @ji-songyuan 保留协同。

当前状态:

  • 关闭状态:已完成;复核项:aclnnL1Loss 资料声明 self/target/out 支持 INT64,但未注明仅 reduction=none 可用(mean/sum 实测 161002)。
  • 我先核对关闭时的结论与当前 master 的实现/资料是否一致。

下一步:

  • 复核完成后在本 issue 补充结论。
  • 如果还有后续需要,请重新提 issue。
likedislike
chenjiayi_
chenjiayi_Collaborators
3 days ago Comments:

补充说明本问题的后续处理:

已修复并随关联 PR 合入。

处理结果:

验证:

  • 关联 PR(2026-11-13)已合入,变更可从 PR 记录追溯。
  • 本次以 PR 记录与 issue 讨论核对为主,未重新执行复现或真机验证。

说明:合入分支与版本以 PR 记录为准;如仍有问题,请重新提 issue 并附版本、shape 与日志。

如果还有后续需要,请重新提 issue。

likedislike
chenjiayi_chenjiayi_Collaborators
19 hours ago Removed responsible person chenjiayi_