Repository navigation
Expand file tree
/
Copy pathbench.py
More file actions
70 lines (54 loc) · 2.14 KB
/
Copy pathbench.py
File metadata and controls
70 lines (54 loc) · 2.14 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys, time
import pandas as pd
from vllm import SamplingParams, LLM
#from https://modal.com/docs/guide/ex/vllm_inference
questions = [
# Coding questions
"Implement a Python function to compute the Fibonacci numbers.",
"Write a Rust function that performs binary exponentiation.",
"What are the differences between Javascript and Python?",
# Literature
"Write a story in the style of James Joyce about a trip to the Australian outback in 2083, to see robots in the beautiful desert.",
"Who does Harry turn into a balloon?",
"Write a tale about a time-traveling historian who's determined to witness the most significant events in human history.",
# Math
"What is the product of 9 and 8?",
"If a train travels 120 kilometers in 2 hours, what is its average speed?",
"Think through this step by step. If the sequence a_n is defined by a_1 = 3, a_2 = 5, and a_n = a_(n-1) + a_(n-2) for n > 2, find a_6.",
]
MODEL_DIR = "/home/ubuntu/hamel-drive/vllm-models"
def download_model_to_folder():
from huggingface_hub import snapshot_download
import os
snapshot_download(
"meta-llama/Llama-2-7b-hf",
local_dir=MODEL_DIR,
token=os.environ["HUGGING_FACE_HUB_TOKEN"],
)
return LLM(MODEL_DIR)
def generate(question, llm, note=None):
response = {'question': question, 'note': note}
sampling_params = SamplingParams(
temperature=1.0,
top_p=1,
max_tokens=200,
)
start = time.perf_counter()
result = llm.generate(question, sampling_params)
request_time = time.perf_counter() - start
for output in result:
response['tok_count'] = len(output.outputs[0].token_ids)
response['time'] = request_time
response['answer'] = output.outputs[0].text
return response
if __name__ == '__main__':
llm = download_model_to_folder()
counter = 1
responses = []
for q in questions:
response = generate(question=q, llm=llm, note='vLLM')
if counter >= 2:
responses.append(response)
counter += 1
df = pd.DataFrame(responses)
df.to_csv('bench-vllm.csv', index=False)