Pull Request has been successfully merged by CANN-robot.
(Thank you for xuejinghui's contribution.)变更摘要
本 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加载流程的依赖。


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


描述
MhcPost算子增加ge converter,支持torch图模式,eager模式支持hRes缺省
关联的Issue
https://gitcode.com/cann/ops-transformer/issues/4289
测试
文档更新
类型标签