-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_eval.py
170 lines (136 loc) · 4.92 KB
/
remote_eval.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
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
159
160
161
162
163
164
165
166
167
168
169
170
#heavily borrowed from https://github.com/modal-labs/llm-finetuning/tree/main/src
import os
from pathlib import PurePosixPath
from typing import Union
import modal
APP_NAME = "CompChomper-LLM-eval"
MINUTES = 60 # seconds
HOURS = 60 * MINUTES
def get_cuda_image(base="nvidia/cuda:12.1.0-base-ubuntu22.04"):
my_reqs_txt = os.path.join(os.path.dirname(__file__), "requirements.txt")
with open(my_reqs_txt, 'r') as reqs_file:
my_reqs = [l.strip() for l in reqs_file.readlines()]
print(f"reqs: {my_reqs}")
apt_commands = [
"jq", "make", "curl", "git", "pciutils", "cuda-toolkit"
]
img = modal.Image.from_registry(base, add_python="3.10")
img = img.apt_install(*apt_commands)
img = img.run_commands("curl -fsSL https://ollama.com/install.sh | sh")
img = img.pip_install(*my_reqs).run_commands("python3 -m pip install flash-attn==2.6.1 --no-build-isolation")
# for some reason extra_options to pip doesn't work
img = img.env({"OLLAMA_MODELS": "/app/eval_models/ollama"})
img = img.env({"HF_HOME": "/app/eval_models/hf"})
return img
app = modal.App(APP_NAME)
# Volumes for pre-trained models and training runs.
eval_packages = modal.Volume.from_name(
"eval_packages", create_if_missing=True
)
eval_outputs = modal.Volume.from_name(
"eval_outputs", create_if_missing=True
)
eval_models = modal.Volume.from_name(
"eval_models", create_if_missing=True
)
eval_raw_files = modal.Volume.from_name(
"eval_raw_files", create_if_missing=True
)
VOLUME_CONFIG: dict[Union[str, PurePosixPath], modal.Volume] = {
"/app/eval_packages" : eval_packages,
"/app/eval_outputs" : eval_outputs,
"/app/eval_models" : eval_models,
"/app/eval_raw_files" : eval_raw_files,
}
MOUNT_CONFIG = [
modal.Mount.from_local_dir("./src", remote_path="/app/src"),
modal.Mount.from_local_dir("./config", remote_path="/app/config"),
modal.Mount.from_local_file("./Makefile", remote_path="/app/Makefile")
]
#SINGLE_GPU_CONFIG = os.environ.get("GPU_CONFIG", "a10g:1")
# we need more vram for larger models
SINGLE_GPU_CONFIG = os.environ.get("GPU_CONFIG", "a100-80gb:1")
def get_commands(provider, packages):
base_command = ""
commands = []
if provider == "ollama":
base_command = "(ollama serve)& sleep 4"
base_command += " && mkdir -p ${OLLAMA_MODELS}"
base_command += " && cd /app"
base_command += " && make fetch_ollama"
for package in packages:
run_command = base_command
run_command += f" && make eval_ollama EVAL_DATA_FILE={package}"
commands.append(run_command)
elif provider == "hf":
base_command = "cd /app && make fetch_hf"
for package in packages:
run_command = base_command
run_command += f" && make eval_hf EVAL_DATA_FILE={package}"
commands.append(run_command)
elif provider == "openai":
base_command = "cd /app && make fetch_openai"
for package in packages:
run_command = base_command
run_command += f" && make eval_openai EVAL_DATA_FILE={package}"
commands.append(run_command)
elif provider == "claude":
base_command = "cd /app && make fetch_claude"
for package in packages:
run_command = base_command
run_command += f" && make eval_claude EVAL_DATA_FILE={package}"
commands.append(run_command)
return commands
def generic_eval_runner(provider):
packages = os.environ.get("EVAL_DATA_FILE", None)
if packages is None:
raise RuntimeError("Please specify a list of packages to eval in EVAL_DATA_FILE env var")
packages = packages.split(";")
commands = get_commands(provider, packages)
for command in commands:
run_in_sandbox(command)
@app.local_entrypoint()
def eval_ollama():
generic_eval_runner("ollama")
@app.local_entrypoint()
def eval_hf():
generic_eval_runner("hf")
@app.local_entrypoint()
def eval_openai():
generic_eval_runner("openai")
@app.local_entrypoint()
def eval_claude():
generic_eval_runner("claude")
@app.local_entrypoint()
def make_eval_packages():
run_in_sandbox("cd /app && make eval_packages_2024-06")
@app.local_entrypoint()
def fetch_all():
run_in_sandbox("(ollama serve)& sleep 4 && cd /app && make fetch_all")
@app.local_entrypoint()
def main():
fetch_all()
make_eval_packages()
eval_openai()
eval_claude()
eval_hf()
eval_ollama()
def run_in_sandbox(cmd: str):
sb = app.spawn_sandbox(
"bash",
"-c",
cmd,
image=get_cuda_image(),
mounts=MOUNT_CONFIG,
volumes=VOLUME_CONFIG,
timeout=24 * HOURS,
gpu=SINGLE_GPU_CONFIG,
secrets=[modal.Secret.from_dotenv()],
)
sb.wait()
if sb.returncode != 0:
print(f"Run failed with code {sb.returncode}")
print(sb.stderr.read())
else:
print(f"Run success")
print(sb.stdout.read())