Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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/ 目录,或直接删除该文件后重新提交。

**Learning:** Found multiple usages of `list.pop(0)` in the codebase, particularly in `fastdeploy/model_executor/entropy_utils.py` . `pop(0)` on a list is an O(N) operation because it requires shifting all subsequent elements. For queues or iterating over elements sequentially, using an index or `collections.deque` is much faster.
**Action:** Replace O(N) `pop(0)` operations with O(1) index tracking or `collections.deque` where appropriate to optimize execution performance.
8 changes: 6 additions & 2 deletions fastdeploy/model_executor/entropy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def calculate_logits_entropy(logits, share_inputs, temperature):
entropy_tensor = get_entropy(logits)
entropy = entropy_tensor.tolist()

entropy_idx = 0
for i in range(real_bsz):
for _ in range(real_seq_lens[i]):
share_inputs["entropy_list"][i].append(entropy.pop(0))
share_inputs["entropy_list"][i].append(entropy[entropy_idx])
entropy_idx += 1
if (
share_inputs["stop_flags"][i]
and share_inputs["seq_lens_decoder"][i] != 0
Expand Down Expand Up @@ -92,9 +94,11 @@ def speculate_calculate_logits_entropy(logits, share_inputs, temperature):
entropy_tensor = get_entropy(accepted_logits)
entropy = entropy_tensor.tolist()

entropy_idx = 0
for i in range(real_bsz):
for _ in range(share_inputs["accept_num"][i]):
share_inputs["entropy_list"][i].append(entropy.pop(0))
share_inputs["entropy_list"][i].append(entropy[entropy_idx])
entropy_idx += 1
if (
share_inputs["stop_flags"][i]
and share_inputs["seq_lens_decoder"][i] != 0
Expand Down
Loading