2023-09-01 11:19:43 +09:00
|
|
|
"""Compare the outputs of HF and vLLM when using greedy sampling.
|
|
|
|
|
2024-03-29 13:06:40 +09:00
|
|
|
This test only tests small models. Big models such as 7B should be tested from
|
|
|
|
test_big_models.py because it could use a larger instance to run tests.
|
|
|
|
|
|
|
|
Run `pytest tests/models/test_models.py`.
|
2023-09-01 11:19:43 +09:00
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
2024-11-05 16:02:23 -05:00
|
|
|
from vllm.platforms import current_platform
|
|
|
|
|
|
|
|
from ...utils import check_logprobs_close
|
2024-06-30 11:44:25 +08:00
|
|
|
|
2023-09-01 11:19:43 +09:00
|
|
|
MODELS = [
|
2024-11-05 16:02:23 -05:00
|
|
|
"facebook/opt-125m", # opt
|
|
|
|
"openai-community/gpt2", # gpt2
|
|
|
|
# "Milos/slovak-gpt-j-405M", # gptj
|
|
|
|
# "bigcode/tiny_starcoder_py", # gpt_bigcode
|
|
|
|
# "EleutherAI/pythia-70m", # gpt_neox
|
|
|
|
"bigscience/bloom-560m", # bloom - testing alibi slopes
|
|
|
|
"microsoft/phi-2", # phi
|
|
|
|
# "stabilityai/stablelm-3b-4e1t", # stablelm
|
|
|
|
# "bigcode/starcoder2-3b", # starcoder2
|
|
|
|
"google/gemma-1.1-2b-it", # gemma
|
|
|
|
"Qwen/Qwen2.5-0.5B-Instruct", # qwen2
|
|
|
|
"meta-llama/Llama-3.2-1B-Instruct", # llama
|
2023-09-01 11:19:43 +09:00
|
|
|
]
|
|
|
|
|
2024-11-05 16:02:23 -05:00
|
|
|
if not current_platform.is_cpu():
|
|
|
|
MODELS += [
|
|
|
|
# fused_moe which not supported on CPU
|
|
|
|
"openbmb/MiniCPM3-4B",
|
|
|
|
]
|
|
|
|
|
2024-11-07 12:43:08 +08:00
|
|
|
target_dtype = "half"
|
2024-11-05 16:02:23 -05:00
|
|
|
|
2023-09-01 11:19:43 +09:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("model", MODELS)
|
2024-11-05 16:02:23 -05:00
|
|
|
@pytest.mark.parametrize("dtype", [target_dtype])
|
|
|
|
@pytest.mark.parametrize("max_tokens", [32])
|
|
|
|
@pytest.mark.parametrize("num_logprobs", [5])
|
2023-09-01 11:19:43 +09:00
|
|
|
def test_models(
|
|
|
|
hf_runner,
|
|
|
|
vllm_runner,
|
|
|
|
example_prompts,
|
|
|
|
model: str,
|
|
|
|
dtype: str,
|
|
|
|
max_tokens: int,
|
2024-11-05 16:02:23 -05:00
|
|
|
num_logprobs: int,
|
2023-09-01 11:19:43 +09:00
|
|
|
) -> None:
|
2024-03-29 13:06:40 +09:00
|
|
|
|
2024-06-07 22:31:32 -07:00
|
|
|
with hf_runner(model, dtype=dtype) as hf_model:
|
2024-11-05 16:02:23 -05:00
|
|
|
hf_outputs = hf_model.generate_greedy_logprobs_limit(
|
|
|
|
example_prompts, max_tokens, num_logprobs)
|
2023-09-01 11:19:43 +09:00
|
|
|
|
2024-06-08 01:59:20 -07:00
|
|
|
with vllm_runner(model, dtype=dtype) as vllm_model:
|
2024-11-05 16:02:23 -05:00
|
|
|
vllm_outputs = vllm_model.generate_greedy_logprobs(
|
|
|
|
example_prompts, max_tokens, num_logprobs)
|
|
|
|
# This test is for verifying whether the model's extra_repr
|
|
|
|
# can be printed correctly.
|
|
|
|
print(vllm_model.model.llm_engine.model_executor.driver_worker.
|
|
|
|
model_runner.model)
|
2023-09-01 11:19:43 +09:00
|
|
|
|
2024-11-05 16:02:23 -05:00
|
|
|
check_logprobs_close(
|
2024-06-30 11:44:25 +08:00
|
|
|
outputs_0_lst=hf_outputs,
|
|
|
|
outputs_1_lst=vllm_outputs,
|
|
|
|
name_0="hf",
|
|
|
|
name_1="vllm",
|
|
|
|
)
|