已关闭
[Bug-Report|缺陷反馈]: Relu6Grad 等 10 个算子未注册 InferDataType,GE 图通路输出 dtype 缺少推导来源 #5417
zl_hw创建于  23 天前关闭于  22 天前
zl_hw成员
23 天前 创建

Describe the current behavior / 问题描述

Relu6Grad、LambApplyOptimizerAssign、LambApplyWeightAssign、LambNextMV、LambNextMVWithDecay、LambNextRight、LambUpdateWithLr、LambUpdateWithLrV2、MultilabelMarginLoss、PoissonNllLoss 这 10 个算子,在各自的 op_host/*_infershape.cpp 中只做了 IMPL_OP_INFERSHAPE(<OpType>).InferShape(...) 注册,没有注册 InferDataType;在 op_graph/ 下也没有 IMPL_OP(<OpType>).InferDataType(...) 的注册。

这 10 个算子的 op_graph 原型、op_host def 与 op_kernel 均齐全,属于有 GE 图通路的算子,因此图编译时其输出 dtype 缺少显式推导来源。

对照:以当前 master 基线计,仓内 op_host 的 IMPL_OP_INFERSHAPE(...).InferDataType(...) 写法共 323 个文件,op_graph 的 IMPL_OP(...).InferDataType(...) 写法共 90 个文件,本批 10 个算子两种写法均无。

Environment / 环境信息

  • 代码仓:cann/ops-nn,master 分支
  • 复现基线:b405035cb(fix(bnll): improve log1p precision)
  • 复现环境:x86_64 Ubuntu,gcc 13.3.0,使用仓内 op_host UT 框架(build.sh -u --ophost --soc=ascend950
  • 说明:该问题位于算子注册面(op_host / op_graph 的 InferDataType 注册),与具体昇腾硬件型号无关,影响所有注册了上述算子的产品形态

Steps to reproduce the issue / 重现步骤

  1. 检出 cann/ops-nn master(基线 b405035cb

  2. 对上述任一算子检查注册面,例如:

grep -n "InferDataType" activation/relu6_grad/op_host/relu6_grad_infershape.cpp
grep -rn "InferDataType" activation/relu6_grad/op_graph/

两条命令均无输出,即该算子既没有在 op_host 也没有在 op_graph 注册 InferDataType。其余 9 个算子(optim/lamb_*loss/multilabel_margin_lossloss/poisson_nll_loss)同理。

  1. 在 UT 中从注册表取该算子实现:
auto opImpl = gert::OpImplRegistry::GetInstance().GetOpImpl("Relu6Grad");
// opImpl->infer_datatype 为 nullptr

Describe the expected behavior / 预期结果

这 10 个算子应注册 InferDataType,即 gert::OpImplRegistry::GetInstance().GetOpImpl("<OpType>")->infer_datatype 非空,且各输出的 dtype 按算子语义正确推导。其中 MultilabelMarginLoss 的 is_target 输出应推导为 INT32(跟随 target),不能跟随 x,否则图上会把 INT32 的 is_target 推成浮点。

修复前,上述 grep 命令无任何输出(即无 InferDataType 注册)。

修复后,bash build.sh -u --ophost --soc=ascend950 --ops=<上述 10 个算子> 的执行结果:

[==========] 116 tests from 19 test suites ran.
[  PASSED  ] 116 tests.

[       OK ] relu6grad.relu6grad_infer_datatype
[       OK ] MultilabelMarginLossInferShapeTest.multilabelmarginloss_infer_datatype
[       OK ] PoissonNllLossInfershapeTest.poissonnllloss_infer_datatype
[       OK ] LambApplyOptimizerAssignProtoTest.lambapplyoptimizerassign_infer_datatype
[       OK ] LambApplyWeightAssignProtoTest.lambapplyweightassign_infer_datatype
[       OK ] LambNextMVProtoTest.lambnextmv_infer_datatype
[       OK ] LambNextMVWithDecayProtoTest.lambnextmvwithdecay_infer_datatype
[       OK ] LambNextRightProtoTest.lambnextright_infer_datatype
[       OK ] LambUpdateWithLrProtoTest.lambupdatewithlr_infer_datatype
[       OK ] LambUpdateWithLrV2ProtoTest.lambupdatewithlrv2_infer_datatype

新增用例中的 ASSERT_NE(dataTypeFunc, nullptr) 即为该注册生效的直接证据。

Special notes for this issue / 备注

  • 修复 PR:https://gitcode.com/cann/ops-nn/pull/9616
  • NormalizeBBox 经复查确认不属于本批缺失范围:它已在 vfusion/normalize_bbox/op_graph/normalize_bbox_graph_infer.cpp 中以 IMPL_OP(NormalizeBBox).InferDataType(...) 注册,只是没有写在 IMPL_OP_INFERSHAPE 块里
  • 本 Issue 与对应 PR 的验证均止于 op_host UT 层,未做真机与 GE 图 e2e 验证
likedislike
Zzl_hw成员
23 天前 添加了label:bug-report
yuning_chenyuning_chen成员
23 天前 将 zl_hw 设为负责人
CANN-robotCANN-robot成员
22 天前 关闭了 issue
CANN-robotCANN-robot成员
22 天前 添加了label:resolved