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

3
4
5
6
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`.
Woosuk Kwon's avatar
Woosuk Kwon committed
7
8
9
"""
import pytest

10
from ...utils import check_outputs_equal
11

Woosuk Kwon's avatar
Woosuk Kwon committed
12
MODELS = [
Isotr0py's avatar
Isotr0py committed
13
14
15
16
    "facebook/opt-125m",
    "gpt2",
    "bigcode/tiny_starcoder_py",
    "EleutherAI/pythia-70m",
17
    "bigscience/bloom-560m",  # Testing alibi slopes.
Isotr0py's avatar
Isotr0py committed
18
19
    "microsoft/phi-2",
    "stabilityai/stablelm-3b-4e1t",
20
    # "allenai/OLMo-1B",  # Broken
21
    "bigcode/starcoder2-3b",
22
    "google/gemma-1.1-2b-it",
Woosuk Kwon's avatar
Woosuk Kwon committed
23
24
25
26
]


@pytest.mark.parametrize("model", MODELS)
27
28
@pytest.mark.parametrize("dtype", ["float"])
@pytest.mark.parametrize("max_tokens", [96])
Woosuk Kwon's avatar
Woosuk Kwon committed
29
30
31
32
33
34
35
36
def test_models(
    hf_runner,
    vllm_runner,
    example_prompts,
    model: str,
    dtype: str,
    max_tokens: int,
) -> None:
37
38
39
    # To pass the small model tests, we need full precision.
    assert dtype == "float"

40
41
    with hf_runner(model, dtype=dtype) as hf_model:
        hf_outputs = hf_model.generate_greedy(example_prompts, max_tokens)
Woosuk Kwon's avatar
Woosuk Kwon committed
42

43
44
    with vllm_runner(model, dtype=dtype) as vllm_model:
        vllm_outputs = vllm_model.generate_greedy(example_prompts, max_tokens)
Woosuk Kwon's avatar
Woosuk Kwon committed
45

46
47
48
49
50
51
    check_outputs_equal(
        outputs_0_lst=hf_outputs,
        outputs_1_lst=vllm_outputs,
        name_0="hf",
        name_1="vllm",
    )
52
53
54
55
56
57
58
59
60


@pytest.mark.parametrize("model", MODELS)
@pytest.mark.parametrize("dtype", ["float"])
def test_model_print(
    vllm_runner,
    model: str,
    dtype: str,
) -> None:
61
62
63
64
65
    with vllm_runner(model, dtype=dtype) as vllm_model:
        # 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)