Repository navigation
Expand file tree
/
Copy pathgenerate_script_alfworld.py
More file actions
158 lines (154 loc) · 6.35 KB
/
Copy pathgenerate_script_alfworld.py
File metadata and controls
158 lines (154 loc) · 6.35 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
157
158
import subprocess
import requests
import time, os
def main():
ckpt_paths = [
'cheesewafer/Llama3-8B-Instruct-sft-alfworld'
]
sft_model_name = 'llama3-8b-sft'
# sft_model_name = 'llama3-8b-0shot'
# sft_model_name = 'llama3-8b-2shot'
devices = len(ckpt_paths) # 2
port = 8001
base_device = 1
ports = [port+i for i in range(devices)]
# launch
override = True
if override:
for j in range(devices):
# sft_model_name = ''.join(ckpt_paths[j].split("/")[7:]) #.replace("/", "_")
print(f"launch {j+base_device}, {sft_model_name}")
process = subprocess.Popen(
f"""
source ~/.bashrc && \
conda activate vllm-0.5.5 && \
CUDA_VISIBLE_DEVICES={j+base_device} vllm serve {ckpt_paths[j]} --host 0.0.0.0 --port {ports[j]} --served-model-name {sft_model_name} --enable-prefix-caching
""",
shell=True,
stdout=subprocess.DEVNULL,
)
print("wait for 30s")
time.sleep(30)
else:
print("skip launch")
# check deployment (vllm)
while True:
try:
# sft_model_name = ''.join(ckpt_paths[j].split("/")[7:])
message_input = [{"role": "user", "content": "hello!"}]
headers = {"Content-Type": "application/json"}
data_json = {
"model": sft_model_name,
"messages": message_input,
}
print(f"send request, {data_json['model']}")
response = requests.post(
f"http://0.0.0.0:{ports[0]}/v1/chat/completions",
headers=headers,
json=data_json,
)
print(response.json())
content = (response.json()["choices"][0]["message"]["content"],)
print(f"ready to generate data: {content}")
break
except Exception as e:
print(f'error: {e}')
time.sleep(5)
# check deployment (openai)
# while True:
# try:
# sft_model_name = ''.join(ckpt_paths[0].split("/")[7:])
# client = openai.Client(base_url=f"http://localhost:{ports[0]}/v1", api_key='empty')
# print(f'send request, {sft_model_name}')
# resp = client.chat.completions.create(
# model=sft_model_name,
# messages=[
# {"role": "system", "content": "You are a helpful assistant."},
# {"role": "user", "content": "What is the meaning of life?"},
# ],
# )
# content = resp.choices[0].message.content
# print(content)
# break
# except Exception as e:
# print(f'error: {e}')
# time.sleep(5)
# eval sft
all_process = []
if override == False:
part_num = 1
else:
part_num = 300 # 10
iteration_limit = 200
split = "train"
policy = "random" # "modified"
roll_num = 3
for j in range(devices):
# sft_model_name = ''.join(ckpt_paths[j].split("/")[7:]) #.replace("/", "_")
task_name = "alfworld"
print(f"{split} {j}, {task_name} iteration_limit: {iteration_limit} part_num: {part_num}")
assert task_name in ["webshop", "alfworld", "sciworld", "intercode_sql", "gsm8k", "gsmhard", "math"], print(f"task_name: {task_name}")
if task_name == 'intercode_sql':
assert part_num == 1
for part_idx in range(part_num):
if override:
if not os.path.exists(f"logs/{task_name}_{split}"):
os.makedirs(f"logs/{task_name}_{split}")
# vllm
process = subprocess.Popen(
f"""source ~/.bashrc && \
export PYTHONPATH="$(pwd)" && \
conda activate IPR && \
python search/generation/generate_both_samples_webshop.py --address http://0.0.0.0:{ports[j]}/v1/chat/completions\
--propose_method {sft_model_name}\
--roll_policy {policy} \
--roll_num {roll_num} \
--iteration_limit {iteration_limit} \
--task_name {task_name}\
--split {split}\
--part_num {part_num}\
--part_idx {part_idx}
""",
shell=True,
)
# > logs/{task_name}_{split}/{part_idx}.log 2>&1
# openai
# process = subprocess.Popen(
# f"""source ~/.bashrc && \
# conda activate IPR && \
# python -m eval_agent.main --address http://0.0.0.0:{ports[j]}/v1\
# --model_name {sft_model_name}\
# --exp_config {task_name}\
# --split test\
# --override\
# --part_num {part_num}\
# --part_idx {part_idx}\
# --output_path outputs/{task_name}/{sft_model_name}_10process_datacache_time2_sglang
# """,
# shell=True,
# )
else:
process = subprocess.Popen(
f"""source ~/.bashrc && \
conda activate IPR && \
python -m eval_agent.main --address http://0.0.0.0:{ports[j]}/v1/chat/completions\
--model_name {sft_model_name}\
--exp_config {task_name}\
--split test\
--part_num {part_num}\
--part_idx {part_idx}\
--output_path outputs/{task_name}/{sft_model_name}
""",
shell=True,
)
all_process.append(process)
for p in all_process:
p.wait()
for j in range(devices):
# sft_model_name = ''.join(ckpt_paths[j].split("/")[7:]) #.replace("/", "_")
print(f"kill {j}, {sft_model_name}")
os.system(
f"""pkill -f "vllm serve {ckpt_paths[j]} --host 0.0.0.0 --port {ports[j]} --served-model-name {sft_model_name} --enable-prefix-caching" """
)
if __name__=="__main__":
main()