Pull Request已成功合入, 合并人@CANN-robot
(感谢 杨金翰50065292 的贡献)变更摘要
本 PR 将 canndev 仓库中4个算子的 host fallback 实现迁移至 ops-nn 仓库,为 AscendQuantV2、AscendAntiQuantV2、DynamicQuant 和 EmbeddingDenseGrad 新增基于 aclnn API 的 CPU 回退执行能力。主要工作是新增4个 *_fallback.cpp 文件,统一替换头文件引用、宏定义和版权声明,保持核心执行逻辑与 canndev 源实现一致。
主要改动
- 新增
EmbeddingDenseGradfallback 实现: 在index/embedding_dense_grad/op_graph/embedding_dense_grad_fallback.cpp中实现EmbeddingDenseGradHostExecuteFunc,通过EXEC_OPAPI_CMD调用aclnnEmbeddingDenseBackward,从输入中获取 grad 和 indices 张量以及numWeight、paddingIdx、scaleGrad属性,并通过IMPL_OP(EmbeddingDenseGrad)完成算子注册。 - 新增
AscendAntiQuantV2fallback 实现: 在quant/ascend_anti_quant_v2/op_graph/ascend_anti_quant_v2_fallback.cpp中实现AntiQuantHostExecuteFunc,调用aclnnAscendAntiQuant,支持dstDtype和sqrt_mode属性,offset 作为可选输入,通过IMPL_OP(AscendAntiQuantV2)注册。 - 新增
AscendQuantV2fallback 实现: 在quant/ascend_quant_v2/op_graph/ascend_quant_v2_fallback.cpp中实现AscendQuantHostExecuteFunc,调用aclnnAscendQuant,支持sqrtMode(bool)、roundMode(char*)和dstDtype(int32_t)三种属性,通过IMPL_OP(AscendQuantV2)注册。 - 新增
DynamicQuantfallback 实现: 在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命名空间下。


代码审查
审查总结
审查覆盖情况
| 文件 | 审查结果 |
|---|---|
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 |
⛔ 需要修改


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


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.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
从 canndev 仓库迁移 fallback 实现至 ops-nn,为 4 个算子新增 host fallback 执行能力(均通过 CANN_OPS_OPB_SYN_EXEC_ACLNN 调用 aclnn API,并以 IMPL_OP(...).OpExecuteFunc(...) 注册执行函数):
aclnnAscendQuant,入参 x/scale/offset,属性 sqrt_mode/round_mode/dst_dtype。aclnnAscendAntiQuant,入参 x/scale/offset,属性 dst_dtype/sqrt_mode。aclnnDynamicQuantV2,入参 x/smooth_scales/group_index。aclnnEmbeddingDenseBackward,入参 grad/indices 等。主要改动:
*_fallback.cpp,统一使用op_fallback.h头文件与OP_CHECK_IF错误处理宏。*_fallback.cpp,无需修改构建配置。关联的Issue
测试
已完成以下静态检查:
fallback_common.h、fallback_opapi.h、op_log.h和旧版OP_CHECK残留。git diff --check检查通过。本地环境缺少完整的 CANN 构建工具链,编译和运行验证待 CI 完成。
文档更新
无,本 PR 仅新增算子 fallback 实现文件。
类型标签
AI/Agent生成声明