Closed
[Bug-Report|缺陷反馈]: aclnnSwiGluGrad 缺形状/dim 校验:dim 非法返回 561002、yGrad 未减半被静默接受 #7173
liuhanwen8Add on Oct 22Closed at 22 days ago
yuning_chen
Oct 22 Comments:
Oct 22 Comments:
Oct 22 Assign shilulu as responsible person
yuning_chen
Oct 22 Comments:
Oct 22 Comments:
您好,该问题已收到,当前问题 @east_yang 处理中


Oct 22 Removed responsible person shilulu
Oct 22 Assign east_yang as responsible person
24 days ago Assign shilulu as responsible person
24 days ago Removed responsible person east_yang
shilulu
22 days ago Comments:
22 days ago Comments:
感谢反馈,问题已确认并处理。
核对结论:dim 越界、dim 维不能被 2 整除两类输入,校验位于 tiling 层(SetTotalShape),失败后由框架统一映射为 ACLNN_ERR_INNER_TILING_ERROR(561002)——这是所有生成式接入算子的统一行为,因此将资料错误码表对齐为 561002(原161002 声明有误)。yGrad 未减半场景原实现确实静默接受,存在按错误形状计算与越界读风险,已在资料错误码表补充该约束声明(yGrad 与 x 形状不匹配 → 561002),对应的 tiling 层形状校验代码随另一个 PR 合入,合入后该场景不再静默。
修复已随 PR https://gitcode.com/cann/ops-nn/pull/13166 提交(资料部分),请基于该 PR 及后续 tiling PR 验证。


22 days ago Close issue
22 days ago Added label: resolved
Describe the current behavior / 问题描述 (Mandatory / 必填)
aclnnSwiGluGrad(yGrad, x, dim, out)有两处参数校验缺失,实测(Atlas A2 910B2 / CANN 9.2.0-beta.2):yGrad=[2x4]、x=[2x8]、dim=1dim=5x=[2x7]、yGrad=[2x3]、dim=1yGradfp16、其余 fp32outfp16、其余 fp32yGrad=[2x8]、x=[2x8]、dim=1两个问题:
实测把 tiling 失败(
ACLNN_ERR_INNER_TILING_ERROR)透出给调用方,无法区分"参数写错"与"算子内部故障"。yGrad的形状约束既没写进资料、也没校验。接口语义要求yGrad在dim维恰为x的一半(公式
out_A = yGrad*(s+s(1-s)A)*B里 A、B 各是 x 的一半),但资料错误码表只有三条(空指针 / dtype / dim),完全没有这一条;实测传
yGrad与x同形时两段都返回 0,即按错误的形状静默算完。这类输入会让内核按 x 的元素数去读 yGrad(越界读)或按半形错位计算结果。
Environment Information / 环境信息 (Mandatory / 必填)
activation/swi_glu_gradactivation/swi_glu_grad/docs/aclnnSwiGluGrad.mdSteps to reproduce the issue / 重现步骤 (Mandatory / 必填)
保存为
repro.cpp,source $ASCEND_HOME_PATH/set_env.sh后编译运行(只依赖 acl):g++ -std=c++17 repro.cpp -I${ASCEND_HOME_PATH}/include \ -L${ASCEND_HOME_PATH}/lib64 -lascendcl -lnnopbase -lopapi -o repro && ./repro// aclnnSwiGluGrad:dim 非法应 161002,yGrad 未减半应被拒绝 #include <cstdio> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_swi_glu_grad.h" static int64_t Numel(const std::vector<int64_t>& s) { int64_t n = 1; for (auto v : s) { n *= v; } return n; } static aclTensor* Make(const std::vector<int64_t>& shape, void** dev) { int64_t bytes = Numel(shape) * 4; if (aclrtMalloc(dev, bytes, ACL_MEM_MALLOC_HUGE_FIRST) != ACL_SUCCESS) { return nullptr; } std::vector<int64_t> strides(shape.size(), 1); for (int64_t i = static_cast<int64_t>(shape.size()) - 2; i >= 0; --i) { strides[i] = shape[i + 1] * strides[i + 1]; } return aclCreateTensor(shape.data(), shape.size(), ACL_FLOAT, strides.data(), 0, ACL_FORMAT_ND, shape.data(), shape.size(), *dev); } static void Case(const char* tag, const std::vector<int64_t>& g, const std::vector<int64_t>& x, int64_t dim, aclrtStream stream) { void *dg = nullptr, *dx = nullptr, *dz = nullptr; aclTensor* tg = Make(g, &dg); aclTensor* tx = Make(x, &dx); aclTensor* tz = Make(x, &dz); uint64_t ws = 0; aclOpExecutor* exec = nullptr; auto rc1 = aclnnSwiGluGradGetWorkspaceSize(tg, tx, dim, tz, &ws, &exec); if (rc1 != ACL_SUCCESS) { printf("%-40s 第一段 rc=%d\n", tag, rc1); } else { void* wsa = nullptr; if (ws > 0) { aclrtMalloc(&wsa, ws, ACL_MEM_MALLOC_HUGE_FIRST); } auto rc2 = aclnnSwiGluGrad(wsa, ws, exec, stream); auto rc3 = aclrtSynchronizeStream(stream); printf("%-40s 第一段 0,第二段 rc=%d sync=%d\n", tag, rc2, rc3); if (wsa != nullptr) { aclrtFree(wsa); } } aclDestroyTensor(tg); aclDestroyTensor(tx); aclDestroyTensor(tz); aclrtFree(dg); aclrtFree(dx); aclrtFree(dz); } int main() { aclInit(nullptr); aclrtSetDevice(0); aclrtStream stream = nullptr; aclrtCreateStream(&stream); Case("对照 yGrad[2x4] x[2x8] dim=1", {2, 4}, {2, 8}, 1, stream); Case("dim=5 越界(应 161002)", {2, 4}, {2, 8}, 5, stream); Case("x[2x7] 不能被 2 整除(应 161002)", {2, 3}, {2, 7}, 1, stream); Case("yGrad 未减半 [2x8](应拒绝)", {2, 8}, {2, 8}, 1, stream); aclrtDestroyStream(stream); aclrtResetDevice(0); aclFinalize(); return 0; }实测输出:
error-scenario 线独立复现了第一条:
NV-SwiGluGrad-161002-2 MISMATCH expect=161002 got=561002。Describe the expected behavior / 预期结果 (Mandatory / 必填)
dim < -x.dim() || dim >= x.dim()或x.size(dim) % 2 != 0→ 第一段返回ACLNN_ERR_PARAM_INVALID(161002),与资料 161002-3 一致;
yGrad.dim() != x.dim()或yGrad.size(dim) * 2 != x.size(dim)→ 161002(并建议把这条约束补进资料的错误码表 —— 现在资料里没有这一条)。
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
Special notes for this issue/备注 (Optional / 选填)
SwiGlu相关条目,未见本条。aclnnSituGluGrad有同类问题(dim 非法返回 561002),已另提 issue。yGrad未减半这一条比错误码更值得注意:结果静默错误,且资料没声明这个约束,调用方即使照资料写也会踩到。建议同时补资料与
CheckParams。