-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_aviary.py
51 lines (41 loc) · 1.37 KB
/
test_aviary.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
import requests
import time
import argparse
import ray
TOTAL_RUN_TIME = 1 * 60. # Number of seconds to run
TARGET_QPS = 1
post_body = {
"data":[
"explain gravity to a first grade student",
"amazon/LightGPT",
"stabilityai/stablelm-tuned-alpha-7b",
"mosaicml/mpt-7b-chat",
None
],
"fn_index":9,
"session_hash":"2q30p62xajq"
}
@ray.remote
def scrape_task(host, data):
start = time.time()
resp = requests.post(host, json=post_body)
end = time.time()
if resp.status_code == 200:
return "Got result in {0} seconds, Result is: {1}".format(end - start,resp.json())
else:
return "Error fetching in {0} seconds, Status is {}, Result is: {}".format(end-start, resp.status_code, resp.text)
# print(f"Error fetching: [{resp.status_code}] {resp.text}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("host", nargs="?", default="https://aviary-staging.anyscale.com/run/predict")
args = parser.parse_args()
host = args.host
last_fired_at = 0
start_time = time.time()
results = []
while time.time() - start_time < TOTAL_RUN_TIME:
now = time.monotonic()
if now - last_fired_at > (1 / TARGET_QPS):
results.append(scrape_task.remote(host, post_body))
last_fired_at = now
print(ray.get(results))