Merged
CANN开发者共建计划-精简 ask_gutenocr_3b.py 预热循环中完全重复的 if/else 分支 #1145
CANN开发者共建计划-精简 ask_gutenocr_3b.py 预热循环中完全重复的 if/else 分支 #1145
Merged
jude_pixelAdd on 1 day ago
jude_pixel
jude_pixel
1 day ago

移除了 modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py(L293-L302)预热循环里 if args.batch > 1: 与 else: 执行完全相同语句的冗余条件判断,直接调用 model.generate(**inputs, max_new_tokens=10, do_sample=False)。

本地已通过 py_compile、ast.parse 和 ruff 增量检查,保持原逻辑不变。

修改补丁

查看完整 unified diff
diff --git a/modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py b/modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py
index e4cc71e..29cc6a5 100644
--- a/modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py
+++ b/modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py
@@ -293,10 +293,7 @@ logging.info("\n[Inference]")
 logging.info(f"Warmup ({args.warmup} iters)...")
 with torch.no_grad():
     for i in range(args.warmup):
-        if args.batch > 1:
-            outputs = model.generate(**inputs, max_new_tokens=10, do_sample=False)
-        else:
-            outputs = model.generate(**inputs, max_new_tokens=10, do_sample=False)
+        outputs = model.generate(**inputs, max_new_tokens=10, do_sample=False)
         torch.npu.synchronize()
         if i % 5 == 0 or i == args.warmup - 1:
             logging.info(f"  Warmup {i+1}/{args.warmup}")

Closes #442

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for jude_pixel's contribution.)
jude_pixeljude_pixel
1 day ago Created pull request, commit f5c81b20
jude_pixeljude_pixel
1 day ago Associated issue: CANN开发者共建计划--pypto-gym ask_gutenocr_3b.py 预热推理循环存在完全一致的 if/else 重复分支
CANN-robot
CANN-robotCollaborators
1 day ago Comments:

Hi @lvyelong12, welcome to submitting your first PR to CANN!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.
%!(EXTRA string=https://atomgit.com/cann/community/blob/master/en/sig-infrastructure/command.md)

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
1 day ago 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
repo-cann/pypto-gym ✅ liulufang_gitcode, congqiannan (2/2) ✅ liulufang_gitcode, congqiannan (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Set xinweiliu,pan-boyi,lim-jiunnbin,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,li-shengxian3,yinjie27_,liulufang_gitcode,congqiannan,tsungl4,gaoxingwang,zhangxiangjie,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
1 day ago Set xinweiliu,pan-boyi,lim-jiunnbin,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,li-shengxian3,yinjie27_,liulufang_gitcode,congqiannan,tsungl4,gaoxingwang,zhangxiangjie,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
jude_pixel
jude_pixel
1 day ago Comments:

/compile

likedislike
jude_pixeljude_pixel
1 day ago Pre merge succeeded (commit_id: af7015787e96f916ff20a11a5b92c9e976eb6c9f)
CANN-robot
CANN-robotCollaborators
1 day ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-passed
jude_pixel
jude_pixel
1 day ago Comments:

这单把 modeling/transformers/gutenocr_3b/ask_gutenocr_3b.py 预热循环里重复的 if/else 分支精简了一下(+1/-4),刚刚 CI 已经跑绿,麻烦 @hw_0086_hrf @liulufang_gitcode @wangzheng97 几位老师有空帮忙看看。

likedislike
congqiannan
congqiannanCollaborators
23 hours ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
23 hours ago Added label: approved
liulufang_gitcode
liulufang_gitcodeCollaborators
23 hours ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
23 hours ago Added label: lgtm
CANN-robotCANN-robotCollaborators
23 hours ago Closed associated issue
CANN-robotCANN-robotCollaborators
23 hours ago Merged pull request