2025-02-02 14:58:18 -05:00
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2024-07-26 22:44:13 -07:00
|
|
|
|
"""
|
2024-10-23 11:35:29 +08:00
|
|
|
|
This example shows how to use vLLM for running offline inference with
|
|
|
|
|
|
the correct prompt format on vision language models for text generation.
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
For most models, the prompt format should follow corresponding examples
|
|
|
|
|
|
on HuggingFace model repository.
|
|
|
|
|
|
"""
|
2025-05-26 17:57:54 +01:00
|
|
|
|
|
2025-03-08 01:28:52 +08:00
|
|
|
|
import os
|
2024-12-11 19:55:30 -05:00
|
|
|
|
import random
|
2025-04-11 12:57:16 +08:00
|
|
|
|
from contextlib import contextmanager
|
2025-03-17 18:00:17 +08:00
|
|
|
|
from dataclasses import asdict
|
|
|
|
|
|
from typing import NamedTuple
|
2024-12-11 19:55:30 -05:00
|
|
|
|
|
2025-03-08 01:28:52 +08:00
|
|
|
|
from huggingface_hub import snapshot_download
|
2026-01-08 05:00:27 -08:00
|
|
|
|
from transformers import AutoProcessor, AutoTokenizer
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
from vllm import LLM, EngineArgs, SamplingParams
|
2024-07-26 22:44:13 -07:00
|
|
|
|
from vllm.assets.image import ImageAsset
|
2024-09-11 13:21:36 +08:00
|
|
|
|
from vllm.assets.video import VideoAsset
|
2025-03-08 01:28:52 +08:00
|
|
|
|
from vllm.lora.request import LoRARequest
|
2025-05-22 18:59:18 -07:00
|
|
|
|
from vllm.multimodal.image import convert_image_mode
|
2025-10-26 16:33:32 +05:30
|
|
|
|
from vllm.utils.argparse_utils import FlexibleArgumentParser
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
class ModelRequestData(NamedTuple):
|
|
|
|
|
|
engine_args: EngineArgs
|
|
|
|
|
|
prompts: list[str]
|
|
|
|
|
|
stop_token_ids: list[int] | None = None
|
|
|
|
|
|
lora_requests: list[LoRARequest] | None = None
|
2025-10-22 22:59:15 +08:00
|
|
|
|
sampling_params: list[SamplingParams] | None = None
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-09-29 00:54:35 +08:00
|
|
|
|
# NOTE: The default `max_num_seqs` and `max_model_len` may result in OOM on
|
|
|
|
|
|
# lower-end GPUs.
|
|
|
|
|
|
# Unless specified, these settings have been tested to work on a single L4.
|
|
|
|
|
|
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Aria
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_aria(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "rhymes-ai/Aria"
|
|
|
|
|
|
|
2024-12-31 13:17:22 -08:00
|
|
|
|
# NOTE: Need L40 (or equivalent) to avoid OOM
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
dtype="bfloat16",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>user\n<fim_prefix><|img|><fim_suffix>{question}"
|
|
|
|
|
|
"<|im_end|>\n<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
stop_token_ids = [93532, 93653, 944, 93421, 1019, 93653, 93519]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 09:30:43 -07:00
|
|
|
|
# Aya Vision
|
|
|
|
|
|
def run_aya_vision(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
2025-12-05 14:41:40 -05:00
|
|
|
|
model_name = "CohereLabs/aya-vision-8b"
|
2025-04-01 09:30:43 -07:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=2048,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
mm_processor_kwargs={"crop_to_patches": True},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-01 09:30:43 -07:00
|
|
|
|
)
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|START_OF_TURN_TOKEN|><|USER_TOKEN|><image>{question}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-20 10:31:26 +08:00
|
|
|
|
# Bee-8B
|
|
|
|
|
|
def run_bee(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "Open-Bee/Bee-8B-RL"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<image>\n{question}<|im_end|>"
|
|
|
|
|
|
f"<|im_start|>assistant\n<think>\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=16384,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-15 14:58:23 +08:00
|
|
|
|
def run_bagel(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "ByteDance-Seed/BAGEL-7B-MoT"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>user\n<|image_pad|>\n{question}<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# BLIP-2
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_blip2(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
# BLIP-2 prompt format is inaccurate on HuggingFace model repository.
|
|
|
|
|
|
# See https://huggingface.co/Salesforce/blip2-opt-2.7b/discussions/15#64ff02f3f8cf9e4f5b038262 #noqa
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"Question: {question} Answer:" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2025-07-07 00:54:36 +08:00
|
|
|
|
model="Salesforce/blip2-opt-2.7b",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Chameleon
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_chameleon(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"{question}<image>" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="facebook/chameleon-7b",
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-12 04:39:54 -04:00
|
|
|
|
def run_command_a_vision(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "CohereLabs/command-a-vision-07-2025"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=32768,
|
|
|
|
|
|
tensor_parallel_size=4,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|START_OF_TURN_TOKEN|><|USER_TOKEN|><|IMG_PATCH|>{question}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-12 16:17:24 +08:00
|
|
|
|
# Deepseek-VL2
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_deepseek_vl2(questions: list[str], modality: str) -> ModelRequestData:
|
2025-01-12 16:17:24 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-01-17 01:14:48 +08:00
|
|
|
|
model_name = "deepseek-ai/deepseek-vl2-tiny"
|
2025-01-12 16:17:24 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
hf_overrides={"architectures": ["DeepseekVLV2ForCausalLM"]},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
2025-01-12 16:17:24 +08:00
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-05-26 17:57:54 +01:00
|
|
|
|
f"<|User|>: <image>\n{question}\n\n<|Assistant|>:" for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2025-01-12 16:17:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-10-22 22:59:15 +08:00
|
|
|
|
def run_deepseek_ocr(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
from vllm.model_executor.models.deepseek_ocr import NGramPerReqLogitsProcessor
|
|
|
|
|
|
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "deepseek-ai/DeepSeek-OCR"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
logits_processors=[NGramPerReqLogitsProcessor],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# deepseek-ocr use plain prompt template
|
|
|
|
|
|
prompts = [f"<image>\n{question}" for question in questions]
|
|
|
|
|
|
|
|
|
|
|
|
# The following sampling params config is taken from
|
|
|
|
|
|
# the official Deepseek-OCR inference example.
|
|
|
|
|
|
# (IMPORTANT) Use the custom logits processor and avoid skipping
|
|
|
|
|
|
# special tokens for this model for the optimal OCR performance.
|
|
|
|
|
|
sampling_params = [
|
|
|
|
|
|
SamplingParams(
|
|
|
|
|
|
temperature=0.0,
|
|
|
|
|
|
max_tokens=8192,
|
|
|
|
|
|
# ngram logit processor args
|
|
|
|
|
|
extra_args=dict(
|
|
|
|
|
|
ngram_size=30,
|
|
|
|
|
|
window_size=90,
|
|
|
|
|
|
# whitelist: <td>, </td>
|
|
|
|
|
|
whitelist_token_ids={128821, 128822},
|
|
|
|
|
|
),
|
|
|
|
|
|
skip_special_tokens=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
for _ in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
sampling_params=sampling_params,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Dots-OCR
|
|
|
|
|
|
def run_dots_ocr(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [f"<|img|><|imgpad|><|endofimg|>{question}" for question in questions]
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="rednote-hilab/dots.ocr",
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-21 18:39:53 +09:00
|
|
|
|
# Eagle2.5-VL
|
|
|
|
|
|
def run_eagle2_5(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "nvidia/Eagle2.5-8B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Stop tokens for Eagle2.5 (Qwen2 based)
|
|
|
|
|
|
stop_tokens = ["<|endoftext|>", "<|im_start|>", "<|im_end|>"]
|
|
|
|
|
|
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
|
|
|
|
|
|
stop_token_ids = [token_id for token_id in stop_token_ids if token_id is not None]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-27 12:02:55 +08:00
|
|
|
|
# Ernie4.5-VL
|
|
|
|
|
|
def run_ernie45_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "baidu/ERNIE-4.5-VL-28B-A3B-PT"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "Picture 1:<|IMAGE_START|><|image@placeholder|><|IMAGE_END|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "Video 1:<|VIDEO_START|><|video@placeholder|><|VIDEO_END|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|begin_of_sentence|>User: {question}{placeholder}\n"
|
|
|
|
|
|
"Assistant: <think></think>"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Fuyu
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_fuyu(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"{question}\n" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="adept/fuyu-8b",
|
|
|
|
|
|
max_model_len=2048,
|
|
|
|
|
|
max_num_seqs=2,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-12 08:36:33 -07:00
|
|
|
|
# Gemma 3
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_gemma3(questions: list[str], modality: str) -> ModelRequestData:
|
2025-03-12 08:36:33 -07:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "google/gemma-3-4b-it"
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2025-03-13 17:23:12 +08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=2048,
|
|
|
|
|
|
max_num_seqs=2,
|
2025-10-22 14:05:34 -03:00
|
|
|
|
mm_processor_kwargs={"do_pan_and_scan": True},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-13 17:23:12 +08:00
|
|
|
|
)
|
2025-03-12 08:36:33 -07:00
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"<bos><start_of_turn>user\n"
|
|
|
|
|
|
f"<start_of_image>{question}<end_of_turn>\n"
|
|
|
|
|
|
"<start_of_turn>model\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-08-09 18:56:25 +02:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
2025-08-09 18:56:25 +02:00
|
|
|
|
# Gemma3N
|
|
|
|
|
|
def run_gemma3n(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "google/gemma-3n-E2B-it"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=2048,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"<start_of_turn>user\n"
|
|
|
|
|
|
f"<image_soft_token>{question}<end_of_turn>\n"
|
|
|
|
|
|
"<start_of_turn>model\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2025-03-12 08:36:33 -07:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# GLM-4v
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_glm4v(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
2025-08-04 14:51:20 +08:00
|
|
|
|
model_name = "zai-org/glm-4v-9b"
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=2048,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
hf_overrides={"architectures": ["GLM4VForCausalLM"]},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
2025-02-13 22:19:15 +08:00
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-08-21 13:03:00 +08:00
|
|
|
|
(
|
|
|
|
|
|
"<|user|>\n<|begin_of_image|><|endoftext|><|end_of_image|>"
|
|
|
|
|
|
f"{question}<|assistant|>"
|
|
|
|
|
|
)
|
2025-05-26 17:57:54 +01:00
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-02-09 04:32:16 +08:00
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
stop_token_ids = [151329, 151336, 151338]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-07-01 20:48:26 +08:00
|
|
|
|
# GLM-4.1V
|
|
|
|
|
|
def run_glm4_1v(questions: list[str], modality: str) -> ModelRequestData:
|
2025-08-04 14:51:20 +08:00
|
|
|
|
model_name = "zai-org/GLM-4.1V-9B-Thinking"
|
2025-07-01 20:48:26 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"size": {"shortest_edge": 12544, "longest_edge": 47040000},
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|begin_of_image|><|image|><|end_of_image|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|begin_of_video|><|video|><|end_of_video|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"[gMASK]<sop><|system|>\nYou are a helpful assistant.<|user|>\n"
|
|
|
|
|
|
f"{placeholder}"
|
|
|
|
|
|
f"{question}<|assistant|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-19 16:56:31 +09:00
|
|
|
|
# GLM-4.5V
|
|
|
|
|
|
def run_glm4_5v(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "zai-org/GLM-4.5V"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"size": {"shortest_edge": 12544, "longest_edge": 47040000},
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
tensor_parallel_size=4,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|begin_of_image|><|image|><|end_of_image|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|begin_of_video|><|video|><|end_of_video|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"[gMASK]<sop><|system|>\nYou are a helpful assistant.<|user|>\n"
|
|
|
|
|
|
f"{placeholder}"
|
|
|
|
|
|
f"{question}<|assistant|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GLM-4.5V-FP8
|
|
|
|
|
|
def run_glm4_5v_fp8(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "zai-org/GLM-4.5V-FP8"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"size": {"shortest_edge": 12544, "longest_edge": 47040000},
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
tensor_parallel_size=4,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|begin_of_image|><|image|><|end_of_image|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|begin_of_video|><|video|><|end_of_video|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"[gMASK]<sop><|system|>\nYou are a helpful assistant.<|user|>\n"
|
|
|
|
|
|
f"{placeholder}"
|
|
|
|
|
|
f"{question}<|assistant|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# H2OVL-Mississippi
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_h2ovl(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-02-16 02:35:54 -08:00
|
|
|
|
model_name = "h2oai/h2ovl-mississippi-800m"
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=8192,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-12-16 19:23:33 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
# Stop tokens for H2OVL-Mississippi
|
2025-02-16 02:35:54 -08:00
|
|
|
|
# https://huggingface.co/h2oai/h2ovl-mississippi-800m
|
2024-12-16 19:23:33 +08:00
|
|
|
|
stop_token_ids = [tokenizer.eos_token_id]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-11-25 11:28:51 +08:00
|
|
|
|
# HunyuanOCR
|
|
|
|
|
|
def run_hunyuan_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "tencent/HunyuanOCR"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
placeholder = "<|hy_place▁holder▁no▁100|><|hy_place▁holder▁no▁102|><|hy_place▁holder▁no▁101|>" # noqa: E501
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|hy_begin▁of▁sentence|>{placeholder}{question}<|hy_User|>"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=None,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-25 22:05:42 +09:00
|
|
|
|
# naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B
|
|
|
|
|
|
def run_hyperclovax_seed_vision(
|
|
|
|
|
|
questions: list[str], modality: str
|
|
|
|
|
|
) -> ModelRequestData:
|
|
|
|
|
|
model_name = "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B"
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=8192 if modality == "image" else 16384,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
messages = list()
|
|
|
|
|
|
for question in questions:
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
"""
|
2025-08-19 16:56:31 +09:00
|
|
|
|
ocr: List the words in the image in raster order.
|
|
|
|
|
|
Even if the word order feels unnatural for reading,
|
2025-07-25 22:05:42 +09:00
|
|
|
|
the model will handle it as long as it follows raster order.
|
|
|
|
|
|
e.g. "Naver, CLOVA, bigshane"
|
|
|
|
|
|
lens_keywords: List the entity names in the image.
|
|
|
|
|
|
e.g. "iPhone"
|
|
|
|
|
|
lens_local_keywords: List the entity names with quads in the image.
|
|
|
|
|
|
e.g. "[0.07, 0.21, 0.92, 0.90] iPhone"
|
|
|
|
|
|
"""
|
|
|
|
|
|
messages.append(
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "image",
|
|
|
|
|
|
"ocr": "",
|
|
|
|
|
|
"lens_keywords": "",
|
|
|
|
|
|
"lens_local_keywords": "",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "text",
|
|
|
|
|
|
"text": question,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
messages.append(
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "video",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "text",
|
|
|
|
|
|
"text": question,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
raise ValueError(f"Unsupported modality: {modality}")
|
|
|
|
|
|
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages,
|
|
|
|
|
|
tokenize=False,
|
|
|
|
|
|
add_generation_prompt=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=None,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Idefics3-8B-Llama3
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_idefics3(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "HuggingFaceM4/Idefics3-8B-Llama3"
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
# if you are running out of memory, you can reduce the "longest_edge".
|
|
|
|
|
|
# see: https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3#model-optimizations
|
|
|
|
|
|
mm_processor_kwargs={
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"size": {"longest_edge": 3 * 364},
|
2024-12-16 19:23:33 +08:00
|
|
|
|
},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-12-16 19:23:33 +08:00
|
|
|
|
)
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [
|
|
|
|
|
|
(f"<|begin_of_text|>User:<image>{question}<end_of_utterance>\nAssistant:")
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-07-26 19:14:04 +08:00
|
|
|
|
# Intern-S1
|
|
|
|
|
|
def run_interns1(questions: list[str], modality: str) -> ModelRequestData:
|
2025-10-03 16:59:06 +08:00
|
|
|
|
model_name = "internlm/Intern-S1-mini"
|
2025-07-26 19:14:04 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-07-27 19:49:43 +08:00
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<IMG_CONTEXT>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<video>"
|
|
|
|
|
|
|
2025-07-26 19:14:04 +08:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"{placeholder}\n{question}"}]
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# InternVL
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_internvl(questions: list[str], modality: str) -> ModelRequestData:
|
2025-05-25 12:51:25 +08:00
|
|
|
|
model_name = "OpenGVLab/InternVL3-2B"
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
2025-05-25 12:51:25 +08:00
|
|
|
|
max_model_len=8192,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-12-16 19:23:33 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-25 12:51:25 +08:00
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<image>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<video>"
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"{placeholder}\n{question}"}]
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
# Stop tokens for InternVL
|
|
|
|
|
|
# models variants may have different stop tokens
|
|
|
|
|
|
# please refer to the model card for the correct "stop words":
|
|
|
|
|
|
# https://huggingface.co/OpenGVLab/InternVL2-2B/blob/main/conversation.py
|
|
|
|
|
|
stop_tokens = ["<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|end|>"]
|
|
|
|
|
|
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
|
2025-05-26 17:57:54 +01:00
|
|
|
|
stop_token_ids = [token_id for token_id in stop_token_ids if token_id is not None]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-01-13 01:39:02 +09:00
|
|
|
|
# Kanana-V
|
|
|
|
|
|
def run_kanana_v(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "kakaocorp/kanana-1.5-v-3b-instruct"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-02 14:35:04 +08:00
|
|
|
|
# Keye-VL
|
|
|
|
|
|
def run_keye_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "Kwai-Keye/Keye-VL-8B-Preview"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-01 18:50:27 +08:00
|
|
|
|
# Keye-VL-1.5
|
|
|
|
|
|
def run_keye_vl1_5(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "Kwai-Keye/Keye-VL-1.5-8B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-15 05:41:48 +08:00
|
|
|
|
# Kimi-VL
|
|
|
|
|
|
def run_kimi_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
"<|im_user|>user<|im_middle|><|media_start|>image<|media_content|>"
|
|
|
|
|
|
f"<|media_pad|><|media_end|>{question}<|im_end|>"
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"<|im_assistant|>assistant<|im_middle|>"
|
|
|
|
|
|
for question in questions
|
2025-04-15 05:41:48 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="moonshotai/Kimi-VL-A3B-Instruct",
|
|
|
|
|
|
trust_remote_code=True,
|
2025-04-18 20:15:09 +08:00
|
|
|
|
max_model_len=4096,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-15 05:41:48 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-17 07:05:24 +02:00
|
|
|
|
# LightOnOCR
|
|
|
|
|
|
def run_lightonocr(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
"<|im_start|>system<|im_end|>\n<|im_start|>user\n<|image_pad|><|im_end|>\n<|im_start|>assistant\n"
|
|
|
|
|
|
for _ in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="lightonai/LightOnOCR-1B",
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-08 05:00:27 -08:00
|
|
|
|
def run_lfm2_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "LiquidAI/LFM2-VL-450M"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
processor = AutoProcessor.from_pretrained(model_name)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": [{"type": "image"}, {"type": "text", "text": question}],
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = processor.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
def run_llama4(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=4,
|
|
|
|
|
|
tensor_parallel_size=8,
|
|
|
|
|
|
gpu_memory_utilization=0.4,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": [{"type": "image"}, {"type": "text", "text": f"{question}"}],
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, add_generation_prompt=True, tokenize=False
|
|
|
|
|
|
)
|
|
|
|
|
|
stop_token_ids = None
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 22:44:13 -07:00
|
|
|
|
# LLaVA-1.5
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_llava(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [f"USER: <image>\n{question}\nASSISTANT:" for question in questions]
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="llava-hf/llava-1.5-7b-hf",
|
|
|
|
|
|
max_model_len=4096,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# LLaVA-1.6/LLaVA-NeXT
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_llava_next(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"[INST] <image>\n{question} [/INST]" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="llava-hf/llava-v1.6-mistral-7b-hf",
|
|
|
|
|
|
max_model_len=8192,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-09-11 13:21:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# LlaVA-NeXT-Video
|
|
|
|
|
|
# Currently only support for video input
|
2025-05-26 17:57:54 +01:00
|
|
|
|
def run_llava_next_video(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "video"
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [f"USER: <video>\n{question} ASSISTANT:" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="llava-hf/LLaVA-NeXT-Video-7B-hf",
|
|
|
|
|
|
max_model_len=8192,
|
2025-03-25 18:22:52 +08:00
|
|
|
|
max_num_seqs=2,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
2024-09-23 01:51:44 +08:00
|
|
|
|
# LLaVA-OneVision
|
2025-05-26 17:57:54 +01:00
|
|
|
|
def run_llava_onevision(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
if modality == "video":
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-08-21 13:03:00 +08:00
|
|
|
|
f"<|im_start|>user <video>\n{question}<|im_end|><|im_start|>assistant\n"
|
2025-05-26 17:57:54 +01:00
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2024-09-23 01:51:44 +08:00
|
|
|
|
|
|
|
|
|
|
elif modality == "image":
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-08-21 13:03:00 +08:00
|
|
|
|
f"<|im_start|>user <image>\n{question}<|im_end|><|im_start|>assistant\n"
|
2025-05-26 17:57:54 +01:00
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2024-09-23 01:51:44 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="llava-hf/llava-onevision-qwen2-7b-ov-hf",
|
|
|
|
|
|
max_model_len=16384,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-09-23 01:51:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Mantis
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_mantis(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
llama3_template = "<|start_header_id|>user<|end_header_id|>\n\n{}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n" # noqa: E501
|
|
|
|
|
|
prompts = [llama3_template.format(f"{question}\n<image>") for question in questions]
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model="TIGER-Lab/Mantis-8B-siglip-llama3",
|
2024-09-29 00:54:35 +08:00
|
|
|
|
max_model_len=4096,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
hf_overrides={"architectures": ["MantisForConditionalGeneration"]},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-07-26 22:44:13 -07:00
|
|
|
|
)
|
2024-12-16 19:23:33 +08:00
|
|
|
|
stop_token_ids = [128009]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# MiniCPM-V
|
2025-03-04 07:43:59 -08:00
|
|
|
|
def run_minicpmv_base(questions: list[str], modality: str, model_name):
|
2025-01-29 17:24:59 +08:00
|
|
|
|
assert modality in ["image", "video"]
|
|
|
|
|
|
# If you want to use `MiniCPM-o-2_6` with audio inputs, check `audio_language.py` # noqa
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
# 2.0
|
|
|
|
|
|
# The official repo doesn't work yet, so we need to use a fork for now
|
|
|
|
|
|
# For more details, please see: See: https://github.com/vllm-project/vllm/pull/4087#issuecomment-2250397630 # noqa
|
|
|
|
|
|
# model_name = "HwwwH/MiniCPM-V-2"
|
|
|
|
|
|
|
|
|
|
|
|
# 2.5
|
2024-08-08 22:02:41 +08:00
|
|
|
|
# model_name = "openbmb/MiniCPM-Llama3-V-2_5"
|
|
|
|
|
|
|
2024-12-31 13:17:22 -08:00
|
|
|
|
# 2.6
|
2025-01-29 17:24:59 +08:00
|
|
|
|
# model_name = "openbmb/MiniCPM-V-2_6"
|
|
|
|
|
|
# o2.6
|
|
|
|
|
|
|
|
|
|
|
|
# modality supports
|
|
|
|
|
|
# 2.0: image
|
|
|
|
|
|
# 2.5: image
|
|
|
|
|
|
# 2.6: image, video
|
|
|
|
|
|
# o2.6: image, video, audio
|
|
|
|
|
|
# model_name = "openbmb/MiniCPM-o-2_6"
|
2025-05-26 17:57:54 +01:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-07-26 22:44:13 -07:00
|
|
|
|
model=model_name,
|
2024-09-29 00:54:35 +08:00
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
2024-07-26 22:44:13 -07:00
|
|
|
|
trust_remote_code=True,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-07-26 22:44:13 -07:00
|
|
|
|
)
|
2024-08-08 22:02:41 +08:00
|
|
|
|
# NOTE The stop_token_ids are different for various versions of MiniCPM-V
|
|
|
|
|
|
# 2.0
|
|
|
|
|
|
# stop_token_ids = [tokenizer.eos_id]
|
|
|
|
|
|
|
|
|
|
|
|
# 2.5
|
|
|
|
|
|
# stop_token_ids = [tokenizer.eos_id, tokenizer.eot_id]
|
|
|
|
|
|
|
2025-01-29 17:24:59 +08:00
|
|
|
|
# 2.6 / o2.6
|
2025-05-26 17:57:54 +01:00
|
|
|
|
stop_tokens = ["<|im_end|>", "<|endoftext|>"]
|
2024-08-08 22:02:41 +08:00
|
|
|
|
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-01-29 17:24:59 +08:00
|
|
|
|
modality_placeholder = {
|
|
|
|
|
|
"image": "(<image>./</image>)",
|
|
|
|
|
|
"video": "(<video>./</video>)",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
|
|
|
|
|
tokenizer.apply_chat_template(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": f"{modality_placeholder[modality]}\n{question}",
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
2025-03-04 07:43:59 -08:00
|
|
|
|
tokenize=False,
|
2025-05-26 17:57:54 +01:00
|
|
|
|
add_generation_prompt=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
stop_token_ids=stop_token_ids,
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_minicpmo(questions: list[str], modality: str) -> ModelRequestData:
|
2025-03-04 07:43:59 -08:00
|
|
|
|
return run_minicpmv_base(questions, modality, "openbmb/MiniCPM-o-2_6")
|
2025-01-29 17:24:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_minicpmv(questions: list[str], modality: str) -> ModelRequestData:
|
2025-03-04 07:43:59 -08:00
|
|
|
|
return run_minicpmv_base(questions, modality, "openbmb/MiniCPM-V-2_6")
|
2025-01-29 17:24:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-19 16:49:29 +08:00
|
|
|
|
def run_minimax_vl_01(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "MiniMaxAI/MiniMax-VL-01"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
tensor_parallel_size=8,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"role": "user",
|
|
|
|
|
|
"content": [{"type": "image"}, {"type": "text", "text": question}],
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, add_generation_prompt=True, tokenize=False
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 07:10:05 -06:00
|
|
|
|
# Mistral-3 HF-format
|
|
|
|
|
|
def run_mistral3(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
|
|
|
|
|
|
|
|
|
|
|
|
# NOTE: Need L40 (or equivalent) to avoid OOM
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
tensor_parallel_size=2,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-07-04 10:55:07 +08:00
|
|
|
|
ignore_patterns=["consolidated.safetensors"],
|
2025-04-01 07:10:05 -06:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [f"<s>[INST]{question}\n[IMG][/INST]" for question in questions]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
# Molmo
|
|
|
|
|
|
def run_molmo(questions: list[str], modality: str) -> ModelRequestData:
|
2025-04-07 08:06:27 -07:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
model_name = "allenai/Molmo-7B-D-0924"
|
2025-04-07 08:06:27 -07:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
dtype="bfloat16",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-07 08:06:27 -07:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
prompts = [
|
2025-08-21 13:03:00 +08:00
|
|
|
|
f"<|im_start|>user <image>\n{question}<|im_end|><|im_start|>assistant\n"
|
2025-05-26 17:57:54 +01:00
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-08-01 01:35:49 -07:00
|
|
|
|
|
2025-04-07 08:06:27 -07:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-13 23:33:09 -08:00
|
|
|
|
# Molmo2
|
|
|
|
|
|
def run_molmo2(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "allenai/Molmo2-8B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
dtype="bfloat16",
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
max_num_batched_tokens=36864,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video|>"
|
|
|
|
|
|
else:
|
|
|
|
|
|
raise ValueError(f"Unsupported modality for molmo2: {modality}")
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
f"{placeholder}<|im_start|>user\n{question}<|im_end|>\n<|im_start|>assistant\n"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
# Nemontron_VL
|
|
|
|
|
|
def run_nemotron_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "nvidia/Llama-3.1-Nemotron-Nano-VL-8B-V1"
|
2024-08-09 22:51:04 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-08-09 22:51:04 +08:00
|
|
|
|
model=model_name,
|
2024-07-29 18:16:30 +08:00
|
|
|
|
trust_remote_code=True,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
max_model_len=8192,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-07-29 18:16:30 +08:00
|
|
|
|
)
|
2024-08-09 22:51:04 +08:00
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
placeholder = "<image>"
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"{placeholder}\n{question}"}]
|
2025-05-26 17:57:54 +01:00
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-08-01 01:35:49 -07:00
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Stop tokens for InternVL
|
|
|
|
|
|
# models variants may have different stop tokens
|
|
|
|
|
|
# please refer to the model card for the correct "stop words":
|
|
|
|
|
|
# https://huggingface.co/OpenGVLab/InternVL2-2B/blob/main/conversation.py
|
|
|
|
|
|
stop_tokens = ["<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|end|>"]
|
|
|
|
|
|
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
|
|
|
|
|
|
stop_token_ids = [token_id for token_id in stop_token_ids if token_id is not None]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
stop_token_ids=stop_token_ids,
|
2025-03-17 18:00:17 +08:00
|
|
|
|
)
|
2024-07-29 18:16:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-10-07 19:55:12 +08:00
|
|
|
|
# NVLM-D
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_nvlm_d(questions: list[str], modality: str) -> ModelRequestData:
|
2024-10-07 19:55:12 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "nvidia/NVLM-D-72B"
|
|
|
|
|
|
|
|
|
|
|
|
# Adjust this as necessary to fit in GPU
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-10-07 19:55:12 +08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
tensor_parallel_size=4,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-10-07 19:55:12 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-10-07 19:55:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-12 08:56:30 +08:00
|
|
|
|
# Ovis
|
|
|
|
|
|
def run_ovis(questions: list[str], modality: str) -> ModelRequestData:
|
2025-04-30 09:33:29 +02:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "AIDC-AI/Ovis2-1B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
dtype="half",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-30 09:33:29 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
2025-04-30 09:33:29 +02:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-19 21:12:59 +08:00
|
|
|
|
# Ovis2_5
|
|
|
|
|
|
def run_ovis2_5(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "AIDC-AI/Ovis2.5-2B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
dtype="half",
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<image>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<video>"
|
|
|
|
|
|
|
2025-10-07 20:54:22 +08:00
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|im_start|>user\n\n{placeholder}\n{question}<|im_end|>\n<|im_start|>assistant\n"
|
2025-08-19 21:12:59 +08:00
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-03 19:04:22 +08:00
|
|
|
|
# PaddleOCR-VL
|
|
|
|
|
|
def run_paddleocr_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "PaddlePaddle/PaddleOCR-VL"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
placeholder = "<|IMAGE_START|><|IMAGE_PLACEHOLDER|><|IMAGE_END|>"
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(f"<|begin_of_sentence|>User: {question}{placeholder}\nAssistant: ")
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# PaliGemma
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_paligemma(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
2024-07-27 19:53:07 +08:00
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# PaliGemma has special prompt format for VQA
|
2025-03-17 18:00:17 +08:00
|
|
|
|
prompts = ["caption en" for _ in questions]
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="google/paligemma-3b-mix-224",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-12 16:52:39 +08:00
|
|
|
|
)
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-07-27 19:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# PaliGemma 2
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_paligemma2(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
2024-09-05 06:48:10 -06:00
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# PaliGemma 2 has special prompt format for VQA
|
2025-03-17 18:00:17 +08:00
|
|
|
|
prompts = ["caption en" for _ in questions]
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model="google/paligemma2-3b-ft-docci-448",
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-12 16:52:39 +08:00
|
|
|
|
)
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-09-05 06:48:10 -06:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Phi-3-Vision
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_phi3v(questions: list[str], modality: str) -> ModelRequestData:
|
2024-09-23 01:51:44 +08:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2024-09-12 00:31:19 +08:00
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# num_crops is an override kwarg to the multimodal image processor;
|
|
|
|
|
|
# For some models, e.g., Phi-3.5-vision-instruct, it is recommended
|
|
|
|
|
|
# to use 16 for single frame scenarios, and 4 for multi-frame.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Generally speaking, a larger value for num_crops results in more
|
|
|
|
|
|
# tokens per image instance, because it may scale the image more in
|
|
|
|
|
|
# the image preprocessing. Some references in the model docs and the
|
|
|
|
|
|
# formula for image tokens after the preprocessing
|
|
|
|
|
|
# transform can be found below.
|
|
|
|
|
|
#
|
|
|
|
|
|
# https://huggingface.co/microsoft/Phi-3.5-vision-instruct#loading-the-model-locally
|
|
|
|
|
|
# https://huggingface.co/microsoft/Phi-3.5-vision-instruct/blob/main/processing_phi3_v.py#L194
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model="microsoft/Phi-3.5-vision-instruct",
|
|
|
|
|
|
trust_remote_code=True,
|
2024-10-31 10:10:52 -06:00
|
|
|
|
max_model_len=4096,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
max_num_seqs=2,
|
2024-10-23 08:05:18 -06:00
|
|
|
|
# Note - mm_processor_kwargs can also be passed to generate/chat calls
|
2024-12-16 19:23:33 +08:00
|
|
|
|
mm_processor_kwargs={"num_crops": 16},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-09-12 00:31:19 +08:00
|
|
|
|
)
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-09-12 00:31:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-08 01:28:52 +08:00
|
|
|
|
# Phi-4-multimodal-instruct
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_phi4mm(questions: list[str], modality: str) -> ModelRequestData:
|
2025-03-08 01:28:52 +08:00
|
|
|
|
"""
|
|
|
|
|
|
Phi-4-multimodal-instruct supports both image and audio inputs. Here, we
|
|
|
|
|
|
show how to process image inputs.
|
|
|
|
|
|
"""
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_path = snapshot_download("microsoft/Phi-4-multimodal-instruct")
|
|
|
|
|
|
# Since the vision-lora and speech-lora co-exist with the base model,
|
|
|
|
|
|
# we have to manually specify the path of the lora weights.
|
|
|
|
|
|
vision_lora_path = os.path.join(model_path, "vision-lora")
|
|
|
|
|
|
prompts = [
|
2025-05-26 17:57:54 +01:00
|
|
|
|
f"<|user|><|image_1|>{question}<|end|><|assistant|>" for question in questions
|
2025-03-08 01:28:52 +08:00
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2025-03-08 01:28:52 +08:00
|
|
|
|
model=model_path,
|
|
|
|
|
|
trust_remote_code=True,
|
2025-04-19 17:26:11 +08:00
|
|
|
|
max_model_len=5120,
|
2025-03-08 01:28:52 +08:00
|
|
|
|
max_num_seqs=2,
|
2025-04-19 17:26:11 +08:00
|
|
|
|
max_num_batched_tokens=12800,
|
2025-03-08 01:28:52 +08:00
|
|
|
|
enable_lora=True,
|
|
|
|
|
|
max_lora_rank=320,
|
2025-04-19 17:26:11 +08:00
|
|
|
|
# Note - mm_processor_kwargs can also be passed to generate/chat calls
|
|
|
|
|
|
mm_processor_kwargs={"dynamic_hd": 16},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-08 01:28:52 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
lora_requests=[LoRARequest("vision", 1, vision_lora_path)],
|
|
|
|
|
|
)
|
2025-03-08 01:28:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-10-18 15:29:56 -04:00
|
|
|
|
# Pixtral HF-format
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_pixtral_hf(questions: list[str], modality: str) -> ModelRequestData:
|
2024-10-18 15:29:56 -04:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "mistral-community/pixtral-12b"
|
|
|
|
|
|
|
2024-12-31 13:17:22 -08:00
|
|
|
|
# NOTE: Need L40 (or equivalent) to avoid OOM
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-10-18 15:29:56 -04:00
|
|
|
|
model=model_name,
|
2025-04-01 00:01:35 +08:00
|
|
|
|
max_model_len=6144,
|
2024-12-31 13:17:22 -08:00
|
|
|
|
max_num_seqs=2,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-10-18 15:29:56 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"<s>[INST]{question}\n[IMG][/INST]" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-10-18 15:29:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
2025-07-07 00:54:36 +08:00
|
|
|
|
# Qwen-VL
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_qwen_vl(questions: list[str], modality: str) -> ModelRequestData:
|
2024-10-14 07:56:24 -07:00
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model="Qwen/Qwen-VL",
|
2024-10-14 07:56:24 -07:00
|
|
|
|
trust_remote_code=True,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
max_model_len=1024,
|
|
|
|
|
|
max_num_seqs=2,
|
2025-02-13 22:19:15 +08:00
|
|
|
|
hf_overrides={"architectures": ["QwenVLForConditionalGeneration"]},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-10-14 07:56:24 -07:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [f"{question}Picture 1: <img></img>\n" for question in questions]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-10-14 07:56:24 -07:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-16 19:23:33 +08:00
|
|
|
|
# Qwen2-VL
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_qwen2_vl(questions: list[str], modality: str) -> ModelRequestData:
|
2024-12-16 19:23:33 +08:00
|
|
|
|
model_name = "Qwen/Qwen2-VL-7B-Instruct"
|
2024-11-06 19:41:17 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2024-11-08 17:56:58 +08:00
|
|
|
|
model=model_name,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
# Note - mm_processor_kwargs can also be passed to generate/chat calls
|
2024-11-08 17:56:58 +08:00
|
|
|
|
mm_processor_kwargs={
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"min_pixels": 28 * 28,
|
|
|
|
|
|
"max_pixels": 1280 * 28 * 28,
|
2024-11-08 17:56:58 +08:00
|
|
|
|
},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2024-11-08 17:56:58 +08:00
|
|
|
|
)
|
2024-11-06 19:41:17 +08:00
|
|
|
|
|
2024-12-20 00:28:00 +08:00
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-05-26 17:57:54 +01:00
|
|
|
|
(
|
|
|
|
|
|
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2024-12-08 01:10:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-02-05 13:31:38 -08:00
|
|
|
|
# Qwen2.5-VL
|
2025-03-17 18:00:17 +08:00
|
|
|
|
def run_qwen2_5_vl(questions: list[str], modality: str) -> ModelRequestData:
|
2025-02-05 13:31:38 -08:00
|
|
|
|
model_name = "Qwen/Qwen2.5-VL-3B-Instruct"
|
|
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
engine_args = EngineArgs(
|
2025-02-05 13:31:38 -08:00
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"min_pixels": 28 * 28,
|
|
|
|
|
|
"max_pixels": 1280 * 28 * 28,
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-02-05 13:31:38 -08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
prompts = [
|
2025-05-26 17:57:54 +01:00
|
|
|
|
(
|
|
|
|
|
|
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
2025-03-04 07:43:59 -08:00
|
|
|
|
]
|
2025-03-17 18:00:17 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
2025-02-05 13:31:38 -08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-19 14:14:36 +08:00
|
|
|
|
# Qwen2.5-Omni
|
|
|
|
|
|
def run_qwen2_5_omni(questions: list[str], modality: str):
|
|
|
|
|
|
model_name = "Qwen/Qwen2.5-Omni-7B"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"min_pixels": 28 * 28,
|
|
|
|
|
|
"max_pixels": 1280 * 28 * 28,
|
2025-11-13 21:06:06 +08:00
|
|
|
|
"fps": 1,
|
2025-04-19 14:14:36 +08:00
|
|
|
|
},
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-04-19 14:14:36 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|IMAGE|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|VIDEO|>"
|
|
|
|
|
|
|
|
|
|
|
|
default_system = (
|
|
|
|
|
|
"You are Qwen, a virtual human developed by the Qwen Team, Alibaba "
|
|
|
|
|
|
"Group, capable of perceiving auditory and visual inputs, as well as "
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"generating text and speech."
|
|
|
|
|
|
)
|
2025-04-19 14:14:36 +08:00
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
f"<|im_start|>system\n{default_system}<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_bos|>{placeholder}<|vision_eos|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-04-19 14:14:36 +08:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-16 22:01:04 -07:00
|
|
|
|
# Qwen3-VL-Dense
|
|
|
|
|
|
def run_qwen3_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "Qwen/Qwen3-VL-4B-Instruct"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"min_pixels": 28 * 28,
|
|
|
|
|
|
"max_pixels": 1280 * 28 * 28,
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Qwen3-VL-MOE
|
|
|
|
|
|
def run_qwen3_vl_moe(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "Qwen/Qwen3-VL-30B-A3B-Instruct"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
max_num_seqs=5,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"min_pixels": 28 * 28,
|
|
|
|
|
|
"max_pixels": 1280 * 28 * 28,
|
|
|
|
|
|
"fps": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-21 12:08:52 +08:00
|
|
|
|
# R-4B
|
|
|
|
|
|
def run_r_vl(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "YannQi/R-4B"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
f"<|im_start|>user <image>\n{question}<|im_end|><|im_start|>assistant\n"
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=16384,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
# SkyworkR1V
|
|
|
|
|
|
def run_skyworkr1v(questions: list[str], modality: str) -> ModelRequestData:
|
2025-08-01 13:44:10 +08:00
|
|
|
|
assert modality == "image"
|
2025-08-01 01:35:49 -07:00
|
|
|
|
|
|
|
|
|
|
model_name = "Skywork/Skywork-R1V-38B"
|
2025-08-01 13:44:10 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
2025-08-01 01:35:49 -07:00
|
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
messages = [
|
|
|
|
|
|
[{"role": "user", "content": f"<image>\n{question}"}] for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
prompts = tokenizer.apply_chat_template(
|
|
|
|
|
|
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Stop tokens for SkyworkR1V
|
|
|
|
|
|
# https://huggingface.co/Skywork/Skywork-R1V-38B/blob/main/conversation.py
|
|
|
|
|
|
stop_tokens = ["<|end▁of▁sentence|>", "<|endoftext|>"]
|
|
|
|
|
|
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
|
2025-08-01 13:44:10 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
stop_token_ids=stop_token_ids,
|
2025-08-01 13:44:10 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
# SmolVLM2-2.2B-Instruct
|
|
|
|
|
|
def run_smolvlm(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
model_name = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
|
2025-06-21 12:01:51 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
max_model_len=8192,
|
|
|
|
|
|
max_num_seqs=2,
|
|
|
|
|
|
enforce_eager=True,
|
|
|
|
|
|
mm_processor_kwargs={
|
|
|
|
|
|
"max_image_size": {"longest_edge": 384},
|
|
|
|
|
|
},
|
2025-06-21 12:01:51 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
2025-08-01 01:35:49 -07:00
|
|
|
|
prompts = [
|
|
|
|
|
|
(f"<|im_start|>User:<image>{question}<end_of_utterance>\nAssistant:")
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-06-21 12:01:51 +08:00
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Step3
|
|
|
|
|
|
def run_step3(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
assert modality == "image"
|
|
|
|
|
|
|
|
|
|
|
|
model_name = "stepfun-ai/step3-fp8"
|
|
|
|
|
|
|
|
|
|
|
|
# NOTE: Below are verified configurations for step3-fp8
|
|
|
|
|
|
# on 8xH100 GPUs.
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_num_batched_tokens=4096,
|
|
|
|
|
|
gpu_memory_utilization=0.85,
|
|
|
|
|
|
tensor_parallel_size=8,
|
|
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
reasoning_parser="step3",
|
|
|
|
|
|
)
|
2025-06-21 12:01:51 +08:00
|
|
|
|
|
|
|
|
|
|
prompts = [
|
2025-08-01 01:35:49 -07:00
|
|
|
|
"<|begin▁of▁sentence|> You are a helpful assistant. <|BOT|>user\n "
|
|
|
|
|
|
f"<im_patch>{question} <|EOT|><|BOT|>assistant\n<think>\n"
|
2025-06-21 12:01:51 +08:00
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
# omni-research/Tarsier-7b
|
|
|
|
|
|
def run_tarsier(questions: list[str], modality: str) -> ModelRequestData:
|
2025-03-29 11:39:21 +08:00
|
|
|
|
assert modality == "image"
|
2025-08-01 01:35:49 -07:00
|
|
|
|
model_name = "omni-research/Tarsier-7b"
|
2025-03-29 11:39:21 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
trust_remote_code=True,
|
|
|
|
|
|
max_model_len=4096,
|
2025-05-07 00:12:28 +08:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
2025-03-29 11:39:21 +08:00
|
|
|
|
)
|
2025-08-01 01:35:49 -07:00
|
|
|
|
prompts = [(f"USER: <image>\n{question} ASSISTANT:") for question in questions]
|
2025-03-29 11:39:21 +08:00
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
2025-05-26 17:57:54 +01:00
|
|
|
|
)
|
2025-03-29 11:39:21 +08:00
|
|
|
|
|
2025-08-01 01:35:49 -07:00
|
|
|
|
|
|
|
|
|
|
def run_tarsier2(questions: list[str], modality: str) -> ModelRequestData:
|
|
|
|
|
|
model_name = "omni-research/Tarsier2-Recap-7b"
|
|
|
|
|
|
|
|
|
|
|
|
engine_args = EngineArgs(
|
|
|
|
|
|
model=model_name,
|
|
|
|
|
|
max_model_len=4096,
|
2025-12-02 21:49:44 +00:00
|
|
|
|
hf_overrides={
|
|
|
|
|
|
"architectures": ["Tarsier2ForConditionalGeneration"],
|
|
|
|
|
|
"model_type": "tarsier2",
|
|
|
|
|
|
},
|
2025-08-01 01:35:49 -07:00
|
|
|
|
limit_mm_per_prompt={modality: 1},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if modality == "image":
|
|
|
|
|
|
placeholder = "<|image_pad|>"
|
|
|
|
|
|
elif modality == "video":
|
|
|
|
|
|
placeholder = "<|video_pad|>"
|
|
|
|
|
|
|
|
|
|
|
|
prompts = [
|
|
|
|
|
|
(
|
|
|
|
|
|
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
|
|
|
|
|
f"<|im_start|>user\n<|vision_start|>{placeholder}<|vision_end|>"
|
|
|
|
|
|
f"{question}<|im_end|>\n"
|
|
|
|
|
|
"<|im_start|>assistant\n"
|
|
|
|
|
|
)
|
|
|
|
|
|
for question in questions
|
|
|
|
|
|
]
|
2025-03-29 11:39:21 +08:00
|
|
|
|
|
|
|
|
|
|
return ModelRequestData(
|
|
|
|
|
|
engine_args=engine_args,
|
|
|
|
|
|
prompts=prompts,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 22:44:13 -07:00
|
|
|
|
model_example_map = {
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"aria": run_aria,
|
2025-04-01 09:30:43 -07:00
|
|
|
|
"aya_vision": run_aya_vision,
|
2025-12-15 14:58:23 +08:00
|
|
|
|
"bagel": run_bagel,
|
2025-10-20 10:31:26 +08:00
|
|
|
|
"bee": run_bee,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"blip-2": run_blip2,
|
|
|
|
|
|
"chameleon": run_chameleon,
|
2025-08-12 04:39:54 -04:00
|
|
|
|
"command_a_vision": run_command_a_vision,
|
2025-01-12 16:17:24 +08:00
|
|
|
|
"deepseek_vl_v2": run_deepseek_vl2,
|
2025-10-22 22:59:15 +08:00
|
|
|
|
"deepseek_ocr": run_deepseek_ocr,
|
|
|
|
|
|
"dots_ocr": run_dots_ocr,
|
2026-01-21 18:39:53 +09:00
|
|
|
|
"eagle2_5": run_eagle2_5,
|
2025-08-27 12:02:55 +08:00
|
|
|
|
"ernie45_vl": run_ernie45_vl,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"fuyu": run_fuyu,
|
2025-03-12 08:36:33 -07:00
|
|
|
|
"gemma3": run_gemma3,
|
2025-08-09 18:56:25 +02:00
|
|
|
|
"gemma3n": run_gemma3n,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"glm4v": run_glm4v,
|
2025-07-01 20:48:26 +08:00
|
|
|
|
"glm4_1v": run_glm4_1v,
|
2025-08-19 16:56:31 +09:00
|
|
|
|
"glm4_5v": run_glm4_5v,
|
|
|
|
|
|
"glm4_5v_fp8": run_glm4_5v_fp8,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"h2ovl_chat": run_h2ovl,
|
2025-11-25 11:28:51 +08:00
|
|
|
|
"hunyuan_vl": run_hunyuan_vl,
|
2025-07-25 22:05:42 +09:00
|
|
|
|
"hyperclovax_seed_vision": run_hyperclovax_seed_vision,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"idefics3": run_idefics3,
|
2025-07-26 19:14:04 +08:00
|
|
|
|
"interns1": run_interns1,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"internvl_chat": run_internvl,
|
2026-01-13 01:39:02 +09:00
|
|
|
|
"kanana_v": run_kanana_v,
|
2025-07-02 14:35:04 +08:00
|
|
|
|
"keye_vl": run_keye_vl,
|
2025-09-01 18:50:27 +08:00
|
|
|
|
"keye_vl1_5": run_keye_vl1_5,
|
2025-04-15 05:41:48 +08:00
|
|
|
|
"kimi_vl": run_kimi_vl,
|
2025-10-17 07:05:24 +02:00
|
|
|
|
"lightonocr": run_lightonocr,
|
2026-01-08 05:00:27 -08:00
|
|
|
|
"lfm2_vl": run_lfm2_vl,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
"llama4": run_llama4,
|
2024-07-26 22:44:13 -07:00
|
|
|
|
"llava": run_llava,
|
|
|
|
|
|
"llava-next": run_llava_next,
|
2024-09-11 13:21:36 +08:00
|
|
|
|
"llava-next-video": run_llava_next_video,
|
2024-09-23 01:51:44 +08:00
|
|
|
|
"llava-onevision": run_llava_onevision,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"mantis": run_mantis,
|
2025-01-29 17:24:59 +08:00
|
|
|
|
"minicpmo": run_minicpmo,
|
2024-07-26 22:44:13 -07:00
|
|
|
|
"minicpmv": run_minicpmv,
|
2025-08-19 16:49:29 +08:00
|
|
|
|
"minimax_vl_01": run_minimax_vl_01,
|
2025-04-01 07:10:05 -06:00
|
|
|
|
"mistral3": run_mistral3,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"molmo": run_molmo,
|
2026-01-13 23:33:09 -08:00
|
|
|
|
"molmo2": run_molmo2,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
"nemotron_vl": run_nemotron_vl,
|
2024-10-07 19:55:12 +08:00
|
|
|
|
"NVLM_D": run_nvlm_d,
|
2025-05-12 08:56:30 +08:00
|
|
|
|
"ovis": run_ovis,
|
2025-08-19 21:12:59 +08:00
|
|
|
|
"ovis2_5": run_ovis2_5,
|
2025-11-03 19:04:22 +08:00
|
|
|
|
"paddleocr_vl": run_paddleocr_vl,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"paligemma": run_paligemma,
|
|
|
|
|
|
"paligemma2": run_paligemma2,
|
|
|
|
|
|
"phi3_v": run_phi3v,
|
2025-03-08 01:28:52 +08:00
|
|
|
|
"phi4_mm": run_phi4mm,
|
2024-12-16 19:23:33 +08:00
|
|
|
|
"pixtral_hf": run_pixtral_hf,
|
2024-09-05 06:48:10 -06:00
|
|
|
|
"qwen_vl": run_qwen_vl,
|
2024-09-12 00:31:19 +08:00
|
|
|
|
"qwen2_vl": run_qwen2_vl,
|
2025-02-05 13:31:38 -08:00
|
|
|
|
"qwen2_5_vl": run_qwen2_5_vl,
|
2025-04-19 14:14:36 +08:00
|
|
|
|
"qwen2_5_omni": run_qwen2_5_omni,
|
2025-09-16 22:01:04 -07:00
|
|
|
|
"qwen3_vl": run_qwen3_vl,
|
|
|
|
|
|
"qwen3_vl_moe": run_qwen3_vl_moe,
|
2025-08-21 12:08:52 +08:00
|
|
|
|
"rvl": run_r_vl,
|
2025-03-29 11:39:21 +08:00
|
|
|
|
"skywork_chat": run_skyworkr1v,
|
2025-04-09 10:12:17 +08:00
|
|
|
|
"smolvlm": run_smolvlm,
|
2025-08-01 01:35:49 -07:00
|
|
|
|
"step3": run_step3,
|
2025-06-03 13:13:13 +08:00
|
|
|
|
"tarsier": run_tarsier,
|
2025-06-21 12:01:51 +08:00
|
|
|
|
"tarsier2": run_tarsier2,
|
2024-07-26 22:44:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-15 20:45:06 +08:00
|
|
|
|
MODELS_NEED_VIDEO_METADATA = [
|
|
|
|
|
|
"glm4_1v",
|
|
|
|
|
|
"glm4_5v",
|
|
|
|
|
|
"glm4_5v_fp8",
|
2026-01-13 23:33:09 -08:00
|
|
|
|
"molmo2",
|
2025-09-16 22:01:04 -07:00
|
|
|
|
"qwen3_vl",
|
|
|
|
|
|
"qwen3_vl_moe",
|
2025-09-15 20:45:06 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-11 13:21:36 +08:00
|
|
|
|
def get_multi_modal_input(args):
|
|
|
|
|
|
"""
|
|
|
|
|
|
return {
|
|
|
|
|
|
"data": image or video,
|
|
|
|
|
|
"question": question,
|
|
|
|
|
|
}
|
|
|
|
|
|
"""
|
|
|
|
|
|
if args.modality == "image":
|
|
|
|
|
|
# Input image and question
|
2025-05-26 17:57:54 +01:00
|
|
|
|
image = convert_image_mode(ImageAsset("cherry_blossom").pil_image, "RGB")
|
2025-03-04 07:43:59 -08:00
|
|
|
|
img_questions = [
|
|
|
|
|
|
"What is the content of this image?",
|
|
|
|
|
|
"Describe the content of this image in detail.",
|
|
|
|
|
|
"What's in the image?",
|
|
|
|
|
|
"Where is this image taken?",
|
|
|
|
|
|
]
|
2024-09-11 13:21:36 +08:00
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
"data": image,
|
2025-03-04 07:43:59 -08:00
|
|
|
|
"questions": img_questions,
|
2024-09-11 13:21:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if args.modality == "video":
|
|
|
|
|
|
# Input video and question
|
2025-09-15 20:45:06 +08:00
|
|
|
|
needs_metadata = args.model_type in MODELS_NEED_VIDEO_METADATA
|
2025-05-26 17:57:54 +01:00
|
|
|
|
video = VideoAsset(name="baby_reading", num_frames=args.num_frames).np_ndarrays
|
2025-07-01 20:48:26 +08:00
|
|
|
|
metadata = VideoAsset(name="baby_reading", num_frames=args.num_frames).metadata
|
2025-03-04 07:43:59 -08:00
|
|
|
|
vid_questions = ["Why is this video funny?"]
|
2024-09-11 13:21:36 +08:00
|
|
|
|
|
|
|
|
|
|
return {
|
2025-09-15 20:45:06 +08:00
|
|
|
|
"data": ([(video, metadata)] if needs_metadata else video),
|
2025-03-04 07:43:59 -08:00
|
|
|
|
"questions": vid_questions,
|
2024-09-11 13:21:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
msg = f"Modality {args.modality} is not supported."
|
|
|
|
|
|
raise ValueError(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
def apply_image_repeat(
|
|
|
|
|
|
image_repeat_prob, num_prompts, data, prompts: list[str], modality
|
|
|
|
|
|
):
|
|
|
|
|
|
"""Repeats images with provided probability of "image_repeat_prob".
|
2024-12-11 19:55:30 -05:00
|
|
|
|
Used to simulate hit/miss for the MM preprocessor cache.
|
|
|
|
|
|
"""
|
2025-05-26 17:57:54 +01:00
|
|
|
|
assert image_repeat_prob <= 1.0 and image_repeat_prob >= 0
|
2024-12-11 19:55:30 -05:00
|
|
|
|
no_yes = [0, 1]
|
|
|
|
|
|
probs = [1.0 - image_repeat_prob, image_repeat_prob]
|
|
|
|
|
|
|
|
|
|
|
|
inputs = []
|
2025-09-12 19:16:06 -07:00
|
|
|
|
inputs_with_empty_media = []
|
2024-12-11 19:55:30 -05:00
|
|
|
|
cur_image = data
|
|
|
|
|
|
for i in range(num_prompts):
|
|
|
|
|
|
if image_repeat_prob is not None:
|
|
|
|
|
|
res = random.choices(no_yes, probs)[0]
|
|
|
|
|
|
if res == 0:
|
|
|
|
|
|
# No repeat => Modify one pixel
|
|
|
|
|
|
cur_image = cur_image.copy()
|
|
|
|
|
|
new_val = (i // 256 // 256, i // 256, i % 256)
|
|
|
|
|
|
cur_image.putpixel((0, 0), new_val)
|
|
|
|
|
|
|
2025-09-12 19:16:06 -07:00
|
|
|
|
uuid = "uuid_{}".format(i)
|
|
|
|
|
|
|
2025-05-26 17:57:54 +01:00
|
|
|
|
inputs.append(
|
|
|
|
|
|
{
|
|
|
|
|
|
"prompt": prompts[i % len(prompts)],
|
|
|
|
|
|
"multi_modal_data": {modality: cur_image},
|
2025-09-12 19:16:06 -07:00
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
inputs_with_empty_media.append(
|
|
|
|
|
|
{
|
|
|
|
|
|
"prompt": prompts[i % len(prompts)],
|
|
|
|
|
|
"multi_modal_data": {modality: None},
|
|
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
2024-12-11 19:55:30 -05:00
|
|
|
|
}
|
2025-05-26 17:57:54 +01:00
|
|
|
|
)
|
2024-12-11 19:55:30 -05:00
|
|
|
|
|
2025-09-12 19:16:06 -07:00
|
|
|
|
return inputs, inputs_with_empty_media
|
2024-12-11 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-11 12:57:16 +08:00
|
|
|
|
@contextmanager
|
|
|
|
|
|
def time_counter(enable: bool):
|
|
|
|
|
|
if enable:
|
|
|
|
|
|
import time
|
2025-05-26 17:57:54 +01:00
|
|
|
|
|
2025-04-11 12:57:16 +08:00
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
yield
|
|
|
|
|
|
elapsed_time = time.time() - start_time
|
|
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
print("-- generate time = {}".format(elapsed_time))
|
|
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
else:
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-15 16:05:30 +08:00
|
|
|
|
def parse_args():
|
|
|
|
|
|
parser = FlexibleArgumentParser(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
description="Demo on using vLLM for offline inference with "
|
|
|
|
|
|
"vision language models for text generation"
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--model-type",
|
|
|
|
|
|
"-m",
|
|
|
|
|
|
type=str,
|
|
|
|
|
|
default="llava",
|
|
|
|
|
|
choices=model_example_map.keys(),
|
|
|
|
|
|
help='Huggingface "model_type".',
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--num-prompts", type=int, default=4, help="Number of prompts to run."
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--modality",
|
|
|
|
|
|
type=str,
|
|
|
|
|
|
default="image",
|
|
|
|
|
|
choices=["image", "video"],
|
|
|
|
|
|
help="Modality of the input.",
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--num-frames",
|
|
|
|
|
|
type=int,
|
|
|
|
|
|
default=16,
|
|
|
|
|
|
help="Number of frames to extract from the video.",
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--seed",
|
|
|
|
|
|
type=int,
|
2025-12-11 11:59:39 +08:00
|
|
|
|
default=0,
|
2025-05-26 17:57:54 +01:00
|
|
|
|
help="Set the seed when initializing `vllm.LLM`.",
|
|
|
|
|
|
)
|
2025-04-15 16:05:30 +08:00
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"--image-repeat-prob",
|
2025-04-15 16:05:30 +08:00
|
|
|
|
type=float,
|
|
|
|
|
|
default=None,
|
2025-05-26 17:57:54 +01:00
|
|
|
|
help="Simulates the hit-ratio for multi-modal preprocessor cache (if enabled)",
|
|
|
|
|
|
)
|
2025-04-15 16:05:30 +08:00
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-08-08 00:47:10 +08:00
|
|
|
|
"--disable-mm-processor-cache",
|
2025-05-26 17:57:54 +01:00
|
|
|
|
action="store_true",
|
2025-08-07 16:45:04 +08:00
|
|
|
|
help="If True, disables caching of multi-modal processor.",
|
2025-05-26 17:57:54 +01:00
|
|
|
|
)
|
2025-04-15 16:05:30 +08:00
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"--time-generate",
|
|
|
|
|
|
action="store_true",
|
|
|
|
|
|
help="If True, then print the total generate() call time",
|
|
|
|
|
|
)
|
2025-04-15 16:05:30 +08:00
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"--use-different-prompt-per-request",
|
|
|
|
|
|
action="store_true",
|
|
|
|
|
|
help="If True, then use different prompt (with the same multi-modal "
|
|
|
|
|
|
"data) for each request.",
|
|
|
|
|
|
)
|
2025-09-12 19:16:06 -07:00
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--verify-mm-cache-hit-with-uuids",
|
|
|
|
|
|
action="store_true",
|
|
|
|
|
|
help="If True, will send all requests in a second batch with empty mm "
|
|
|
|
|
|
"data to verify cache hits with UUIDs.",
|
|
|
|
|
|
)
|
2025-11-25 14:03:20 +08:00
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--tensor-parallel-size",
|
|
|
|
|
|
"-tp",
|
|
|
|
|
|
type=int,
|
|
|
|
|
|
default=None,
|
|
|
|
|
|
help="Tensor parallel size to override the model's default setting. ",
|
|
|
|
|
|
)
|
2025-04-15 16:05:30 +08:00
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 22:44:13 -07:00
|
|
|
|
def main(args):
|
|
|
|
|
|
model = args.model_type
|
|
|
|
|
|
if model not in model_example_map:
|
|
|
|
|
|
raise ValueError(f"Model type {model} is not supported.")
|
|
|
|
|
|
|
2025-11-25 14:03:20 +08:00
|
|
|
|
if args.tensor_parallel_size is not None and args.tensor_parallel_size < 1:
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"tensor_parallel_size must be a positive integer, "
|
|
|
|
|
|
f"got {args.tensor_parallel_size}"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2024-09-11 13:21:36 +08:00
|
|
|
|
modality = args.modality
|
|
|
|
|
|
mm_input = get_multi_modal_input(args)
|
|
|
|
|
|
data = mm_input["data"]
|
2025-03-04 07:43:59 -08:00
|
|
|
|
questions = mm_input["questions"]
|
2024-09-11 13:21:36 +08:00
|
|
|
|
|
2025-03-17 18:00:17 +08:00
|
|
|
|
req_data = model_example_map[model](questions, modality)
|
|
|
|
|
|
|
2025-04-12 16:52:39 +08:00
|
|
|
|
# Disable other modalities to save memory
|
|
|
|
|
|
default_limits = {"image": 0, "video": 0, "audio": 0}
|
|
|
|
|
|
req_data.engine_args.limit_mm_per_prompt = default_limits | dict(
|
2025-05-26 17:57:54 +01:00
|
|
|
|
req_data.engine_args.limit_mm_per_prompt or {}
|
|
|
|
|
|
)
|
2025-04-12 16:52:39 +08:00
|
|
|
|
|
|
|
|
|
|
engine_args = asdict(req_data.engine_args) | {
|
|
|
|
|
|
"seed": args.seed,
|
2025-08-08 00:47:10 +08:00
|
|
|
|
"mm_processor_cache_gb": 0 if args.disable_mm_processor_cache else 4,
|
2025-04-12 16:52:39 +08:00
|
|
|
|
}
|
2025-11-25 14:03:20 +08:00
|
|
|
|
if args.tensor_parallel_size is not None:
|
|
|
|
|
|
engine_args["tensor_parallel_size"] = args.tensor_parallel_size
|
2025-03-17 18:00:17 +08:00
|
|
|
|
llm = LLM(**engine_args)
|
|
|
|
|
|
|
2025-03-04 07:43:59 -08:00
|
|
|
|
# Don't want to check the flag multiple times, so just hijack `prompts`.
|
2025-05-26 17:57:54 +01:00
|
|
|
|
prompts = (
|
|
|
|
|
|
req_data.prompts
|
|
|
|
|
|
if args.use_different_prompt_per_request
|
|
|
|
|
|
else [req_data.prompts[0]]
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
# We set temperature to 0.2 so that outputs can be different
|
|
|
|
|
|
# even when all prompts are identical when running batch inference.
|
2025-10-22 22:59:15 +08:00
|
|
|
|
sampling_params = (
|
|
|
|
|
|
SamplingParams(
|
|
|
|
|
|
temperature=0.2, max_tokens=64, stop_token_ids=req_data.stop_token_ids
|
|
|
|
|
|
)
|
|
|
|
|
|
if req_data.sampling_params is None
|
|
|
|
|
|
else req_data.sampling_params
|
2025-05-26 17:57:54 +01:00
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
assert args.num_prompts > 0
|
|
|
|
|
|
if args.num_prompts == 1:
|
|
|
|
|
|
# Single inference
|
2025-09-12 19:16:06 -07:00
|
|
|
|
uuid = "uuid_0"
|
2024-07-26 22:44:13 -07:00
|
|
|
|
inputs = {
|
2025-03-04 07:43:59 -08:00
|
|
|
|
"prompt": prompts[0],
|
2025-05-26 17:57:54 +01:00
|
|
|
|
"multi_modal_data": {modality: data},
|
2025-09-12 19:16:06 -07:00
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
|
|
|
|
|
}
|
|
|
|
|
|
inputs_with_empty_media = {
|
|
|
|
|
|
"prompt": prompts[0],
|
|
|
|
|
|
"multi_modal_data": {modality: None},
|
|
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
2024-07-26 22:44:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Batch inference
|
2024-12-11 19:55:30 -05:00
|
|
|
|
if args.image_repeat_prob is not None:
|
|
|
|
|
|
# Repeat images with specified probability of "image_repeat_prob"
|
2025-09-12 19:16:06 -07:00
|
|
|
|
inputs, inputs_with_empty_media = apply_image_repeat(
|
|
|
|
|
|
args.image_repeat_prob,
|
|
|
|
|
|
args.num_prompts,
|
|
|
|
|
|
data,
|
|
|
|
|
|
prompts,
|
|
|
|
|
|
modality,
|
2025-05-26 17:57:54 +01:00
|
|
|
|
)
|
2024-12-11 19:55:30 -05:00
|
|
|
|
else:
|
|
|
|
|
|
# Use the same image for all prompts
|
2025-09-12 19:16:06 -07:00
|
|
|
|
inputs = []
|
|
|
|
|
|
inputs_with_empty_media = []
|
|
|
|
|
|
for i in range(args.num_prompts):
|
|
|
|
|
|
uuid = "uuid_{}".format(i)
|
|
|
|
|
|
inputs.append(
|
|
|
|
|
|
{
|
|
|
|
|
|
"prompt": prompts[i % len(prompts)],
|
|
|
|
|
|
"multi_modal_data": {modality: data},
|
|
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
inputs_with_empty_media.append(
|
|
|
|
|
|
{
|
|
|
|
|
|
"prompt": prompts[i % len(prompts)],
|
|
|
|
|
|
"multi_modal_data": {modality: None},
|
|
|
|
|
|
"multi_modal_uuids": {modality: uuid},
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
2024-12-11 19:55:30 -05:00
|
|
|
|
|
2025-04-11 12:57:16 +08:00
|
|
|
|
# Add LoRA request if applicable
|
2025-05-26 17:57:54 +01:00
|
|
|
|
lora_request = (
|
|
|
|
|
|
req_data.lora_requests * args.num_prompts if req_data.lora_requests else None
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-04-11 12:57:16 +08:00
|
|
|
|
with time_counter(args.time_generate):
|
|
|
|
|
|
outputs = llm.generate(
|
|
|
|
|
|
inputs,
|
|
|
|
|
|
sampling_params=sampling_params,
|
|
|
|
|
|
lora_request=lora_request,
|
|
|
|
|
|
)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-04-08 18:42:32 +08:00
|
|
|
|
print("-" * 50)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
for o in outputs:
|
|
|
|
|
|
generated_text = o.outputs[0].text
|
|
|
|
|
|
print(generated_text)
|
2025-04-08 18:42:32 +08:00
|
|
|
|
print("-" * 50)
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
2025-09-12 19:16:06 -07:00
|
|
|
|
if args.verify_mm_cache_hit_with_uuids:
|
|
|
|
|
|
try:
|
|
|
|
|
|
# Verify cache hits with UUIDs
|
|
|
|
|
|
print(
|
|
|
|
|
|
"Sending a second batch of requests with empty media"
|
|
|
|
|
|
" and matching UUIDs."
|
|
|
|
|
|
)
|
|
|
|
|
|
outputs = llm.generate(
|
|
|
|
|
|
inputs_with_empty_media,
|
|
|
|
|
|
sampling_params=sampling_params,
|
|
|
|
|
|
lora_request=lora_request,
|
|
|
|
|
|
)
|
|
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
for o in outputs:
|
|
|
|
|
|
generated_text = o.outputs[0].text
|
|
|
|
|
|
print(generated_text)
|
|
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print(f"Failed to verify cache hits with UUIDs. Error: {e}")
|
|
|
|
|
|
|
2024-07-26 22:44:13 -07:00
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-04-15 16:05:30 +08:00
|
|
|
|
args = parse_args()
|
2024-11-08 17:56:58 +08:00
|
|
|
|
main(args)
|