Skip to content

compute image start_idx after audio expansion#1398

Open
WANDY666 wants to merge 1 commit into
mainfrom
fix_qwen3_omni
Open

compute image start_idx after audio expansion#1398
WANDY666 wants to merge 1 commit into
mainfrom
fix_qwen3_omni

Conversation

@WANDY666

Copy link
Copy Markdown
Contributor

No description provided.

@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 updates the encode method in lightllm/models/qwen3_omni_moe_thinker/model.py to calculate the start_idx of images after constructing the full input_ids list, rather than during the construction loop. Feedback suggests wrapping the .index() call in a try-except block to handle potential ValueError exceptions gracefully if the image token ID is not found in input_ids.

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 +146 to +150
if multimodal_params:
image_search_start = 0
for image in multimodal_params.images:
image.start_idx = input_ids.index(image.token_id, image_search_start)
image_search_start = image.start_idx + image.token_num

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

Calling input_ids.index(image.token_id, image_search_start) can raise a ValueError if image.token_id is not found in input_ids (for example, if image.token_num is 0, or if there is a mismatch). To prevent an unhandled exception and make debugging easier, it is highly recommended to wrap this in a try-except block and raise a descriptive error message.

Suggested change
if multimodal_params:
image_search_start = 0
for image in multimodal_params.images:
image.start_idx = input_ids.index(image.token_id, image_search_start)
image_search_start = image.start_idx + image.token_num
if multimodal_params:
image_search_start = 0
for image in multimodal_params.images:
try:
image.start_idx = input_ids.index(image.token_id, image_search_start)
except ValueError as e:
raise ValueError(
f"Failed to find image.token_id ({image.token_id}) in input_ids starting from index {image_search_start}. "
f"This can happen if token_num is 0 or if there is an image token mismatch."
) from e
image_search_start = image.start_idx + image.token_num

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.

1 participant