Skip to content

Commit 49c23d9

Browse files
JustinTong0323jimoosciuc
authored andcommitted
fix: examples for token_in_token_out_vlm (sgl-project#5193)
1 parent e650554 commit 49c23d9

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

examples/runtime/token_in_token_out/token_in_token_out_vlm_engine.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import argparse
22
import dataclasses
3-
from io import BytesIO
43
from typing import Tuple
54

6-
import requests
7-
from PIL import Image
85
from transformers import AutoProcessor
96

107
from sglang import Engine
@@ -19,20 +16,22 @@ def get_input_ids(
1916
) -> Tuple[list[int], list]:
2017
chat_template = get_chat_template_by_model_path(model_config.model_path)
2118
text = f"{chat_template.image_token}What is in this picture?"
22-
images = [Image.open(BytesIO(requests.get(DEFAULT_IMAGE_URL).content))]
2319
image_data = [DEFAULT_IMAGE_URL]
2420

2521
processor = AutoProcessor.from_pretrained(
2622
model_config.model_path, trust_remote_code=server_args.trust_remote_code
2723
)
2824

29-
inputs = processor(
30-
text=[text],
31-
images=images,
32-
return_tensors="pt",
25+
input_ids = (
26+
processor.tokenizer(
27+
text=[text],
28+
return_tensors="pt",
29+
)
30+
.input_ids[0]
31+
.tolist()
3332
)
3433

35-
return inputs.input_ids[0].tolist(), image_data
34+
return input_ids, image_data
3635

3736

3837
def token_in_out_example(

examples/runtime/token_in_token_out/token_in_token_out_vlm_server.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
66
"""
77

8-
from io import BytesIO
98
from typing import Tuple
109

1110
import requests
12-
from PIL import Image
1311
from transformers import AutoProcessor
1412

1513
from sglang.lang.chat_template import get_chat_template_by_model_path
@@ -28,18 +26,20 @@
2826
def get_input_ids() -> Tuple[list[int], list]:
2927
chat_template = get_chat_template_by_model_path(MODEL_PATH)
3028
text = f"{chat_template.image_token}What is in this picture?"
31-
images = [Image.open(BytesIO(requests.get(DEFAULT_IMAGE_URL).content))]
3229
image_data = [DEFAULT_IMAGE_URL]
3330

3431
processor = AutoProcessor.from_pretrained(MODEL_PATH)
3532

36-
inputs = processor(
37-
text=[text],
38-
images=images,
39-
return_tensors="pt",
33+
input_ids = (
34+
processor.tokenizer(
35+
text=[text],
36+
return_tensors="pt",
37+
)
38+
.input_ids[0]
39+
.tolist()
4040
)
4141

42-
return inputs.input_ids[0].tolist(), image_data
42+
return input_ids, image_data
4343

4444

4545
def main():

0 commit comments

Comments
 (0)