"vllm/vscode:/vscode.git/clone" did not exist on "56dcf4e7e965e34043acf20ca4e4aceda21d41ec"
test_regression.py 2.74 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
3
4
5
6
7
"""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.

"""
8
9
10
11
import gc

import torch

12
from vllm import LLM, SamplingParams
13
14
15
from vllm.config import LoadFormat

from .conftest import MODEL_WEIGHTS_S3_BUCKET
16
17
18
19
20
21
22
23


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)
24
25
    llm = LLM(model=f"{MODEL_WEIGHTS_S3_BUCKET}/distilgpt2",
              load_format=LoadFormat.RUNAI_STREAMER,
26
27
28
29
30
31
32
33
              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)


34
35
36
37
def test_max_tokens_none():
    sampling_params = SamplingParams(temperature=0.01,
                                     top_p=0.1,
                                     max_tokens=None)
38
39
    llm = LLM(model=f"{MODEL_WEIGHTS_S3_BUCKET}/distilgpt2",
              load_format=LoadFormat.RUNAI_STREAMER,
40
41
42
43
44
45
46
47
              max_num_batched_tokens=4096,
              tensor_parallel_size=1)
    prompts = ["Just say hello!"]
    outputs = llm.generate(prompts, sampling_params=sampling_params)

    assert len(prompts) == len(outputs)


48
def test_gc():
49
50
51
    llm = LLM(model=f"{MODEL_WEIGHTS_S3_BUCKET}/distilgpt2",
              load_format=LoadFormat.RUNAI_STREAMER,
              enforce_eager=True)
52
53
54
55
56
57
58
59
60
61
62
63
    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


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def test_model_from_modelscope(monkeypatch):
    # model: https://modelscope.cn/models/qwen/Qwen1.5-0.5B-Chat/summary
    MODELSCOPE_MODEL_NAME = "qwen/Qwen1.5-0.5B-Chat"
    monkeypatch.setenv("VLLM_USE_MODELSCOPE", "True")
    try:
        llm = LLM(model=MODELSCOPE_MODEL_NAME)

        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
    finally:
        monkeypatch.delenv("VLLM_USE_MODELSCOPE", raising=False)


85
86
87
if __name__ == "__main__":
    import pytest
    pytest.main([__file__])