main
py 51 lines 1.47 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 from vllm import LLM, SamplingParams
5 from vllm.config import KVTransferConfig
6
7
8 def read_prompts():
9 """Read prompts from output.txt."""
10 prompts = []
11 try:
12 with open("output.txt") as f:
13 for line in f:
14 prompts.append(line.strip())
15 print(f"Loaded {len(prompts)} prompts from output.txt")
16 return prompts
17 except FileNotFoundError:
18 print("Error: output.txt file not found")
19 exit(-1)
20
21
22 def main():
23 prompts = read_prompts()
24 sampling_params = SamplingParams(temperature=0, top_p=0.95, max_tokens=10)
25
26 llm = LLM(
27 model="meta-llama/Llama-3.2-1B-Instruct",
28 enforce_eager=True,
29 gpu_memory_utilization=0.8,
30 max_num_batched_tokens=64,
31 max_num_seqs=16,
32 kv_transfer_config=KVTransferConfig(
33 kv_connector="ExampleConnector",
34 kv_role="kv_both",
35 kv_connector_extra_config={"shared_storage_path": "local_storage"},
36 ),
37 ) # , max_model_len=2048, max_num_batched_tokens=2048)
38
39 # 1ST generation (prefill instance)
40 outputs = llm.generate(prompts, sampling_params)
41
42 print("-" * 30)
43 for output in outputs:
44 prompt = output.prompt
45 generated_text = output.outputs[0].text
46 print(f"Prompt: {prompt!r}\nGenerated text: {generated_text!r}")
47 print("-" * 30)
48
49
50 if __name__ == "__main__":
51 main()