test_models.py 3.3 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
Woosuk Kwon's avatar
Woosuk Kwon committed
2
3
"""Compare the outputs of HF and vLLM when using greedy sampling.

4
Run `pytest tests/models/test_models.py`.
Woosuk Kwon's avatar
Woosuk Kwon committed
5
6
"""
import pytest
7
import os
Woosuk Kwon's avatar
Woosuk Kwon committed
8

9
from ...utils import check_logprobs_close
zhuwenwen's avatar
zhuwenwen committed
10
from ....utils import models_path_prefix
Woosuk Kwon's avatar
Woosuk Kwon committed
11
12


13
14
15
16
@pytest.mark.parametrize(
    "model",
    [
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
17
            os.path.join(models_path_prefix, "bigscience/bloom-560m"),  # bloom - testing alibi slopes
18
19
20
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
21
            os.path.join(models_path_prefix, "openai-community/gpt2"),  # gpt2
22
23
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
24
25
26
        pytest.param(os.path.join(models_path_prefix, "Milos/slovak-gpt-j-405M")),  # gptj
        pytest.param(os.path.join(models_path_prefix, "bigcode/tiny_starcoder_py")),  # gpt_bigcode
        pytest.param(os.path.join(models_path_prefix, "EleutherAI/pythia-70m")),  # gpt_neox
27
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
28
            os.path.join(models_path_prefix, "google/gemma-1.1-2b-it"),  # gemma
29
30
31
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
32
            os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),  # llama
33
34
35
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
36
            os.path.join(models_path_prefix, "openbmb/MiniCPM3-4B"),
37
38
39
40
            # fused_moe not supported on CPU
            marks=[pytest.mark.core_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
41
            os.path.join(models_path_prefix, "facebook/opt-125m"),  # opt
42
43
44
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
45
            os.path.join(models_path_prefix, "microsoft/phi-2"),  # phi
46
47
48
            marks=[pytest.mark.core_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
49
            os.path.join(models_path_prefix, "Qwen/Qwen2.5-0.5B-Instruct"),  # qwen2
50
51
            marks=[pytest.mark.core_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
52
53
        pytest.param(os.path.join(models_path_prefix, "stabilityai/stablelm-3b-4e1t")),  # stablelm
        pytest.param(os.path.join(models_path_prefix, "bigcode/starcoder2-3b")),  # starcoder2
54
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
55
            os.path.join(models_path_prefix, "ehristoforu/Falcon3-MoE-2x7B-Insruct"),  # mixtral
56
57
            marks=[pytest.mark.cpu_model],
        )
58
59
    ])
@pytest.mark.parametrize("dtype", ["half"])
60
61
@pytest.mark.parametrize("max_tokens", [32])
@pytest.mark.parametrize("num_logprobs", [5])
Woosuk Kwon's avatar
Woosuk Kwon committed
62
63
64
65
66
67
68
def test_models(
    hf_runner,
    vllm_runner,
    example_prompts,
    model: str,
    dtype: str,
    max_tokens: int,
69
    num_logprobs: int,
Woosuk Kwon's avatar
Woosuk Kwon committed
70
) -> None:
71

72
    with hf_runner(model, dtype=dtype) as hf_model:
73
74
        hf_outputs = hf_model.generate_greedy_logprobs_limit(
            example_prompts, max_tokens, num_logprobs)
Woosuk Kwon's avatar
Woosuk Kwon committed
75

76
    with vllm_runner(model, dtype=dtype) as vllm_model:
77
78
        vllm_outputs = vllm_model.generate_greedy_logprobs(
            example_prompts, max_tokens, num_logprobs)
79

80
81
        # This test is for verifying whether the model's extra_repr
        # can be printed correctly.
82
83
84
85
        def print_model(model):
            print(model)

        vllm_model.apply_model(print_model)
Woosuk Kwon's avatar
Woosuk Kwon committed
86

87
    check_logprobs_close(
88
89
90
91
92
        outputs_0_lst=hf_outputs,
        outputs_1_lst=vllm_outputs,
        name_0="hf",
        name_1="vllm",
    )