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 @@
## 2025-05-05 - Replacing O(N^2) list pop(0) in fastdeploy/model_executor/entropy_utils.py
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 AI 工具的内部日志文件,不应提交到项目仓库。

建议在 .gitignore 中忽略 .jules/ 目录,或直接删除该文件,避免污染项目仓库历史。

**Learning:** Found O(N^2) list operations where `entropy.pop(0)` was called inside nested loops over batch size and sequence lengths.
**Action:** Replace `pop(0)` within a loop with an index tracker and bulk addition via `.extend(list[start:end])`.
16 changes: 12 additions & 4 deletions fastdeploy/model_executor/entropy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ 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))
seq_len = int(real_seq_lens[i])
if seq_len > 0:
share_inputs["entropy_list"][i].extend(entropy[entropy_idx : entropy_idx + seq_len])
entropy_idx += seq_len

if (
share_inputs["stop_flags"][i]
and share_inputs["seq_lens_decoder"][i] != 0
Expand Down Expand Up @@ -92,9 +96,13 @@ 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))
accept_num = int(share_inputs["accept_num"][i])
if accept_num > 0:
share_inputs["entropy_list"][i].extend(entropy[entropy_idx : entropy_idx + accept_num])
entropy_idx += accept_num

if (
share_inputs["stop_flags"][i]
and share_inputs["seq_lens_decoder"][i] != 0
Expand Down
Loading