2025-11-14 03:03:55 -08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
import requests
|
|
|
|
|
|
2026-01-23 20:03:44 +08:00
|
|
|
from tests.entrypoints.test_utils import encode_base64_content_from_url
|
2025-11-14 03:03:55 -08:00
|
|
|
from tests.utils import RemoteOpenAIServer
|
2025-12-01 15:30:43 +08:00
|
|
|
from vllm.entrypoints.pooling.classify.protocol import ClassificationResponse
|
2025-11-14 03:03:55 -08:00
|
|
|
|
2026-01-23 20:03:44 +08:00
|
|
|
MODEL_NAME = "muziyongshixin/Qwen2.5-VL-7B-for-VideoCls"
|
2025-11-14 03:03:55 -08:00
|
|
|
MAXIMUM_VIDEOS = 1
|
|
|
|
|
|
|
|
|
|
HF_OVERRIDES = {
|
|
|
|
|
"text_config": {
|
|
|
|
|
"architectures": ["Qwen2_5_VLForSequenceClassification"],
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-01-23 20:03:44 +08:00
|
|
|
input_text = "This product was excellent and exceeded my expectations"
|
|
|
|
|
image_url = "https://vllm-public-assets.s3.us-west-2.amazonaws.com/multimodal_asset/cat_snow.jpg"
|
|
|
|
|
image_base64 = encode_base64_content_from_url(image_url)
|
|
|
|
|
video_url = "https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4"
|
2025-11-14 03:03:55 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2026-01-23 20:03:44 +08:00
|
|
|
def server():
|
2025-11-14 03:03:55 -08:00
|
|
|
args = [
|
|
|
|
|
"--runner",
|
|
|
|
|
"pooling",
|
|
|
|
|
"--max-model-len",
|
|
|
|
|
"5000",
|
|
|
|
|
"--enforce-eager",
|
|
|
|
|
"--limit-mm-per-prompt",
|
|
|
|
|
json.dumps({"video": MAXIMUM_VIDEOS}),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
with RemoteOpenAIServer(
|
2026-01-23 20:03:44 +08:00
|
|
|
MODEL_NAME, args, override_hf_configs=HF_OVERRIDES
|
2025-11-14 03:03:55 -08:00
|
|
|
) as remote_server:
|
|
|
|
|
yield remote_server
|
|
|
|
|
|
|
|
|
|
|
2026-01-23 20:03:44 +08:00
|
|
|
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
|
|
|
|
def test_chat_text_request(server: RemoteOpenAIServer, model_name: str):
|
|
|
|
|
messages = [
|
|
|
|
|
{
|
|
|
|
|
"role": "assistant",
|
|
|
|
|
"content": "Please classify this text request.",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"role": "user",
|
|
|
|
|
"content": input_text,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
|
|
|
|
server.url_for("classify"),
|
|
|
|
|
json={"model": model_name, "messages": messages},
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
output = ClassificationResponse.model_validate(response.json())
|
|
|
|
|
|
|
|
|
|
assert output.object == "list"
|
|
|
|
|
assert output.model == model_name
|
|
|
|
|
assert len(output.data) == 1
|
|
|
|
|
assert len(output.data[0].probs) == 2
|
|
|
|
|
assert output.usage.prompt_tokens == 35
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
|
|
|
|
def test_chat_image_url_request(server: RemoteOpenAIServer, model_name: str):
|
|
|
|
|
messages = [
|
|
|
|
|
{
|
|
|
|
|
"role": "user",
|
|
|
|
|
"content": [
|
|
|
|
|
{"type": "text", "text": "Please classify this image."},
|
|
|
|
|
{"type": "image_url", "image_url": {"url": image_url}},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
|
|
|
|
server.url_for("classify"),
|
|
|
|
|
json={"model": model_name, "messages": messages},
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
output = ClassificationResponse.model_validate(response.json())
|
|
|
|
|
|
|
|
|
|
assert output.object == "list"
|
|
|
|
|
assert output.model == model_name
|
|
|
|
|
assert len(output.data) == 1
|
|
|
|
|
assert len(output.data[0].probs) == 2
|
|
|
|
|
assert output.usage.prompt_tokens == 47
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
|
|
|
|
def test_chat_image_base64_request(server: RemoteOpenAIServer, model_name: str):
|
2025-11-14 03:03:55 -08:00
|
|
|
messages = [
|
|
|
|
|
{
|
|
|
|
|
"role": "user",
|
|
|
|
|
"content": [
|
2026-01-23 20:03:44 +08:00
|
|
|
{"type": "text", "text": "Please classify this image."},
|
|
|
|
|
{"type": "image_url", "image_url": image_base64},
|
2025-11-14 03:03:55 -08:00
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
2026-01-23 20:03:44 +08:00
|
|
|
server.url_for("classify"),
|
2025-11-14 03:03:55 -08:00
|
|
|
json={"model": model_name, "messages": messages},
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
output = ClassificationResponse.model_validate(response.json())
|
|
|
|
|
|
|
|
|
|
assert output.object == "list"
|
|
|
|
|
assert output.model == model_name
|
|
|
|
|
assert len(output.data) == 1
|
|
|
|
|
assert len(output.data[0].probs) == 2
|
2026-01-23 20:03:44 +08:00
|
|
|
assert output.usage.prompt_tokens == 47
|
2025-11-14 03:03:55 -08:00
|
|
|
|
|
|
|
|
|
2026-01-23 20:03:44 +08:00
|
|
|
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
|
|
|
|
def test_chat_video_url_request(server: RemoteOpenAIServer, model_name: str):
|
2025-11-14 03:03:55 -08:00
|
|
|
messages = [
|
|
|
|
|
{
|
|
|
|
|
"role": "user",
|
|
|
|
|
"content": [
|
|
|
|
|
{"type": "text", "text": "Please classify this video."},
|
2026-01-23 20:03:44 +08:00
|
|
|
{"type": "video_url", "video_url": {"url": video_url}},
|
2025-11-14 03:03:55 -08:00
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
2026-01-23 20:03:44 +08:00
|
|
|
server.url_for("classify"),
|
2025-11-14 03:03:55 -08:00
|
|
|
json={"model": model_name, "messages": messages},
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
output = ClassificationResponse.model_validate(response.json())
|
|
|
|
|
|
|
|
|
|
assert output.object == "list"
|
|
|
|
|
assert output.model == model_name
|
|
|
|
|
assert len(output.data) == 1
|
|
|
|
|
assert len(output.data[0].probs) == 2
|
|
|
|
|
assert output.usage.prompt_tokens == 4807
|