Skip to content

fix: guard empty free_token_index in InferBatch._filter#1391

Closed
sufubao wants to merge 1 commit into
mainfrom
claude/qwen35-27260707-error-stwro5
Closed

fix: guard empty free_token_index in InferBatch._filter#1391
sufubao wants to merge 1 commit into
mainfrom
claude/qwen35-27260707-error-stwro5

Conversation

@sufubao

@sufubao sufubao commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

For linear-attention mixed models (e.g. Qwen3.5), a request aborted
before any kv is generated (cur_kv_len == 0) makes _linear_att_free_req
return without appending anything. custom_cat then crashes with
'IndexError: list index out of range' on the empty list, killing the
infer_loop thread. Skip custom_cat when the list is empty, matching the
existing guard in pause_reqs.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_018e7Le4MGpdfA1LdPRShk3f

For linear-attention mixed models (e.g. Qwen3.5), a request aborted
before any kv is generated (cur_kv_len == 0) makes _linear_att_free_req
return without appending anything. custom_cat then crashes with
'IndexError: list index out of range' on the empty list, killing the
infer_loop thread. Skip custom_cat when the list is empty, matching the
existing guard in pause_reqs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018e7Le4MGpdfA1LdPRShk3f

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a check to handle empty free_token_index lists in infer_batch.py to prevent errors when calling custom_cat on linear attention hybrid models. The reviewer suggested simplifying the check using Python's idiomatic truthiness and removing the redundant else block.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +286 to +289
if len(free_token_index) != 0:
free_token_index = custom_cat(free_token_index)
else:
free_token_index = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The else block is redundant because free_token_index is already initialized as an empty list [] at the beginning of the method. Additionally, we can use Python's idiomatic truthiness check if free_token_index: instead of if len(free_token_index) != 0: to make the code cleaner and more readable.

Suggested change
if len(free_token_index) != 0:
free_token_index = custom_cat(free_token_index)
else:
free_token_index = []
if free_token_index:
free_token_index = custom_cat(free_token_index)

@sufubao sufubao changed the base branch from main to qwen35-27b-260707 July 14, 2026 05:15
@sufubao sufubao changed the base branch from qwen35-27b-260707 to main July 14, 2026 05:16
@sufubao sufubao closed this Jul 15, 2026
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