A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 07:15 UTC
Fix #19130 (#19132)
Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com>
汪志鹏 committed
Jun 4, 2025 at 16:42 UTC
3336c8cfbef6c7d6688ca1e5b0b26424baef02c4
1 file changed
+26
-10
examples/offline_inference/vision_language_multi_image.py
+26
-10
@@ -593,21 +593,21 @@ def load_qwen_vl_chat(question: str, image_urls: list[str]) -> ModelRequestData:
593
594
def load_qwen2_vl(question: str, image_urls: list[str]) -> ModelRequestData:
595
try:
596
- from qwen_vl_utils import process_vision_info
596
+ from qwen_vl_utils import smart_resize
597
except ModuleNotFoundError:
598
print(
599
"WARNING: `qwen-vl-utils` not installed, input images will not "
600
"be automatically resized. You can enable this functionality by "
601
"`pip install qwen-vl-utils`."
602
)
603
- process_vision_info = None
603
+ smart_resize = None
604
605
model_name = "Qwen/Qwen2-VL-7B-Instruct"
606
607
# Tested on L40
608
engine_args = EngineArgs(
609
model=model_name,
610
- max_model_len=32768 if process_vision_info is None else 4096,
610
+ max_model_len=32768 if smart_resize is None else 4096,
611
max_num_seqs=5,
612
limit_mm_per_prompt={"image": len(image_urls)},
613
)
@@ -630,10 +630,18 @@ def load_qwen2_vl(question: str, image_urls: list[str]) -> ModelRequestData:
630
messages, tokenize=False, add_generation_prompt=True
631
)
632
633
- if process_vision_info is None:
633
+ if smart_resize is None:
634
image_data = [fetch_image(url) for url in image_urls]
635
else:
636
- image_data, _ = process_vision_info(messages)
636
+
637
+ def post_process_image(image: Image) -> Image:
638
+ width, height = image.size
639
+ resized_height, resized_width = smart_resize(
640
+ height, width, max_pixels=1024 * 28 * 28
641
+ )
642
+ return image.resize((resized_width, resized_height))
643
+
644
+ image_data = [post_process_image(fetch_image(url)) for url in image_urls]
645
646
return ModelRequestData(
647
engine_args=engine_args,
@@ -644,20 +652,20 @@ def load_qwen2_vl(question: str, image_urls: list[str]) -> ModelRequestData:
652
653
def load_qwen2_5_vl(question: str, image_urls: list[str]) -> ModelRequestData:
654
try:
647
- from qwen_vl_utils import process_vision_info
655
+ from qwen_vl_utils import smart_resize
656
except ModuleNotFoundError:
657
print(
658
"WARNING: `qwen-vl-utils` not installed, input images will not "
659
"be automatically resized. You can enable this functionality by "
660
"`pip install qwen-vl-utils`."
661
)
654
- process_vision_info = None
662
+ smart_resize = None
663
664
model_name = "Qwen/Qwen2.5-VL-3B-Instruct"
665
666
engine_args = EngineArgs(
667
model=model_name,
660
- max_model_len=32768 if process_vision_info is None else 4096,
668
+ max_model_len=32768 if smart_resize is None else 4096,
669
max_num_seqs=5,
670
limit_mm_per_prompt={"image": len(image_urls)},
671
)
@@ -680,10 +688,18 @@ def load_qwen2_5_vl(question: str, image_urls: list[str]) -> ModelRequestData:
688
messages, tokenize=False, add_generation_prompt=True
689
)
690
683
- if process_vision_info is None:
691
+ if smart_resize is None:
692
image_data = [fetch_image(url) for url in image_urls]
693
else:
686
- image_data, _ = process_vision_info(messages, return_video_kwargs=False)
694
+
695
+ def post_process_image(image: Image) -> Image:
696
+ width, height = image.size
697
+ resized_height, resized_width = smart_resize(
698
+ height, width, max_pixels=1024 * 28 * 28
699
+ )
700
+ return image.resize((resized_width, resized_height))
701
+
702
+ image_data = [post_process_image(fetch_image(url)) for url in image_urls]
703
704
return ModelRequestData(
705
engine_args=engine_args,