forked from LAIR-RCC/ruadapt
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_pipeline_app.py
More file actions
157 lines (143 loc) · 3.92 KB
/
run_pipeline_app.py
File metadata and controls
157 lines (143 loc) · 3.92 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from fastapi import FastAPI
import uvicorn
from anyio.lowlevel import RunVar
from anyio import CapacityLimiter
from fastapi import Request
import threading
import time
import subprocess
import json
import codecs
from fastapi import FastAPI, HTTPException, Request, Response, Query, Depends
from pydantic import BaseModel, Field
import os
app = FastAPI()
class Params(BaseModel):
ruadapt_base_model_name_or_path: str = Field(
Query(
min_length=0, max_length=5000
)
)
raw_base_model_name_or_path: str = Field(
Query(
min_length=0, max_length=5000,
default=''
)
)
instruct_model_name_or_path: str = Field(
Query(
min_length=0, max_length=5000,
default=''
)
)
custom_chat_template_path: str | None = Field(
Query(
min_length=0, max_length=5000,
default=None
)
)
output_dir: str = Field(
Query(
min_length=1, max_length=5000
)
)
pipeline_config_path: str = Field(
Query(
min_length=1, max_length=5000
)
)
alpaca_eval_questions_path: str = Field(
Query(
min_length=1, max_length=5000
)
)
custom_bos_token: str | None = Field(
Query(
min_length=0, max_length=100,
default=None
)
)
custom_eos_token: str | None = Field(
Query(
min_length=0, max_length=100,
default=None
)
)
custom_pad_token: str | None = Field(
Query(
min_length=0, max_length=100,
default=None
)
)
skip_lep: bool = Field(
Query(
default=False
)
)
eval: bool = Field(
Query(
default=True
)
)
sample_rate: float = Field(
Query(
ge=0.0, le=1.0,
default=1.0
)
)
alpha_scale: float = Field(
Query(
ge=0.0, le=10.0,
default=1.0
)
)
not_scale_lm_head: bool = Field(
Query(
default=False
)
)
q = []
@app.on_event("startup")
def startup():
print("start")
RunVar("_default_thread_limiter").set(CapacityLimiter(1))
@app.get('/get')
def get():
return q
@app.get('/add')
def add(query: Params = Depends()):
q.append(query)
devices = ['cuda1', 'cuda2', 'cuda3', 'cuda4']
def check_available_devices():
res = subprocess.check_output(['docker', 'ps']).decode('utf-8')
res = [r.split()[-1] for r in res.split('\n') if len(r.strip()) > 0]
available_devices = [d for d in devices if d not in res]
return available_devices
def query2params(query):
params = {k: v.strip() if type(v) == str else v for k, v in query.dict().items()}
return params
def start_pipeline(params, device):
print('Start experiment with:')
print(params)
print(f'on device {device}')
with codecs.open('tmp_config.json', 'w', 'utf-8') as file:
json.dump(params, file, ensure_ascii=False, indent=4)
call = 'python run_pipeline_config.py --config_path tmp_config.json'
wandb_api_key = os.environ['WANDB_API_KEY']
print(wandb_api_key)
full_call = f'docker run -v /home/maindev:/workdir -it --gpus \'\"device={device[-1]}\"\' --rm -d --name {device} ngc_cuda_pytorch_vllm_11_10_24_v7 bash -c \"cd projects/ruadapt && WANDB_API_KEY={wandb_api_key} {call}\"'
print(full_call)
print(subprocess.call(
full_call, shell=True
))
def loop():
while True:
time.sleep(10)
available_devices = check_available_devices()
if len(available_devices) > 0 and len(q) > 0:
query = q.pop(0)
params = query2params(query)
threading.Thread(target=start_pipeline, args=[params, available_devices[0]]).start()
t = threading.Thread(target=loop)
t.start()
uvicorn.run(app, host='0.0.0.0', port=8108, workers=1)