test_common.py 6.97 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

Woosuk Kwon's avatar
Woosuk Kwon committed
4
import pytest
5
import os
6
7
8
import torch

from vllm.platforms import current_platform
Woosuk Kwon's avatar
Woosuk Kwon committed
9

10
from ....utils import large_gpu_mark
11
from ...registry import HF_EXAMPLE_MODELS
12
from ...utils import check_logprobs_close
zhuwenwen's avatar
zhuwenwen committed
13
from ....utils import models_path_prefix
Woosuk Kwon's avatar
Woosuk Kwon committed
14

15
16
17
18
19
20
# This list contains the model that are using AITER kernel.
# Skip model that are not using AITER tests.
# When more AITER kernels are added, this list will not be
# needed as all the models will be calling AITER kernels
# in parts of the operators
AITER_MODEL_LIST = [
21
22
23
24
25
26
    os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),
    os.path.join(models_path_prefix, "openbmb/MiniCPM3-4B"),
    os.path.join(models_path_prefix, "Qwen/Qwen-7B-Chat"),
    os.path.join(models_path_prefix, "Qwen/Qwen2.5-0.5B-Instruct"),
    os.path.join(models_path_prefix, "TitanML/tiny-mixtral"),
    os.path.join(models_path_prefix, "Qwen/Qwen3-8B"),
27
]
Woosuk Kwon's avatar
Woosuk Kwon committed
28
29


30
# @maybe_test_rocm_aiter
31
32
33
34
@pytest.mark.parametrize(
    "model",
    [
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
35
            os.path.join(models_path_prefix, "bigscience/bloom-560m"),  # bloom - testing alibi slopes
36
37
38
39
40
            marks=[
                pytest.mark.core_model,
                pytest.mark.slow_test,
                pytest.mark.cpu_model,
            ],
41
42
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
43
            os.path.join(models_path_prefix, "openai-community/gpt2"),  # gpt2
44
45
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
zhuwenwen's avatar
zhuwenwen committed
46
47
48
        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
49
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
50
            os.path.join(models_path_prefix, "google/gemma-1.1-2b-it"),  # gemma
51
            marks=[
52
53
54
                pytest.mark.core_model,
                pytest.mark.cpu_model,
                pytest.mark.slow_test,
55
            ],
56
        ),
57
        pytest.param(
58
            os.path.join(models_path_prefix, "google/gemma-2-2b-it"),  # test hybrid attention
59
60
            marks=[pytest.mark.cpu_model],
        ),
61
        pytest.param(
62
            os.path.join(models_path_prefix, "zai-org/chatglm3-6b"),  # chatglm (text-only)
63
        ),
64
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
65
            os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),  # llama
66
67
68
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
69
            os.path.join(models_path_prefix, "openbmb/MiniCPM3-4B"),
70
            marks=[pytest.mark.core_model, large_gpu_mark(min_gb=32)],
71
72
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
73
            os.path.join(models_path_prefix, "facebook/opt-125m"),  # opt
74
75
76
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
        ),
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
77
            os.path.join(models_path_prefix, "microsoft/phi-2"),  # phi
78
            marks=[pytest.mark.core_model, pytest.mark.slow_test],
79
        ),
80
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
81
            os.path.join(models_path_prefix, "Qwen/Qwen-7B-Chat"),  # qwen (text-only)
82
        ),
83
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
84
            os.path.join(models_path_prefix, "Qwen/Qwen2.5-0.5B-Instruct"),  # qwen2
85
            marks=[
86
87
88
                pytest.mark.core_model,
                pytest.mark.cpu_model,
                pytest.mark.slow_test,
89
            ],
90
        ),
91
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
92
            os.path.join(models_path_prefix, "Qwen/Qwen3-8B"),  # qwen (text-only)
93
        ),
zhuwenwen's avatar
zhuwenwen committed
94
95
        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
96
        pytest.param(
zhuwenwen's avatar
zhuwenwen committed
97
            os.path.join(models_path_prefix, "TitanML/tiny-mixtral"),  # mixtral
98
            marks=[pytest.mark.core_model, pytest.mark.cpu_model],
99
        ),
100
        pytest.param("swiss-ai/Apertus-8B-Instruct-2509"),  # apertus
101
102
    ],
)
103
104
@pytest.mark.parametrize("max_tokens", [32])
@pytest.mark.parametrize("num_logprobs", [5])
105
@pytest.mark.parametrize(
106
107
    "use_rocm_aiter", [True, False] if current_platform.is_rocm() else [False]
)
108
@pytest.mark.parametrize("use_prompt_embeds", [True, False])
109
110
111
112
113
114
115
116
117
118
119
def test_models(
    hf_runner,
    vllm_runner,
    example_prompts,
    model: str,
    max_tokens: int,
    num_logprobs: int,
    use_rocm_aiter: bool,
    use_prompt_embeds: bool,
    monkeypatch,
) -> None:
120
121
122
    model_info = HF_EXAMPLE_MODELS.find_hf_info(model)
    model_info.check_available_online(on_fail="skip")
    model_info.check_transformers_version(on_fail="skip")
123
124
125
126
127
128
129
130
131

    if use_rocm_aiter and (model in AITER_MODEL_LIST):
        monkeypatch.setenv("VLLM_ROCM_USE_AITER", "1")
    elif use_rocm_aiter and model not in AITER_MODEL_LIST:
        # Skip model that are not using AITER tests.
        # When more AITER kernels are added, this list will not be
        # needed as all the models will be calling AITER kernels
        # in parts of the operators
        pytest.skip(f"Skipping '{model}' model test with AITER kernel.")
132

133
    with hf_runner(model) as hf_model:
134
        hf_outputs = hf_model.generate_greedy_logprobs_limit(
135
136
            example_prompts, max_tokens, num_logprobs
        )
Woosuk Kwon's avatar
Woosuk Kwon committed
137

138
        prompt_embeds: list[torch.Tensor] | None = [] if use_prompt_embeds else None
139

140
141
        prompt_token_ids = []
        for prompt in example_prompts:
142
143
144
            token_ids = hf_model.tokenizer(prompt, return_tensors="pt").input_ids.to(
                hf_model.model.device
            )
145
146
            prompt_token_ids.append(token_ids)
            if prompt_embeds is not None:
147
148
149
                prompt_embeds.append(
                    hf_model.model.get_input_embeddings()(token_ids).squeeze(0)
                )
150

151
    with vllm_runner(
152
153
154
155
156
157
        model,
        tokenizer_name=model_info.tokenizer or model,
        tokenizer_mode=model_info.tokenizer_mode,
        trust_remote_code=model_info.trust_remote_code,
        max_num_seqs=2,
        enable_prompt_embeds=use_prompt_embeds,
158
    ) as vllm_model:
159
        vllm_outputs = vllm_model.generate_greedy_logprobs(
160
161
            example_prompts, max_tokens, num_logprobs
        )
162
163
        if prompt_embeds is not None:
            vllm_outputs_from_embeds = vllm_model.generate_greedy_logprobs(
164
165
                prompt_embeds, max_tokens, num_logprobs
            )
166

167
    check_logprobs_close(
168
169
170
171
172
        outputs_0_lst=hf_outputs,
        outputs_1_lst=vllm_outputs,
        name_0="hf",
        name_1="vllm",
    )
173
174
175
176
177
178
179
180
    if prompt_embeds is not None:
        check_logprobs_close(
            outputs_0_lst=vllm_outputs,
            outputs_1_lst=vllm_outputs_from_embeds,
            name_0="vllm",
            name_1="vllm_from_embeds",
        )

181
182
183
184
185
186
187
    if use_rocm_aiter:
        # this is to ensure that vllm engine
        # has deallocated the memory before running the next
        # unit tests. On ROCm, when using AITER
        # the memory might not be deallocated completely
        # before running the next test case
        torch.cuda.synchronize()