Skip to content

Commit 2d0afcc

Browse files
authored
[mrope][Qwen2-VL] Fix edge case where getting index of image/video token can potentially throw in default vl mrope implementation. (vllm-project#23895)
Signed-off-by: Chenheli Hua <[email protected]>
1 parent b4f9e96 commit 2d0afcc

File tree

1 file changed

+10
-4
lines changed
  • vllm/model_executor/layers/rotary_embedding

1 file changed

+10
-4
lines changed

vllm/model_executor/layers/rotary_embedding/mrope.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,18 @@ def _vl_get_input_positions_tensor(
670670
image_index, video_index = 0, 0
671671
for _ in range(image_nums + video_nums):
672672
video_second_per_grid_t = 0.0
673-
if image_token_id in input_tokens and remain_images > 0:
674-
ed_image = input_tokens.index(image_token_id, st)
673+
if remain_images > 0:
674+
try:
675+
ed_image = input_tokens.index(image_token_id, st)
676+
except ValueError:
677+
ed_image = len(input_tokens) + 1
675678
else:
676679
ed_image = len(input_tokens) + 1
677-
if video_token_id in input_tokens and remain_videos > 0:
678-
ed_video = input_tokens.index(video_token_id, st)
680+
if remain_videos > 0:
681+
try:
682+
ed_video = input_tokens.index(video_token_id, st)
683+
except ValueError:
684+
ed_video = len(input_tokens) + 1
679685
else:
680686
ed_video = len(input_tokens) + 1
681687
if ed_image < ed_video:

0 commit comments

Comments
 (0)