test_regression.py 2.31 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
"""Containing tests that check for regressions in vLLM's behavior.

It should include tests that are reported by users and making sure they
will never happen again.

"""
9

10
11
import gc

12
import pytest
13
14
import torch

15
from tests.utils import large_gpu_mark
16
from vllm import LLM, SamplingParams
17
from vllm.platforms import current_platform
18
19


20
21
22
23
24
25
26
27
28
29
30
31
@pytest.mark.parametrize(
    "model",
    [
        pytest.param(
            "distilbert/distilgpt2",
            marks=[
                *([large_gpu_mark(min_gb=80)] if current_platform.is_rocm() else []),
            ],
        ),
    ],
)
def test_max_tokens_none(model):
32
33
    sampling_params = SamplingParams(temperature=0.01, top_p=0.1, max_tokens=None)
    llm = LLM(
34
        model=model,
35
36
37
        max_num_batched_tokens=4096,
        tensor_parallel_size=1,
    )
38
39
40
41
42
43
    prompts = ["Just say hello!"]
    outputs = llm.generate(prompts, sampling_params=sampling_params)

    assert len(prompts) == len(outputs)


44
def test_gc():
45
    llm = LLM(model="distilbert/distilgpt2", enforce_eager=True)
46
47
48
    del llm

    gc.collect()
49
    torch.accelerator.empty_cache()
50
51
52
53

    # The memory allocated for model and KV cache should be released.
    # The memory allocated for PyTorch and others should be less than 50MB.
    # Usually, it's around 10MB.
54
    allocated = torch.accelerator.memory_allocated()
55
56
57
    assert allocated < 50 * 1024 * 1024


58
def test_model_from_modelscope(monkeypatch: pytest.MonkeyPatch):
59
    # model: https://modelscope.cn/models/qwen/Qwen1.5-0.5B-Chat/summary
60
61
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_MODELSCOPE", "True")
62
63
64
        # Don't use HF_TOKEN for ModelScope repos, otherwise it will fail
        # with 400 Client Error: Bad Request.
        m.setenv("HF_TOKEN", "")
65
66
        attn_backend = "TRITON_ATTN" if current_platform.is_rocm() else "auto"
        llm = LLM(model="qwen/Qwen1.5-0.5B-Chat", attention_backend=attn_backend)
67
68
69
70
71
72
73
74
75
76
77

        prompts = [
            "Hello, my name is",
            "The president of the United States is",
            "The capital of France is",
            "The future of AI is",
        ]
        sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

        outputs = llm.generate(prompts, sampling_params)
        assert len(outputs) == 4