Closed
[Bug-Report|缺陷反馈]: aclnnGeluBackward 不校验出参 gradInput 的 dtype,INT8/INT32/BOOL 两段均返回 0 而非 161002 #7157
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:
感谢反馈,问题已确认并修复。
根因:与您的分析一致。CheckPromoteType 仅校验 gradOutput 与 self 的类型推导,gradInput 除判空外未被读取,出参 dtype 不在支持列表时两段均返回 0,契约中「类型推导结果与 gradInput 一致」的校验未实现。
修复:补齐出参 gradInput 的 dtype 白名单校验(FLOAT/FLOAT16/BFLOAT16,与资料参数表一致),不在列表内返回 161002。采用白名单而非「等于推导类型」的口径,以保持出参在支持列表内、依赖 Cast 兜底转换的现有合法用法不受影响。
修复已随 PR https://gitcode.com/cann/ops-nn/pull/13166 提交,请基于该 PR 验证。


22 days ago Close issue
22 days ago Added label: resolved
一、问题描述
aclnnGeluBackward对出参gradInput的 dtype 不做校验:传入资料明确不支持的INT8/INT32/BOOL时,aclnnGeluBackwardGetWorkspaceSize与aclnnGeluBackward两段均返回 0(ACLNN_SUCCESS),未按资料返回161002。资料(
activation/gelu_grad/docs/aclnnGeluBackward.md):gradInput的数据类型列只列了FLOAT、FLOAT16、BFLOAT16;gradOutput、self、gradInput的数据类型和数据格式不在支持的范围之内。实测该子项未被拦截。同接口的 shape 类非法入参是会被拦的(见下"边界确认"),所以这不是"整个校验都不生效",而是出参 dtype 这一路漏了。
二、环境信息
aclnnGeluBackward(gradOutput, self, gradInput, workspaceSize, executor)activation/gelu_grad/op_api/aclnn_gelu_backward.cpp(master)三、重现步骤
最小复现(
g++直编,不依赖任何测试框架;完整代码见附件repro_gelu_backward_output_dtype.cpp):source $ASCEND_HOME/set_env.sh g++ -std=c++17 repro_gelu_backward_output_dtype.cpp -o repro \ -I$ASCEND_HOME/include -I$ASCEND_HOME/aarch64-linux/include \ -L$ASCEND_HOME/aarch64-linux/lib64 -L$ASCEND_HOME/lib64 \ -lascendcl -lopapi -lnnopbase ./repro核心逻辑(生效部分):
// gradOutput / self 固定 fp32,shape=[8];只改 gradInput 的 dtype aclTensor* gradOutput = MakeTensor(devGrad, {8}, ACL_FLOAT); aclTensor* self = MakeTensor(devSelf, {8}, ACL_FLOAT); aclTensor* gradInput = MakeTensor(devOut, {8}, outDtype); // outDtype 依次取 FLOAT/INT8/INT32/BOOL uint64_t ws = 0; aclOpExecutor* ex = nullptr; aclnnStatus r1 = aclnnGeluBackwardGetWorkspaceSize(gradOutput, self, gradInput, &ws, &ex); if (r1 == 0) { r2 = aclnnGeluBackward(workspace, ws, ex, stream); }实测输出:
期望:后三行均为
161002。四、根因
activation/gelu_grad/op_api/aclnn_gelu_backward.cpp:60:static bool CheckPromoteType(const aclTensor* gradOutput, const aclTensor* self, const aclTensor* /* gradInput */) // ← 形参被注释掉 { op::DataType promoteType; if (!CheckPromoteTypeGeluBackward(gradOutput, self, promoteType, DTYPE_SUPPORT_LIST)) { return false; } return true; // ← 从不使用 gradInput }CheckPromoteTypeGeluBackward(common/inc/op_api/level2_base_nn.h:349)只做两件事:① 用
PromoteType(gradOutput->GetDataType(), self->GetDataType())推导 promote 类型;② 检查该 promote 类型在
DTYPE_SUPPORT_LIST内。gradInput除了判空之外没有被读取,因此CheckParams第 2 步注释所写的「检查gradOutput和self的dtype能否作类型推导, 类型推导后的结果需要与gradInput一致」
后半句实际未执行。
gradInput=int8时 promote 类型仍是 fp32,白名单自然通过。五、边界确认(排除误判)
同一套复现程序里追加的对照项,说明拦截机制本身是工作的、只缺出参 dtype 这一路:
gradInputshape[3x5](与 self[8]不匹配)selfshape[16](与 gradOutput[8]不匹配)gradOutput/self/gradInput任一为 nullptrgradInputdtypeINT8/INT32/BOOL两条确定性开关腿(默认 / ACL 确定性开启)行为一致,均返回 0。
六、影响
出参 dtype 配错时接口层不给任何信号,两段都返回 0。调用方把 fp32 梯度缓冲误声明成整型时,
错误要到后续消费环节才可能暴露,且难以归因到接口契约。属「契约承诺的拦截未兑现」,
不影响合法路径的正确性。
七、建议修复
在
CheckPromoteType(或新增CheckGradInputDtype)里补齐出参校验,二选一:gradInput->GetDataType()必须等于promoteType;gradInput->GetDataType()必须在DTYPE_SUPPORT_LIST内。任一不满足返回
ACLNN_ERR_PARAM_INVALID(161002)。建议顺带补 UT:gradInput取INT8/INT32/BOOL各一条,断言首段返回 161002。八、日志与验证
aclnnStatus直接打印,未经任何包装;ascend-op-error-scenario线(资料错误码子项单点变异)在两腿各命中 2 条ACCEPTED后发现,再用上述独立 C 程序逐 dtype 复核确认。