test_regression.py 3.22 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
import os
10
11
import gc

12
import pytest
13
14
import torch

15
16
from vllm import LLM, SamplingParams

17
from .utils import models_path_prefix
zhuwenwen's avatar
zhuwenwen committed
18
from vllm.platforms import current_platform
19
20


21
@pytest.mark.skip(reason="In V1, we reject tokens > max_seq_len")
22
23
24
25
26
27
def test_duplicated_ignored_sequence_group():
    """https://github.com/vllm-project/vllm/issues/1655"""

    sampling_params = SamplingParams(temperature=0.01,
                                     top_p=0.1,
                                     max_tokens=256)
28
    llm = LLM(model=os.path.join(models_path_prefix, "distilbert/distilgpt2"),
29
30
31
32
33
34
35
36
              max_num_batched_tokens=4096,
              tensor_parallel_size=1)
    prompts = ["This is a short prompt", "This is a very long prompt " * 1000]
    outputs = llm.generate(prompts, sampling_params=sampling_params)

    assert len(prompts) == len(outputs)


37
38
39
40
def test_max_tokens_none():
    sampling_params = SamplingParams(temperature=0.01,
                                     top_p=0.1,
                                     max_tokens=None)
zhuwenwen's avatar
zhuwenwen committed
41
    if not current_platform.is_rocm():
42
43
        llm = LLM(model=os.path.join(models_path_prefix, "distilbert/distilgpt2"),
                max_num_batched_tokens=4096,
zhuwenwen's avatar
zhuwenwen committed
44
                tensor_parallel_size=1)
45
46
47
    else:
        llm = LLM(model=os.path.join(models_path_prefix, "distilbert/distilgpt2"),
                max_num_batched_tokens=4096,
zhuwenwen's avatar
zhuwenwen committed
48
49
50
                tensor_parallel_size=1,
                block_size=64)
        
51
52
53
54
55
56
    prompts = ["Just say hello!"]
    outputs = llm.generate(prompts, sampling_params=sampling_params)

    assert len(prompts) == len(outputs)


57
def test_gc():
58
    llm = LLM(model=os.path.join(models_path_prefix, "distilbert/distilgpt2"), enforce_eager=True)
59
60
61
62
63
64
65
66
67
68
69
70
    del llm

    gc.collect()
    torch.cuda.empty_cache()

    # 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.
    allocated = torch.cuda.memory_allocated()
    assert allocated < 50 * 1024 * 1024


71
def test_model_from_modelscope(monkeypatch: pytest.MonkeyPatch):
72
    # model: https://modelscope.cn/models/qwen/Qwen1.5-0.5B-Chat/summary
73
74
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_MODELSCOPE", "True")
75
76
77
        # Don't use HF_TOKEN for ModelScope repos, otherwise it will fail
        # with 400 Client Error: Bad Request.
        m.setenv("HF_TOKEN", "")
zhuwenwen's avatar
zhuwenwen committed
78
        if not current_platform.is_rocm():
79
            llm = LLM(model=os.path.join(models_path_prefix, "qwen/Qwen1.5-0.5B-Chat"))
zhuwenwen's avatar
zhuwenwen committed
80
81
        else:
            llm = LLM(model=os.path.join(models_path_prefix, "qwen/Qwen1.5-0.5B-Chat"), block_size=64)
82
83
84
85
86
87
88
89
90
91

        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)
92
        assert len(outputs) == 4