2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-10-19 02:31:58 +08:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from vllm import LLM
|
2025-02-18 23:34:59 -08:00
|
|
|
from vllm.config import LoadFormat
|
2024-10-19 02:31:58 +08:00
|
|
|
|
2025-02-18 23:34:59 -08:00
|
|
|
from ...conftest import MODEL_WEIGHTS_S3_BUCKET
|
2024-10-19 02:31:58 +08:00
|
|
|
from ..openai.test_vision import TEST_IMAGE_URLS
|
|
|
|
|
2025-02-18 23:34:59 -08:00
|
|
|
RUNAI_STREAMER_LOAD_FORMAT = LoadFormat.RUNAI_STREAMER
|
|
|
|
|
2024-10-19 02:31:58 +08:00
|
|
|
|
|
|
|
def test_chat():
|
2025-02-18 23:34:59 -08:00
|
|
|
llm = LLM(model=f"{MODEL_WEIGHTS_S3_BUCKET}/Llama-3.2-1B-Instruct",
|
|
|
|
load_format=RUNAI_STREAMER_LOAD_FORMAT)
|
2024-10-19 02:31:58 +08:00
|
|
|
|
|
|
|
prompt1 = "Explain the concept of entropy."
|
|
|
|
messages = [
|
|
|
|
{
|
|
|
|
"role": "system",
|
|
|
|
"content": "You are a helpful assistant"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"role": "user",
|
|
|
|
"content": prompt1
|
|
|
|
},
|
|
|
|
]
|
|
|
|
outputs = llm.chat(messages)
|
|
|
|
assert len(outputs) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_multi_chat():
|
2025-02-18 23:34:59 -08:00
|
|
|
llm = LLM(model=f"{MODEL_WEIGHTS_S3_BUCKET}/Llama-3.2-1B-Instruct",
|
|
|
|
load_format=RUNAI_STREAMER_LOAD_FORMAT)
|
2024-10-19 02:31:58 +08:00
|
|
|
|
|
|
|
prompt1 = "Explain the concept of entropy."
|
|
|
|
prompt2 = "Explain what among us is."
|
|
|
|
|
|
|
|
conversation1 = [
|
|
|
|
{
|
|
|
|
"role": "system",
|
|
|
|
"content": "You are a helpful assistant"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"role": "user",
|
|
|
|
"content": prompt1
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
conversation2 = [
|
|
|
|
{
|
|
|
|
"role": "system",
|
|
|
|
"content": "You are a helpful assistant"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"role": "user",
|
|
|
|
"content": prompt2
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
messages = [conversation1, conversation2]
|
|
|
|
|
|
|
|
outputs = llm.chat(messages)
|
|
|
|
assert len(outputs) == 2
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("image_urls",
|
|
|
|
[[TEST_IMAGE_URLS[0], TEST_IMAGE_URLS[1]]])
|
|
|
|
def test_chat_multi_image(image_urls: List[str]):
|
|
|
|
llm = LLM(
|
2025-02-18 23:34:59 -08:00
|
|
|
model=f"{MODEL_WEIGHTS_S3_BUCKET}/Phi-3.5-vision-instruct",
|
|
|
|
load_format=RUNAI_STREAMER_LOAD_FORMAT,
|
2024-10-19 02:31:58 +08:00
|
|
|
dtype="bfloat16",
|
|
|
|
max_model_len=4096,
|
|
|
|
max_num_seqs=5,
|
|
|
|
enforce_eager=True,
|
|
|
|
trust_remote_code=True,
|
|
|
|
limit_mm_per_prompt={"image": 2},
|
|
|
|
)
|
|
|
|
|
|
|
|
messages = [{
|
|
|
|
"role":
|
|
|
|
"user",
|
|
|
|
"content": [
|
|
|
|
*({
|
|
|
|
"type": "image_url",
|
|
|
|
"image_url": {
|
|
|
|
"url": image_url
|
|
|
|
}
|
|
|
|
} for image_url in image_urls),
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"text": "What's in this image?"
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}]
|
|
|
|
outputs = llm.chat(messages)
|
|
|
|
assert len(outputs) >= 0
|