Merged
fix: 将5个eager算子编译延迟到dispatcher首次调用, import不再触发编译 #9734
weihao18Add on Aug 7
fix: 将5个eager算子编译延迟到dispatcher首次调用, import不再触发编译 #9734
Merged
weihao18Add on Aug 7
Merged fromDeleted :fix-issue-4154intocann/ops-transformermaster
weihao18
weihao18Collaborators
Aug 7

描述

fix: 将5个eager算子编译延迟到dispatcher首次调用, import不再触发编译

关联的Issue

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

测试

本地验证不触发编译

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for weihao18's contribution.)
weihao18weihao18Collaborators
Aug 7 Created pull request, commit 8a16a488
weihao18weihao18Collaborators
Aug 7 Associated issue: [torch_extension] import cann_ops_transformer 强制编译 5 个 eager 算子,影响首次加载耗时
atomgit-bot
atomgit-bot
Aug 7 Comments:

变更摘要

此 PR 将 5 个 eager 算子的编译时机从模块 import 阶段延迟到各算子 dispatcher 首次调用时,解决 import 即触发编译导致启动开销过大的问题(关联 Issue #4154)。核心做法是移除模块顶层立即执行的 OpBuilder.load() 调用,改为在对应的算子函数内部按需调用,确保只有在实际执行运算时才完成 JIT 编译加载。

主要改动

  • dense_lightning_indexer_softmax_lse.py: 移除模块级 op_module = ...load() 预加载,改为在 dense_lightning_indexer_softmax_lse_metadata 和 dense_lightning_indexer_softmax_lse 两个函数内部首次调用时才执行 load()。
  • inplace_partial_rotary_mul.py: 删除模块级 inplace_partial_rotary_mul_op_builder.load() 预加载调用及其注释,不再在 import 时触发编译。
  • inplace_partial_rotary_mul_backward.py: 删除模块级 inplace_partial_rotary_mul_backward_op_builder.load() 预加载调用及其注释,编译延迟到算子实际调用时。
  • moe_finalize_routing.py: 移除模块级 _op_module = ...load() 预加载,改为在 _moe_finalize_routing 函数内部按需执行 load()。
  • quant_flash_attn.py: 移除模块级 op_module = ...load() 预加载,改为在 quant_flash_attn_metadata 和 quant_flash_attn 两个函数内部首次调用时才执行 load()。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 7 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 7 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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
sig-ops-transformer ✅ 蒋礼锐, 刘丹 (2/2) ✅ 刘丹, 蒋礼锐 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
weihao18weihao18Collaborators
Aug 7 Modify description of pull request
CANN-robotCANN-robotCollaborators
Aug 7 Set monologue815,jiang-lirui,Allan_Yu,liudan12,mabing1118 as approver
CANN-robotCANN-robotCollaborators
Aug 7 Set monologue815,jiang-lirui,Allan_Yu,liudan12,mabing1118 as approver
weihao18
weihao18Collaborators
Aug 7 Comments:

compile

likedislike
weihao18weihao18Collaborators
Aug 7 Pre merge succeeded (commit_id: 596e5cc0e522d4c0a4df4ae68634334aa23f3853)
CANN-robotCANN-robotCollaborators
Aug 7 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Aug 7 Comments:

流水线任务触发成功
任务链接 [f9be1261f2b74f2795db7b4a29707dfe][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_classify ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
UT_Test_harmony-infer-chs-transformer ✅ SUCCESS
UT_Test_harmony-infer-cpro-transformer ✅ SUCCESS
UT_Test_report_lcov ⚠️ WARNING >>>>>

[2026-08-07 10:51:46]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Aug 7 Comments:

流水线任务触发成功
任务链接 [113fa35d0f5b414d967655727d1f2f63][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>

[2026-08-07 10:32:17]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Aug 7 Added label: api-check-pass
CANN-robotCANN-robotCollaborators
Aug 7 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 7 Added label: ci-pipeline-passed
weihao18weihao18Collaborators
Aug 7 Modify description of pull request
liudan12
liudan12Collaborators
Aug 7 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 7 Added label: approved
jiang-lirui
jiang-liruiCollaborators
Aug 7 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 7 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 7 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 7 Merged pull request