-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathmodal_ci.py
164 lines (141 loc) · 5.46 KB
/
modal_ci.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
import os
import subprocess
import modal
# Create an image with system dependencies
image = (
modal.Image.debian_slim(python_version=os.environ["PYTHON_VERSION"])
.apt_install(["git", "procps", "build-essential", "cmake", "wget"])
.pip_install_from_requirements("requirements-dev.txt")
.pip_install_from_requirements("requirements.txt")
.run_commands(
[
"git clone --branch 0.45.2 --depth 1 https://github.com/bitsandbytes-foundation/bitsandbytes.git",
"cd bitsandbytes && cmake -DCOMPUTE_BACKEND=cpu -S . && make && pip --no-cache install . ",
]
)
.add_local_dir("hivemind", remote_path="/root/hivemind/hivemind")
.add_local_file("requirements.txt", remote_path="/root/hivemind/requirements.txt")
.add_local_file("requirements-dev.txt", remote_path="/root/hivemind/requirements-dev.txt")
.add_local_file("requirements-docs.txt", remote_path="/root/hivemind/requirements-docs.txt")
.add_local_file("setup.py", remote_path="/root/hivemind/setup.py")
.add_local_file("pyproject.toml", remote_path="/root/hivemind/pyproject.toml")
.add_local_dir("tests", remote_path="/root/hivemind/tests")
)
# Create an image with golang and other system dependencies
image_with_golang = (
modal.Image.debian_slim(python_version=os.environ["PYTHON_VERSION"])
.apt_install(["git", "procps", "build-essential", "cmake", "wget"])
.pip_install_from_requirements("requirements-dev.txt")
.pip_install_from_requirements("requirements.txt")
.run_commands(
[
# Install Go 1.20.11
"wget https://go.dev/dl/go1.20.11.linux-amd64.tar.gz",
"rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.11.linux-amd64.tar.gz",
"ln -s /usr/local/go/bin/go /usr/bin/go",
# Install bitsandbytes
"git clone --branch 0.45.2 --depth 1 https://github.com/bitsandbytes-foundation/bitsandbytes.git",
"cd bitsandbytes && cmake -DCOMPUTE_BACKEND=cpu -S . && make && pip --no-cache install . ",
]
)
.add_local_dir("hivemind", remote_path="/root/hivemind/hivemind")
.add_local_file("requirements.txt", remote_path="/root/hivemind/requirements.txt")
.add_local_file("requirements-dev.txt", remote_path="/root/hivemind/requirements-dev.txt")
.add_local_file("requirements-docs.txt", remote_path="/root/hivemind/requirements-docs.txt")
.add_local_file("setup.py", remote_path="/root/hivemind/setup.py")
.add_local_file("pyproject.toml", remote_path="/root/hivemind/pyproject.toml")
.add_local_dir("tests", remote_path="/root/hivemind/tests")
)
app = modal.App("hivemind-ci")
codecov_secret = modal.Secret.from_dict(
{
"CODECOV_TOKEN": os.getenv("CODECOV_TOKEN"),
"GITHUB_EVENT_PULL_REQUEST_HEAD_SHA": os.getenv("GITHUB_EVENT_PULL_REQUEST_HEAD_SHA"),
"GITHUB_EVENT_NUMBER": os.getenv("GITHUB_EVENT_NUMBER"),
"GITHUB_REPOSITORY": os.getenv("GITHUB_REPOSITORY"),
}
)
def setup_environment(*, build_p2pd=False):
os.chdir("/root/hivemind")
if build_p2pd:
install_cmd = [
"pip",
"install",
"--no-cache-dir",
".",
"--global-option=build_py",
"--global-option=--buildgo",
"--no-use-pep517",
]
else:
install_cmd = ["pip", "install", "-e", ".", "--no-use-pep517"]
subprocess.run(install_cmd, check=True)
environment = os.environ.copy()
environment["HIVEMIND_MEMORY_SHARING_STRATEGY"] = "file_descriptor"
return environment
@app.function(image=image, timeout=600, cpu=8, memory=8192)
def run_tests():
environment = setup_environment(build_p2pd=False)
subprocess.run(
[
"pytest",
"--durations=0",
"--durations-min=1.0",
"-v",
"-n",
"8",
"tests",
],
check=True,
env=environment,
)
@app.function(image=image, timeout=900, cpu=8, memory=8192, secrets=[codecov_secret])
def run_codecov():
environment = setup_environment(build_p2pd=False)
subprocess.run(
[
"pytest",
"--cov",
"hivemind",
"--cov-config=pyproject.toml",
"-v",
"tests",
],
check=True,
env=environment,
)
# Forward GitHub Actions environment variables to the codecov command
environment.update(
{
"CODECOV_TOKEN": os.environ["CODECOV_TOKEN"],
"CC_SHA": os.environ["GITHUB_EVENT_PULL_REQUEST_HEAD_SHA"],
"CC_PR": os.environ["GITHUB_EVENT_NUMBER"],
"CC_SLUG": os.environ["GITHUB_REPOSITORY"],
}
)
subprocess.run(
[
"bash",
"-c",
"wget -q https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov "
"&& ./codecov create-commit -C $CC_SHA -P $CC_PR -r $CC_SLUG --git-service github "
"&& ./codecov create-report -C $CC_SHA -r $CC_SLUG --git-service github "
"&& ./codecov do-upload -C $CC_SHA -r $CC_SLUG -P $CC_PR --git-service github",
],
check=True,
env=environment,
)
@app.function(image=image_with_golang, timeout=600, cpu=1, memory=4096)
def build_and_test_p2pd():
environment = setup_environment(build_p2pd=True)
subprocess.run(
[
"pytest",
"-k",
"p2p",
"-v",
"tests",
],
check=True,
env=environment,
)