-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_detect_num_list.py
executable file
·58 lines (47 loc) · 1.46 KB
/
generate_detect_num_list.py
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
#!/usr/bin/env python
"""
Generate LLM queries to see if number is in list.
Purpose is to benchmark if overlapping strings improve
speed, for instance by better using KV cache in VLLM.
Use set of JSON files instead of list so easier to run
in parallel with GNU parallel.
"""
import json
import fire
import numpy as np
def generate_detect_num_list(
out_file_prefix: str,
num_gen: int,
make_same: int,
):
"""
Main function that runs the program.
Due to how fire package works, make make_same int instead of bool.
"""
check_list = None
rgen = np.random.default_rng()
for i in range(num_gen):
if (make_same == 0) or (i == 0):
check_list = rgen.integers(0, 1000, size=100)
check_list_str = ", ".join([str(x) for x in check_list])
rnum = int(rgen.integers(0, 1000))
r = [
{
"role": "system",
"content": "Determine if the specified number is in the list.",
},
{
"role": "User",
"content": f"The list is: {check_list_str}.",
},
{
"role": "User",
"content": f"The number is: {rnum}.",
},
]
out_file = f"{out_file_prefix}_{i:03}.json"
print("Save file:", out_file)
with open(out_file, "w", encoding="UTF8") as f:
json.dump(r, f)
if __name__ == "__main__":
fire.Fire(generate_detect_num_list)