Closed
[Bug-Report|缺陷反馈]: aclnnClippedSwiglu out 形状/rank/dim 越界返回 561002,资料声明 161002(实测 561002) #7555
liuhanwen8Add on  24 days agoClosed at  4 days ago
liuhanwen8
liuhanwen8
24 days ago Create

[Bug-Report|缺陷反馈]: aclnnClippedSwiglu out 形状/rank/dim 越界返回 561002,资料声明 161002(实测 561002)

现象

aclnnClippedSwigluGetWorkspaceSize 对维度类非法入参返回 561002(内部 tiling 异常),
与资料错误码表声明的 ACLNN_ERR_PARAM_INVALID(161002)不符。第一段即返回,第二段不执行。

输入(x=fp32[2,32],dim=-1,alpha=1.702,limit=7.0,bias=1.0,interleaved=true) 两段返回 判定
out=fp32[2,16](在 dim 上减半,合法) 0 / 0 对照组
out=fp32[2,32](out 在 dim 上未减半) 561002 / 未执行 缺陷组 A
out=fp32[2](out rank 与 x 不一致) 561002 / 未执行 缺陷组 B
out=fp32[2,16]、dim=2(dim 等于 rank,越界) 561002 / 未执行 缺陷组 C
  • 资料锚点:activation/clipped_swiglu/docs/aclnnClippedSwiglu.md 错误码表 161002 的第 2 子项
    「输入或输出的参数维度不在支持的范围内」、第 3 子项「dim 不在指定的取值范围内」。
  • 实现锚点:host 侧未校验 out 的 rank 与 out[dim] 减半关系、dim 的取值范围,
    三类非法入参未被拦截,落到 clipped_swiglu_tiling.cpp 的 CheckY()(yDims != xDims_、
    y[cutDim] != xCutDimNum_/2)与 CheckAndGetXAndAttrs()(cutDim_ 越界)返回 GRAPH_FAILED,
    再由 aclnn 层统一包成 561002。
  • 同一 CheckY() 第 237 行取 dtype 用 context_->GetInputDesc(Y_INDEX)(Y_INDEX=0 即 x),
    yDtype != xDtype_ 恒为假,out 与 x dtype 一致性校验实际不生效。
  • 同族已记录 #7297(aclnnDeepNorm)、#7531(aclnnDynamicBlockQuantV2)。本 issue 是前向
    aclnnClippedSwiglu,校验点在 clipped_swiglu_tiling.cpp 的 CheckY() / CheckAndGetXAndAttrs(),
    与上述两条不是同一处代码。

期望

这两类非法入参应返回 161002,实测返回 561002。应得值有两个独立来源:① 上引本接口资料错误码表
把「参数维度」与「dim 取值」两类挂在 161002 下;② 仓内 docs/zh/context/aclnn_return_code.md 表 1/表 2 定义
ACLNN_ERR_PARAM_INVALID = 161002(参数校验错误)、ACLNN_ERR_INNER_TILING_ERROR = 561002
(API 内部做 tiling 时发生异常)。用户传入的 out 形状错误属参数问题,不属于 API 内部异常。

环境

  • 硬件:Atlas A2 训练系列(Ascend 910B2);CANN 26.1.1(ASCEND_HOME_PATH=/usr/local/Ascend/ascend-toolkit/latest)
  • 仓库/版本:cann/ops-nn master f769b5ed(2026-10-28 git fetch 后)。该提交下 clipped_swiglu_tiling.cpp 的校验点与上文一致,文件内 161002 / ACLNN_ERR_PARAM_INVALID 出现 0 次
  • 接口:aclnnClippedSwiglu(aclnnClippedSwigluGetWorkspaceSize + aclnnClippedSwiglu)

复现步骤

  1. 把下方代码保存为 repro.cpp。
  2. source $ASCEND_HOME_PATH/set_env.sh
  3. 编译:g++ -std=c++17 -O2 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase
  4. 运行:./repro
  5. 对照输出:第 1 行两段返回 0,第 2-4 行为 561002 且第二段不执行。

复现脚本

#include <acl/acl.h>
#include <aclnnop/aclnn_clipped_swiglu.h>
#include <cstdio>
#include <vector>

static aclTensor* mkT(void* d, std::vector<int64_t> sh, aclDataType dt) {
    std::vector<int64_t> st(sh.size());
    int64_t acc = 1;
    for (int i = (int)sh.size() - 1; i >= 0; --i) { st[i] = acc; acc *= sh[i] ? sh[i] : 1; }
    return aclCreateTensor(sh.data(), (uint64_t)sh.size(), dt, st.data(), 0,
                           ACL_FORMAT_ND, sh.data(), (uint64_t)sh.size(), d);
}

// x 固定 fp32[2,32];out 形状与 dim 按用例变;groupIndex 传 nullptr
static void run_case(const char* tag, void* dIn, void* dOut, std::vector<int64_t> outShape,
                     int64_t dim, aclrtStream s) {
    aclTensor* x = mkT(dIn, {2, 32}, ACL_FLOAT);
    aclTensor* out = mkT(dOut, outShape, ACL_FLOAT);
    uint64_t ws = 0;
    aclOpExecutor* ex = nullptr;
    int r1 = (int)aclnnClippedSwigluGetWorkspaceSize(x, nullptr, dim, 1.702, 7.0, 1.0, true, out, &ws, &ex);
    int r2 = -1;
    if (r1 == 0) {
        void* w = nullptr;
        if (ws > 0) { aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST); }
        r2 = (int)aclnnClippedSwiglu(w, ws, ex, s);
        aclrtSynchronizeStream(s);
        if (w) { aclrtFree(w); }
    }
    printf("[%s] GetWorkspaceSize = %d, Execute = %d\n", tag, r1, r2);
    aclDestroyTensor(x);
    aclDestroyTensor(out);
}

int main() {
    if (aclInit(nullptr) != ACL_SUCCESS) { printf("aclInit failed\n"); return 2; }
    aclrtSetDevice(0);
    aclrtStream s;
    aclrtCreateStream(&s);
    void *dIn = nullptr, *dOut = nullptr;
    aclrtMalloc(&dIn, 2 * 32 * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&dOut, 2 * 32 * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    run_case("对照组 ok out 2x16", dIn, dOut, {2, 16}, -1, s);
    run_case("缺陷组 out未减半 2x32", dIn, dOut, {2, 32}, -1, s);
    run_case("缺陷组 out rank=1", dIn, dOut, {2}, -1, s);
    run_case("缺陷组 dim=2", dIn, dOut, {2, 16}, 2, s);
    aclrtDestroyStream(s);
    aclrtResetDevice(0);
    aclFinalize();
    return 0;
}

实测输出(910B2 / CANN 26.1.1):

[对照组 ok out 2x16] GetWorkspaceSize = 0, Execute = 0
[缺陷组 out未减半 2x32] GetWorkspaceSize = 561002, Execute = -1
[缺陷组 out rank=1] GetWorkspaceSize = 561002, Execute = -1
[缺陷组 dim=2] GetWorkspaceSize = 561002, Execute = -1

影响

调用方按资料写 if (ret == 161002) 的参数错误分支收不到该错误,非法入参被报成 ACLNN_ERR_INNER_TILING_ERROR,与「算子包缺失 / tiling 内部故障」同类,无法区分调用方参数问题与环境故障;训练脚本里表现为难以定位的算子初始化失败。

建议

host 侧(op_api 适配层)补 out rank、out[dim] 减半关系、dim 取值范围的显式校验并返回 ACLNN_ERR_PARAM_INVALID;同时把 CheckY() 第 237 行的 context_->GetInputDesc(Y_INDEX) 改为输出描述符接口,使 out 与 x 的 dtype 一致性校验真正生效。

likedislike
liuhanwen8liuhanwen8
24 days ago Added label: bug-report
yuning_chen
yuning_chenCollaborators
24 days ago Comments:

初步分析

感谢反馈。

现象理解:
aclnnClippedSwiglu 在 out 形状/rank/dim 越界时返回 561002,资料声明 161002。

当前判断:初步判断,待复现确认。
偏参数非法由 tiling 上报内部码。

涉及范围:
clipped_swiglu 出参校验与错误码表。

下一步:
首段返回 161002 或资料声明 561002 场景。

likedislike
yuning_chenyuning_chenCollaborators
24 days ago Assign clwsy1 as responsible person
yuning_chen
yuning_chenCollaborators
24 days ago Comments:

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

likedislike
caorenleicaorenleiCollaborators
15 days ago Removed responsible person clwsy1
yuning_chenyuning_chenCollaborators
10 days ago Assign east_yang as responsible person
east_yangeast_yangCollaborators
10 days ago Assign shilulu as responsible person
east_yangeast_yangCollaborators
10 days ago Removed responsible person east_yang
east_yangeast_yangCollaborators
7 days ago Assign east_yang as responsible person
east_yangeast_yangCollaborators
7 days ago Removed responsible person shilulu
east_yang
east_yangCollaborators
7 days ago Comments:

/unassign @east_yang

likedislike
east_yang
east_yangCollaborators
7 days ago Comments:

/assign @shilulu
——assign by agent

likedislike
CANN-robotCANN-robotCollaborators
7 days ago Removed responsible person east_yang
CANN-robotCANN-robotCollaborators
7 days ago Assign shilulu as responsible person
shilulushiluluCollaborators
4 days ago Associated pull request
shilulu
shiluluCollaborators
4 days ago Comments:

感谢反馈,问题确认有效,资料已修正,见修复 PR:https://gitcode.com/cann/ops-nn/pull/14619。说明如下:

一、复现确认(910B3 + CANN 9.3.0)

  • out=[2,32](dim 轴未减半)、out=[2](rank 与 x 不一致)、dim=2(越界):三个用例均在第一段返回 561002,第二段不执行——与报告一致;
  • dtype 不匹配(x=fp32、out=fp16):第一段返回 161002;x=fp64:第一段返回 161002——dtype 类校验在 host 首段拦截,资料 161002 声明对该子项成立。

二、确认结论

维度与 dim 两类非法入参的校验位于 tiling 层(CheckY 的 rank 相等与 dim 轴减半校验、CheckAndGetXAndAttrs 的 dim 取值域校验),tiling 拒绝按框架约定包装为 561002(ACLNN_ERR_INNER_TILING_ERROR);资料将其声明在 161002
下与实际行为不符,属资料-实现不一致。dtype 子项由 host 首段校验返回 161002,声明正确。

报告补充指出的 CheckY 取 dtype 用 GetInputDesc(Y_INDEX)(导致 out 与 x dtype 一致性校验恒假)的问题:该问题已在 f134ef309(2026-10-28 内部错误码整改)中修正为 GetOutputDesc,报告基线(10-28 快照)早于该修复;且 dtype
一致性另有 host 首段校验(实测 161002),tiling 侧校验为二道防线。

三、修复内容

错误码表拆分(见修复 PR:https://gitcode.com/cann/ops-nn/pull/14619):

  • "数据类型不在支持的范围内"维持 161002;
  • "输入或输出的参数维度不在支持的范围内""dim 不在指定的取值范围内"拆分至 561002(ACLNN_ERR_INNER_TILING_ERROR),与 tiling 层校验的实际拦截行为一致,也与 V2 资料(aclnnClippedSwigluV2.md)已有口径对齐。

关于报告期望的"参数非法应统一 161002":参数维度/dim 取值类校验实施在 tiling 层,按框架约定归 561002 内部错误类,资料如实按此描述。

感谢支持。

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
4 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved