Closed
[Bug-Report|缺陷反馈]: SparseApplyAdadelta 更新公式运算顺序错误、tiling/infershape 缺少入参与溢出校验 #8581
renshuojianAdd on  11 days agoClosed at  9 days ago
renshuojian
renshuojianCollaborators
11 days ago Create

Describe the current behavior / 问题描述 (Mandatory / 必填)

SparseApplyAdadelta 算子存在以下缺陷:

  1. 更新公式运算顺序与参考实现不一致:kernel 侧 update 计算为 sqrtf(numer) * (g / sqrtf(denom)),先做除法再做乘法。当 denom 很大、g 很小时,g / sqrt(denom) 中间结果会下溢为 0 或产生明显精度偏差;与 README 公式及 TensorFlow 参考实现的 (sqrt(numer) / sqrt(denom)) * g 不等价。
  2. tiling 缺少输入合法性与溢出校验:对 kCount、varShapeSize 未做负值判断与乘法溢出检查(MulOverflow),未校验 var 秩非零、indices 为一维;核数计算使用较小位宽类型,大 shape 下存在溢出后 SetBlockDim 异常的风险。
  3. infershape 缺少输入合法性校验:未校验 var/accum/accum_update/grad/indices 秩至少为 1、accum/accum_update 与 var 逐维形状一致、indices 为一维、lr/rho/epsilon 为标量。非法输入不会返回 GRAPH_FAILED,而是进入后续流程,存在越界访问与结果错误风险。
  4. 主机侧标量读取冗余:tiling 通过 GetScalarFloat 读取 lr/rho/epsilon 并写入 SparseApplyAdadeltaTilingData,增加了 tiling 数据依赖与主机侧开销(属加固项,非功能缺陷)。

Environment Information / 环境信息 (Mandatory / 必填)

950

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 编译安装 ops-nn,确认 SparseApplyAdadelta 可正常调用。
  2. 问题 1(公式顺序/精度):构造 denom 极大(如 1e20)、grad 极小(如 1e-20)的输入执行算子,与 TF 参考实现对比 update 结果。
  3. 问题 2(tiling 校验):构造使 varShapeSize 乘积溢出的 shape,或将 kCount/varShapeSize 传入负值,观察 tiling 是否拦截。
  4. 问题 3(infershape 校验):分别构造以下非法输入并执行图模式 InferShape:
    • var 与 accum 形状不一致,如 var = [3, 4]、accum = [4, 4];
    • var 为 0 维标量;
    • indices 为 2 维;
    • lr/rho/epsilon 为非标量(如 1 维);
      观察是否返回失败。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

  1. update 按 (sqrt(numer) / sqrt(denom)) * g 计算,与 README 公式及 TF 参考实现一致,极小/极大值场景不出现中间商下溢与精度偏差。
  2. tiling 对 kCount、varShapeSize 的负值与乘法溢出进行拦截并返回明确错误码;var 秩非零、indices 一维校验不通过时直接失败;核数计算全程使用 int64 后再 SetBlockDim。
  3. infershape 对上述非法输入返回 GRAPH_FAILED,并输出明确的校验失败日志;合法输入形状推导结果保持不变。
  4. lr/rho/epsilon 由 kernel 直接从 GM 读取,tiling 不再下发对应标量字段,行为与精度不变。

// 问题 1:中间商下溢
grad/sqrt(denom) = 1e-20 / 1e10 = 0(下溢)
期望 (sqrt(numer)/sqrt(denom))*grad != 0
// 问题 2:溢出不拦截
kCount = -1 / varShapeSize 溢出,tiling 未返回失败
// 问题 3:非法形状未拦截
var=3,4, accum=4,4 -> infershape 未返回 GRAPH_FAILED
var 为 0 维 / indices 为 2 维 / lr 为 1 维 -> 未返回 GRAPH_FAILED

Special notes for this issue/备注 (Optional / 选填)

likedislike
renshuojianrenshuojianCollaborators
11 days ago Added label: bug-report
yuning_chenyuning_chenCollaborators
11 days ago Assign rsj007 as responsible person
CANN-robotCANN-robotCollaborators
9 days ago Close issue
CANN-robotCANN-robotCollaborators
9 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
9 days ago Added label: resolved