"tests/vscode:/vscode.git/clone" did not exist on "dbeac95dbbf898bcc0965528fc767e9cadbbe0c5"
test_gpu_utilization.py 940 Bytes
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

zhuwenwen's avatar
zhuwenwen committed
3
import os
4
from vllm import LLM, SamplingParams
zhuwenwen's avatar
zhuwenwen committed
5
from ...utils import models_path_prefix
6
7
8
9
10
11
12
13
14
15
16
17
18
19


def test_gpu_memory_utilization():
    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)

    # makes sure gpu_memory_utilization is per-instance limit,
    # not a global limit
    llms = [
zhuwenwen's avatar
zhuwenwen committed
20
        LLM(model=os.path.join(models_path_prefix, "facebook/opt-125m"),
21
22
23
24
25
26
27
28
29
            gpu_memory_utilization=0.3,
            enforce_eager=True) for i in range(3)
    ]
    for llm in llms:
        outputs = llm.generate(prompts, sampling_params)
        for output in outputs:
            prompt = output.prompt
            generated_text = output.outputs[0].text
            print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")