已合并
fix(op-plugin): identity round for integers; delegate round_ to round.out for op_api. #4917
Margaret_wangrui创建于 5月9日
fix(op-plugin): identity round for integers; delegate round_ to round.out for op_api. #4917
已合并
Margaret_wangrui创建于 5月9日
Margaret_wangrui
5月9日

【合入来源】

如有社区 issue,请关联 issue 链接:

请勿携带内部流程信息(需求链接、问题单、内部 issue 等)
https://gitcode.com/Ascend/pytorch/issues/1873

[Bug]: aclnnInplaceRound / aclnnRound 与整数 dtype 在 PyTorch test_meta 等场景下的语义对齐

类型勾选(请按实际保留一项):


【修改方案】

CANN aclnnRound / aclnnInplaceRound 对部分整数 dtype(典型为 int8 / int16 / uint8)不支持或行为与 Pyorch 不一致,而在 transfer_to_npu、调用 test_meta.py*_round_cuda_* 用例 时会经 op_api 落到上述 aclnn 算子,导致失败。PyTorch 对整数张量round / round_ 语义为恒等(无小数可取整),应与 CPU 一致。

  1. acl_op 路径(RoundKernelNpu.cpp
    • 增加 round_integral_identityat::isIntegralType(self.scalar_type(), false)(与 CPU 一致,排除 bool)。
    • round_out:整数分支经 copy_ 及既有 NPU format/contiguous 处理写回 out不再调用 OpCommand("Round")
    • round:整数返回 self.clone();非整数保持原路径。
    • round_ 仍通过 round_out(self, self),in-place 覆盖整数场景。
  2. op_api 路径(op_plugin_functions.yaml + torchnpugen 生成)
    • round.outgen_opapi 增加 integral_identity_tensor: self,在生成体最前插入整数早退,直接 acl_op::round_out,避免整数走 aclnnRound
    • round_gen_opapiexec: aclnnInplaceRound 改为 structured_inherit: round.out,生成 round_out(self, self),统一走带整数早退的 round_out,避免整数调用 aclnnInplaceRound
  3. 代码生成(torchnpugen/struct/model.pystruct_codegen.py
    • StructInfo.integral_identity_tensor;从 gen_opapi pop,避免参与 out 结果字段校验。
    • INTEGRAL_IDENTITY_GUARD 写入 StructKernelNpuOpApi.cppACLNN_EXTENSION 分支补充 #include <ATen/native/TypeProperties.h>

说明: round(..., decimals=...)aclnnRoundDecimals / RoundDecimalsKernelNpuOpApi)本 PR 不涉及

交互关系: 运行时调度 → op_api(生成)acl_op;整数 round 在 op_api 早退回 acl_op::round_outYAML ↔ torchnpugen ↔ StructKernelNpuOpApi.cpp 为构建期关系。


【资料变更】

不涉及(若对外需声明「NPU 上整数 round 与 PyTorch 一致为恒等」,可由资料接口人另单跟踪。)


【接口变更】

不涉及

未新增/变更 Python API;torch.round / tensor.round_(无 decimals 重载)对外语义与 PyTorch 对齐,属实现修正。


【功能验证】

场景

  • 整数 dtype 在 NPU 上执行 roundround_、与 round.out 一致的 out 语义(由 op 组合覆盖)。
  • 浮点回归: round 仍走 CANN / 原路径。

方法

  • 运行 test_meta.py 中与 inplace_round 相关的 int8 / int16 / uint8 等用例(若环境将 cuda 设备映射为 npu)。
  • 运行本仓 test/test_base_ops/test_round.pytest_round_integer_identity_npu

UT

  • 已增加 test_round_integer_identity_npu,覆盖 int8 / uint8 / int16 / int32 / int64
    image.png

【CheckList】

(请提交人将 [ ] 改为 [x] 并自检)

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Margaret_wangrui 的贡献)
Margaret_wangruiMargaret_wangrui
5月9日 创建了 pull request,commit 60d9b708
ascend-robot
ascend-robot成员
5月9日 评论:

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-Ascend/op-plugin wangmin0104, sunyu-xuan (2/2) wangmin0104 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
ascend-robotascend-robot成员
5月9日 添加了label:ascend-cla/yes
Margaret_wangruiMargaret_wangrui
5月9日 修改了pull request 的描述
此处折叠了116条消息 查看更多
ascend-robot
ascend-robot成员
5月15日 评论:
流水线 PR-pipeline_op-plugin#1144 (重试第2次) [ commitID:c24d951e ] 已完成
>>>代码风格自动修复执行失败,具体请查看日志,不影响流水线执行及PR合入
阶段 任务名 状态 详情
编译构建 Build_master_ARM >>>
Build_v2_7_1_ARM >>>
Build_v2_9_0_ARM >>>
Build_v2_10_0_ARM >>>
Build_v2_11_0_ARM >>>
Build_master_x86 >>>
Build_v2_7_1_x86 >>>
Build_v2_9_0_x86 >>>
Build_v2_10_0_x86 >>>
Build_v2_11_0_x86 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
开源片段检查 SCA >>>
开发者测试 UT_master_ARM >>>
UT_v2_7_1_ARM >>>
UT_v2_9_0_ARM >>>
UT_v2_10_0_ARM >>>
UT_v2_11_0_ARM >>>
流水线 PR-pipeline_op-plugin >>>
此流水线已支持下列评论快捷指令,仅PR创建者评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
sunyu-xuan成员
5月15日 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
5月15日 添加了label:lgtm
ascend-robot
ascend-robot成员
5月15日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: wangmin0104.
Reviewers who wrote a comment of /lgtm are: sunyu-xuan, wangmin0104.

likedislike
ascend-robotascend-robot成员
5月15日 合入了pull request