basic.py 1.16 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
from vllm import LLM, SamplingParams
5

6
7
8
9
10
11
# Sample prompts.
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
zhuwenwen's avatar
zhuwenwen committed
12
    "Hello, my name is",
13
14
]
# Create a sampling params object.
zhuwenwen's avatar
zhuwenwen committed
15
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=16)
16

17
18

def main():
zhuwenwen's avatar
zhuwenwen committed
19
    # Create an LLM.
zhuwenwen's avatar
zhuwenwen committed
20
    llm = LLM(model="facebook/opt-125m",tensor_parallel_size=1, dtype="float16",trust_remote_code=True, enforce_eager=True, block_size=16, enable_prefix_caching=False)
21
22
    # Generate texts from the prompts.
    # The output is a list of RequestOutput objects
zhuwenwen's avatar
zhuwenwen committed
23
24
25
26
27
28
29
30
31
32
    # that contain the prompt, generated text, and other information.
    outputs = llm.generate(prompts, sampling_params)
    # Print the outputs.
    print("\nGenerated Outputs:\n" + "-" * 60)
    for output in outputs:
        prompt = output.prompt
        generated_text = output.outputs[0].text
        print(f"Prompt:    {prompt!r}")
        print(f"Output:    {generated_text!r}")
        print("-" * 60)
33
34
35
36


if __name__ == "__main__":
    main()
zhuwenwen's avatar
zhuwenwen committed
37