Skip to content

Commit f4d10cf

Browse files
author
wangzaijun
committed
fix start_idx used
1 parent e7da666 commit f4d10cf

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lightllm/models/qwen2_vl/model.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,25 @@ def encode(self, prompt, multimodal_params: MultimodalParams = None, **kwargs):
6262
# <img></img> --> <img>id,id+1...id+num</img>
6363
input_ids = []
6464
image_id = 0
65-
start_idx = 0
66-
cu_image_token_num = 0
6765
while True:
6866
try:
69-
start_idx = origin_ids.index(self.image_start_id, start_idx)
67+
start_idx = origin_ids.index(self.image_start_id)
7068
if start_idx + 1 >= len(origin_ids):
7169
break
7270
if origin_ids[start_idx + 1] == self.image_end_id:
7371
input_ids.extend(origin_ids[: start_idx + 1])
7472
token_id = multimodal_params.images[image_id].token_id
7573
token_num = multimodal_params.images[image_id].token_num
76-
multimodal_params.images[image_id].start_idx = start_idx + 1 + cu_image_token_num
74+
multimodal_params.images[image_id].start_idx = len(input_ids)
7775
input_ids.extend(range(token_id, token_id + token_num))
7876
input_ids.append(self.image_end_id)
79-
start_idx += 1
77+
origin_ids = origin_ids[start_idx + 2 :]
8078
image_id += 1
81-
cu_image_token_num += token_num
8279
else:
8380
raise ValueError("image token error")
8481
except ValueError:
8582
break
86-
input_ids.extend(origin_ids[start_idx + 1 :])
83+
input_ids.extend(origin_ids)
8784
return input_ids
8885

8986

0 commit comments

Comments
 (0)