test_models.py 3.7 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
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
31
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
32
            os.path.join(models_path_prefix, "THUDM/chatglm3-6b"),  # chatglm (text-only)
33
        ),
34
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
35
            os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),  # llama
36
37
38
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
39
            os.path.join(models_path_prefix, "openbmb/MiniCPM3-4B"),
40
41
42
43
            # fused_moe not supported on CPU
            marks=[pytest.mark.core_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
44
            os.path.join(models_path_prefix, "facebook/opt-125m"),  # opt
45
46
47
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
48
            os.path.join(models_path_prefix, "microsoft/phi-2"),  # phi
49
50
            marks=[pytest.mark.core_model],
        ),
51
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
52
            os.path.join(models_path_prefix, "Qwen/Qwen-7B"),  # qwen (text-only)
53
        ),
54
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
55
            os.path.join(models_path_prefix, "Qwen/Qwen2.5-0.5B-Instruct"),  # qwen2
56
57
            marks=[pytest.mark.core_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
58
59
        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
60
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
61
            os.path.join(models_path_prefix, "ehristoforu/Falcon3-MoE-2x7B-Insruct"),  # mixtral
62
63
            marks=[pytest.mark.cpu_model],
        )
64
65
    ])
@pytest.mark.parametrize("dtype", ["half"])
66
67
@pytest.mark.parametrize("max_tokens", [32])
@pytest.mark.parametrize("num_logprobs", [5])
Woosuk Kwon's avatar
Woosuk Kwon committed
68
69
70
71
72
73
74
def test_models(
    hf_runner,
    vllm_runner,
    example_prompts,
    model: str,
    dtype: str,
    max_tokens: int,
75
    num_logprobs: int,
Woosuk Kwon's avatar
Woosuk Kwon committed
76
) -> None:
77

78
    with hf_runner(model, dtype=dtype) as hf_model:
79
80
81
82
        if model.startswith("THUDM/chatglm3"):
            hf_model.model.get_output_embeddings = lambda: \
                hf_model.model.transformer.output_layer

83
84
        hf_outputs = hf_model.generate_greedy_logprobs_limit(
            example_prompts, max_tokens, num_logprobs)
Woosuk Kwon's avatar
Woosuk Kwon committed
85

86
    with vllm_runner(model, dtype=dtype) as vllm_model:
87
88
        vllm_outputs = vllm_model.generate_greedy_logprobs(
            example_prompts, max_tokens, num_logprobs)
89

90
91
        # This test is for verifying whether the model's extra_repr
        # can be printed correctly.
92
93
94
95
        def print_model(model):
            print(model)

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

97
    check_logprobs_close(
98
99
100
101
102
        outputs_0_lst=hf_outputs,
        outputs_1_lst=vllm_outputs,
        name_0="hf",
        name_1="vllm",
    )