vllm_test.py 534 Bytes
Newer Older
Rayyyyy's avatar
Rayyyyy committed
1
from vllm import LLM, SamplingParams
chenych's avatar
chenych committed
2
import os
Rayyyyy's avatar
Rayyyyy committed
3

chenych's avatar
chenych committed
4
os.environ["CUDA_VISIBLE_DEVICES"] = '7'
Rayyyyy's avatar
Rayyyyy committed
5

chenych's avatar
chenych committed
6
7
prompt = ''
model_path = ''
Rayyyyy's avatar
Rayyyyy committed
8

chenych's avatar
chenych committed
9
10
11
12
13
sampling_params = SamplingParams(temperature=1, top_p=0.95)
llm = LLM(model=model_path,
               trust_remote_code=True,
               enforce_eager=True,
               tensor_parallel_size=1)
Rayyyyy's avatar
Rayyyyy committed
14

chenych's avatar
chenych committed
15
16
17
18
outputs = llm.generate(prompt, sampling_params)
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
Rayyyyy's avatar
Rayyyyy committed
19
20
21
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")