test_models.py 3.1 KB
Newer Older
Woosuk Kwon's avatar
Woosuk Kwon committed
1
2
"""Compare the outputs of HF and vLLM when using greedy sampling.

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

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


12
13
14
15
@pytest.mark.parametrize(
    "model",
    [
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
16
            os.path.join(models_path_prefix, "bigscience/bloom-560m"),  # bloom - testing alibi slopes
17
18
19
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
20
            os.path.join(models_path_prefix, "openai-community/gpt2"),  # gpt2
21
22
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
23
24
25
        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
26
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
27
            os.path.join(models_path_prefix, "google/gemma-1.1-2b-it"),  # gemma
28
29
30
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
31
            os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),  # llama
32
33
34
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
35
            os.path.join(models_path_prefix, "openbmb/MiniCPM3-4B"),
36
37
38
39
            # fused_moe not supported on CPU
            marks=[pytest.mark.core_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
40
            os.path.join(models_path_prefix, "facebook/opt-125m"),  # opt
41
42
43
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
44
            os.path.join(models_path_prefix, "microsoft/phi-2"),  # phi
45
46
47
            marks=[pytest.mark.core_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
48
            os.path.join(models_path_prefix, "Qwen/Qwen2.5-0.5B-Instruct"),  # qwen2
49
50
            marks=[pytest.mark.core_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
51
52
        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
53
54
    ])
@pytest.mark.parametrize("dtype", ["half"])
55
56
@pytest.mark.parametrize("max_tokens", [32])
@pytest.mark.parametrize("num_logprobs", [5])
Woosuk Kwon's avatar
Woosuk Kwon committed
57
58
59
60
61
62
63
def test_models(
    hf_runner,
    vllm_runner,
    example_prompts,
    model: str,
    dtype: str,
    max_tokens: int,
64
    num_logprobs: int,
Woosuk Kwon's avatar
Woosuk Kwon committed
65
) -> None:
66

67
    with hf_runner(model, dtype=dtype) as hf_model:
68
69
        hf_outputs = hf_model.generate_greedy_logprobs_limit(
            example_prompts, max_tokens, num_logprobs)
Woosuk Kwon's avatar
Woosuk Kwon committed
70

71
    with vllm_runner(model, dtype=dtype) as vllm_model:
72
73
74
75
76
77
        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)
Woosuk Kwon's avatar
Woosuk Kwon committed
78

79
    check_logprobs_close(
80
81
82
83
84
        outputs_0_lst=hf_outputs,
        outputs_1_lst=vllm_outputs,
        name_0="hf",
        name_1="vllm",
    )