Merged
MhcPost接口增加ge converter,支持torch图模式,eager模式支持hRes缺省 #10570
MhcPost接口增加ge converter,支持torch图模式,eager模式支持hRes缺省 #10570
Merged
xuejinghuiAdd on Aug 25
xuejinghui
xuejinghuiCollaborators
Aug 25

描述

MhcPost算子增加ge converter,支持torch图模式,eager模式支持hRes缺省

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/4289

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for xuejinghui's contribution.)
xuejinghuixuejinghuiCollaborators
Aug 25 Created pull request, commit 895e325b
atomgit-bot
atomgit-bot
Aug 25 Comments:

变更摘要

本 PR 为 MhcPost 算子新增 GE(Graph Engine)converter,以支持 torch 图模式(graph mode)下的算子下沉执行。核心做法是新增 graph_convert_mhc_post.py 文件,通过 register_fx_node_ge_converter 将 torch.ops.cann_ops_transformer.mhc_post.default 注册到 GE 转换流程,并在 __init__.py 中导入该模块以确保注册生效;同时将 mhc_post.py 中原来通过 mhc_post_op_builder.load() 加载算子模块的调用方式,统一改为直接调用 torch.ops.cann_ops_transformer.mhc_post,使 eager 模式与图模式共用同一算子入口。

主要改动

  • 新增 GE converter 文件 graph_convert_mhc_post.py:新增 MhcPost 函数(带 auto_convert_to_tensor 装饰器),声明算子的 4 个输入(x、h_res、h_out、h_post)、输出 y 及各输入输出支持的数据类型(如 DT_BF16、DT_FLOAT16、DT_FLOAT),并通过 ge_op 与 IrDef 构建 GE 算子描述;同时用 try/except ImportError 包裹 torchair 相关导入并设置 _TORCHAIR_AVAILABLE 标志,兼容 torchair 不可用的环境。
  • 注册 FX 节点到 GE 的转换函数:通过 @register_fx_node_ge_converter(torch.ops.cann_ops_transformer.mhc_post.default) 注册 convert_mhc_post 函数,将 FX 图节点(x、hRes、hOut、hPost)映射到 MhcPost 算子,从而支持 torch 图模式。
  • 导出并注册新模块:在 torch_extension/__init__.py 中新增 from . import graph_convert_mhc_post,使新增的 converter 模块随扩展包自动加载。
  • 统一算子调用入口:在 mhc_post.py 中,将 MhcPostFunction.forward 和 mhc_post 函数里通过 mhc_post_op_builder.load() 获取模块再调用 mhc_post 的方式,改为直接调用 torch.ops.cann_ops_transformer.mhc_post,去掉对 OpBuilder 加载流程的依赖。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 25 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 25 Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to 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
mhc ✅ luwei_1104, 蒋礼锐, 马兵 (3/2) ✅ luwei_1104 (1/1)
sig-ops-transformer ✅ 马兵, 蒋礼锐 (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

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

likedislike
CANN-robot
CANN-robotCollaborators
Aug 25 Comments:

CLA Signature Pass

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

likedislike
94 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 31 Added label: api-check-pass
CANN-robotCANN-robotCollaborators
Aug 31 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 31 Added label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
Aug 31 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 31 Merged pull request