已合并
feat: 新增AscendQuantV2/AscendAntiQuantV2/DynamicQuant/EmbeddingDenseGrad算子host fallback支持 #8392
杨金翰50065292创建于 8月7日
feat: 新增AscendQuantV2/AscendAntiQuantV2/DynamicQuant/EmbeddingDenseGrad算子host fallback支持 #8392
已合并
杨金翰50065292创建于 8月7日
杨金翰50065292
杨金翰50065292成员
8月7日

描述

从 canndev 仓库迁移 fallback 实现至 ops-nn,为 4 个算子新增 host fallback 执行能力(均通过 CANN_OPS_OPB_SYN_EXEC_ACLNN 调用 aclnn API,并以 IMPL_OP(...).OpExecuteFunc(...) 注册执行函数):

  • AscendQuantV2(quant/ascend_quant_v2/op_graph/ascend_quant_v2_fallback.cpp):调用 aclnnAscendQuant,入参 x/scale/offset,属性 sqrt_mode/round_mode/dst_dtype。
  • AscendAntiQuantV2(quant/ascend_anti_quant_v2/op_graph/ascend_anti_quant_v2_fallback.cpp):调用 aclnnAscendAntiQuant,入参 x/scale/offset,属性 dst_dtype/sqrt_mode。
  • DynamicQuant(quant/dynamic_quant/op_graph/dynamic_quant_fallback.cpp):调用 aclnnDynamicQuantV2,入参 x/smooth_scales/group_index。
  • EmbeddingDenseGrad(index/embedding_dense_grad/op_graph/embedding_dense_grad_fallback.cpp):调用 aclnnEmbeddingDenseBackward,入参 grad/indices 等。

主要改动:

  • 各算子 op_graph 目录新增 *_fallback.cpp,统一使用 op_fallback.h 头文件与 OP_CHECK_IF 错误处理宏。
  • 版权声明更新为 CANN Open Software License Agreement Version 2.0。
  • 现有 CMake 自动收集 *_fallback.cpp,无需修改构建配置。

关联的Issue

测试

已完成以下静态检查:

  • 确认不存在 fallback_common.h、fallback_opapi.h、op_log.h 和旧版 OP_CHECK 残留。
  • 确认 4 个算子的执行函数、CANN_OPS_OPB_SYN_EXEC_ACLNN 调用和 IMPL_OP 注册均存在。
  • git diff --check 检查通过。

本地环境缺少完整的 CANN 构建工具链,编译和运行验证待 CI 完成。

文档更新

无,本 PR 仅新增算子 fallback 实现文件。

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 杨金翰50065292 的贡献)
杨金翰50065292杨金翰50065292成员
8月7日 创建了 pull request,commit 6d961b6c
atomgit-bot
atomgit-bot
8月7日 评论:

变更摘要

本 PR 将 canndev 仓库中4个算子的 host fallback 实现迁移至 ops-nn 仓库,为 AscendQuantV2、AscendAntiQuantV2、DynamicQuant 和 EmbeddingDenseGrad 新增基于 aclnn API 的 CPU 回退执行能力。主要工作是新增4个 *_fallback.cpp 文件,统一替换头文件引用、宏定义和版权声明,保持核心执行逻辑与 canndev 源实现一致。

主要改动

  • 新增 EmbeddingDenseGrad fallback 实现: 在 index/embedding_dense_grad/op_graph/embedding_dense_grad_fallback.cpp 中实现 EmbeddingDenseGradHostExecuteFunc,通过 EXEC_OPAPI_CMD 调用 aclnnEmbeddingDenseBackward,从输入中获取 grad 和 indices 张量以及 numWeight、paddingIdx、scaleGrad 属性,并通过 IMPL_OP(EmbeddingDenseGrad) 完成算子注册。
  • 新增 AscendAntiQuantV2 fallback 实现: 在 quant/ascend_anti_quant_v2/op_graph/ascend_anti_quant_v2_fallback.cpp 中实现 AntiQuantHostExecuteFunc,调用 aclnnAscendAntiQuant,支持 dstDtype 和 sqrt_mode 属性,offset 作为可选输入,通过 IMPL_OP(AscendAntiQuantV2) 注册。
  • 新增 AscendQuantV2 fallback 实现: 在 quant/ascend_quant_v2/op_graph/ascend_quant_v2_fallback.cpp 中实现 AscendQuantHostExecuteFunc,调用 aclnnAscendQuant,支持 sqrtMode(bool)、roundMode(char*)和 dstDtype(int32_t)三种属性,通过 IMPL_OP(AscendQuantV2) 注册。
  • 新增 DynamicQuant fallback 实现: 在 quant/dynamic_quant/op_graph/dynamic_quant_fallback.cpp 中实现 DynamicQuantExecuteFunc,调用 aclnnDynamicQuantV2,支持 smooth_scales 和 group_index 两个可选输入,输出 y 和 scale 两个张量,通过 IMPL_OP(DynamicQuant) 注册。
  • 统一迁移规范: 所有新增文件均包含 "op_fallback.h" 头文件,使用 OP_CHECK_IF 宏替代旧版 OP_CHECK,采用 CANN Open Software License Agreement Version 2.0 版权声明,并置于 fallback 命名空间下。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月7日 评论:

代码审查

审查总结

审查覆盖情况

文件 审查结果
index/embedding_dense_grad/op_graph/embedding_dense_grad_fallback.cpp 发现问题(P1×1, P3×2)
quant/ascend_anti_quant_v2/op_graph/ascend_anti_quant_v2_fallback.cpp 发现问题(P1×1, P3×2)
quant/ascend_quant_v2/op_graph/ascend_quant_v2_fallback.cpp 发现问题(P1×1, P3×2)
quant/dynamic_quant/op_graph/dynamic_quant_fallback.cpp 发现问题(P3×1)

按优先级统计

  • P1:3 个 — GetAttrPointer 返回值未做空指针检查即解引用(embedding_dense_grad_fallback.cpp、ascend_anti_quant_v2_fallback.cpp、ascend_quant_v2_fallback.cpp 各一个)
  • P3:7 个 — 日志拼写错误 "faild" → "failed"(4 个文件各一个)+ 日志 tag 大小写不一致(embedding_dense_grad_fallback.cpp、ascend_anti_quant_v2_fallback.cpp、ascend_quant_v2_fallback.cpp 各一个)

整体风险评估

中等风险。核心问题是在 3 个文件中 GetAttrPointer 返回值未经空指针检查即解引用,这与代码库中广泛使用的 OP_CHECK_NULL_WITH_CONTEXT 惯用模式不一致。若运行时属性缺失,将导致段错误崩溃。dynamic_quant_fallback.cpp 不涉及 GetAttrPointer 调用,无此问题。其余为低影响的日志拼写和一致性问题,不影响功能正确性。建议优先修复 P1 空指针检查问题后再合入。

类型 数量
🔴 阻塞 3
🟡 建议 0

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
8月7日 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
8月7日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
index ✅ 王星, 陈琦 (2/2) ✅ 王星 (1/1)
quant ✅ 陈琦, 王星 (2/2) ✅ 王星 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Ruyue1550, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了142条消息 查看更多
CANN-robot
CANN-robot成员
8月18日 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Eesok11成员
8月18日 解决了最后一个问题
CANN-robotCANN-robot成员
8月18日 关闭了关联的issue
CANN-robotCANN-robot成员
8月18日 合入了pull request
CANN-robot
CANN-robot成员
8月18日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike