Skip to content

⚡ Bolt: [Optimization] Optimize O(N^2) pop(0) in entropy_utils.py#7719

Open
google-labs-jules[bot] wants to merge 1 commit intodevelopfrom
bolt-entropy-optimization-4001707810666485455
Open

⚡ Bolt: [Optimization] Optimize O(N^2) pop(0) in entropy_utils.py#7719
google-labs-jules[bot] wants to merge 1 commit intodevelopfrom
bolt-entropy-optimization-4001707810666485455

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

Motivation

This pull request implements a performance optimization to replace an O(N^2) operation in fastdeploy/model_executor/entropy_utils.py. The use of .pop(0) inside a loop requires shifting all subsequent elements in a list, resulting in poor execution time for larger array inputs.

Modifications

  • 💡 What: Replaced entropy.pop(0) with an entropy_idx variable for O(1) array access in calculate_logits_entropy and speculate_calculate_logits_entropy loops.
  • 🎯 Why: pop(0) on a list is an O(N) operation. Repeated in a nested loop this becomes O(N^2).
  • 📊 Impact: Faster execution time on CPU processing when fetching entropy elements. Reduces complexity to O(N) iterating over entropy sequentially instead.
  • 🔬 Measurement: Verified with unit tests via pytest tests/model_executor/test_entropy_utils.py. The behavior functions identically to before.

Usage or Command

python -m pytest tests/model_executor/test_entropy_utils.py

Accuracy Tests

No change to model outputs, only variable tracking.

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests (Existing unit tests were used to verify logic).
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

PR created automatically by Jules for task 4001707810666485455 started by @ZeyuChen

…py_utils.py

Replaces `list.pop(0)` within nested loops with an O(1) index increment
variable `entropy_idx` to iterate over elements sequentially. This
improves execution time inside `calculate_logits_entropy` and
`speculate_calculate_logits_entropy` from O(N^2) to O(N).
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 4, 2026

Thanks for your contribution!

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Paddle-CI-Agent | pr_review | 2026-05-05 00:36:02

📋 Review 摘要

PR 概述:将 entropy_utils.py 中两处 pop(0) 的 O(N²) 操作替换为索引追踪,消除嵌套循环中的 O(N²) 复杂度,提升 CPU 侧熵值计算性能。
变更范围fastdeploy/model_executor/entropy_utils.py.jules/bolt.md
影响面 Tag[Optimization]

📝 PR 规范检查

标题携带非标准前缀 ⚡ Bolt: ,不符合 [Tag] 描述 的标准格式。PR 描述各节(Motivation / Modifications / Usage or Command / Accuracy Tests / Checklist)结构完整,无需修改。

标题建议(可直接复制):

  • [Optimization] Optimize O(N^2) pop(0) in entropy_utils.py

问题

级别 文件 概述
🟡 建议 .jules/bolt.md:1 AI 工具产生的 learning notes 文件,不应提交至主仓库

总体评价

代码逻辑优化正确,pop(0) 替换为索引追踪在语义上完全等价,性能有所提升。建议移除 .jules/bolt.md 工具产物并修正标题前缀后合入。

Comment thread .jules/bolt.md
@@ -0,0 +1,3 @@
## 2024-05-04 - Inefficient list.pop(0) operations
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 .jules/bolt.md 是 Jules AI 工具自动生成的 learning notes 产物文件,不属于项目源码范畴,不应提交至主仓库。

建议在 .gitignore 中忽略 .jules/ 目录,或直接删除该文件后重新提交。

@PaddlePaddle-bot
Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-05 00:55:40

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

⏳ CI 运行中:5 个 Required 任务尚未完成,当前 0 个 Required 任务失败,暂无阻塞合并风险。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
35(0) 35 26 2 6 1 0

2 任务状态汇总

2.1 Required任务 : 5/10 通过

必选任务阻塞合并,失败需优先处理。

状态 任务 耗时 根因 修复建议 日志 重跑
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage - 运行中 - Job -
Extracted partial CE model tasks to run in CI. / run_ce_cases - 运行中 - Job -
Run Four Cards Tests / run_4_cards_tests - 运行中 - Job -
xpu_4cards_case_test / run_xpu_4cards_cases - 运行中 - Job -
xpu_8cards_case_test / run_xpu_8cards_cases - 运行中 - Job -
其余 5 个必选任务通过 - - - - -

2.2 可选任务 — 21/25 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
Check PR Template 15s Job -
Trigger Jenkins for PR 10m7s Job -
CI_HPU - Job -
⏸️ Run iluvatar Tests / run_iluvatar_cases - - -
其余 21 个可选任务通过 - - -

3 失败详情(仅 required)

无 required 失败任务。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants