-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
48 lines (42 loc) · 1.06 KB
/
example.py
File metadata and controls
48 lines (42 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from TD_Pipe import LLM, SamplingParams
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--model",
type=str,
default="facebook/opt-125m",
)
parser.add_argument(
"--pipeline-parallel-size",
"-pp",
type=int,
default=1,
)
parser.add_argument(
"--profiler-path",
type=str,
required=True,
)
args = parser.parse_args()
# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
# Create an LLM with specified configurations.
llm = LLM(
model=args.model,
pipeline_parallel_size=args.pipeline_parallel_size,
profiler_path=args.profiler_path,
)
# Generate texts from the prompts.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")