compute image start_idx after audio expansion#1398
Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
No description provided.