-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathproject_bite_config.py
204 lines (183 loc) · 6.42 KB
/
project_bite_config.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities to construct configs for solutionsteam_jax_bite DAG."""
import datetime
from typing import Tuple, Optional
from dags.common import test_owner
from xlml.apis import gcp_config, metric_config, task, test_config
from dags import gcs_bucket
from dags.sparsity_diffusion_devx.configs import common
from dags.common.vm_resource import TpuVersion, Project
from airflow.models.taskmixin import DAGNode
GCS_SUBFOLDER_PREFIX = test_owner.Team.SPARSITY_DIFFUSION_DEVX.value
def set_up_axlearn(pinned_version) -> Tuple[str]:
reset_version = ""
if pinned_version:
reset_version = f"cd axlearn && git reset --hard {pinned_version} && cd .."
return (
common.UPGRADE_PIP,
common.UPGRADE_SETUPTOOLS,
common.UPGRADE_PACKAGING,
"git clone https://github.com/apple/axlearn.git",
reset_version,
"python -m pip install ./axlearn[core]",
*common.set_up_nightly_jax(),
)
def get_bite_tpu_config(
tpu_version: TpuVersion,
tpu_cores: int,
tpu_zone: str,
runtime_version: str,
model_config: str,
time_out_in_min: int,
task_owner: str,
is_tpu_reserved: bool = False,
pinned_version: Optional[str] = None,
project_name: Optional[Project] = Project.CLOUD_ML_AUTO_SOLUTIONS.value,
network: str = "default",
subnetwork: str = "default",
):
job_gcp_config = gcp_config.GCPConfig(
project_name=project_name,
zone=tpu_zone,
dataset_name=metric_config.DatasetOption.XLML_DATASET,
)
set_up_cmds = set_up_axlearn(pinned_version)
run_model_cmds = (
(
"cd axlearn && python -m axlearn.common.launch_trainer_main"
f" --module=text.gpt.c4_trainer --config={model_config}"
f" --trainer_dir={metric_config.SshEnvVars.GCS_OUTPUT.value}"
f" --data_dir={gcs_bucket.AXLEARN_DIR} --jax_backend=tpu"
),
)
test_name = f"bite_{'pinned_' if pinned_version else ''}{model_config}"
job_test_config = test_config.TpuVmTest(
test_config.Tpu(
version=tpu_version,
cores=tpu_cores,
runtime_version=runtime_version,
reserved=is_tpu_reserved,
network=network,
subnetwork=subnetwork,
),
test_name=test_name,
set_up_cmds=set_up_cmds,
run_model_cmds=run_model_cmds,
timeout=datetime.timedelta(minutes=time_out_in_min),
task_owner=task_owner,
gcs_subfolder=f"{GCS_SUBFOLDER_PREFIX}/jax",
)
return task.run_queued_resource_test(
task_test_config=job_test_config,
task_gcp_config=job_gcp_config,
)
def dockerfile_build_cmd(jax_version):
# Generate pip commands to install certain version of JAX/libTPU e.g.
# pip install --pre jaxlib==0.5.1 -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html
# pip install jax[tpu]==0.5.1 -f https://storage.googleapis.com/jax-releases/libtpu_releases.html
# pip install jax==0.5.1
if jax_version:
pip_tpu_jax_install = "\n".join(
["RUN " + x for x in common.set_up_jax_version(jax_version)]
)
else:
pip_tpu_jax_install = "\n".join(
["RUN " + x for x in common.set_up_nightly_jax()]
)
return (
"""cat > Dockerfile_CI <<EOF
FROM python:3.10-slim
WORKDIR /workspace
COPY run_tpu_tests.sh /workspace/
RUN apt update -y
RUN apt install -y git
RUN git clone https://github.com/apple/axlearn.git
WORKDIR /workspace/axlearn
RUN pip install --upgrade pip
RUN pip install -e '.[core,dev,gcp]'
RUN pip install grain
RUN pip install google-cloud-aiplatform
"""
+ pip_tpu_jax_install
+ """
RUN pip freeze
EOF
"""
)
def get_bite_tpu_unittests_config(
tpu_version: TpuVersion,
tpu_cores: int,
tpu_zone: str,
runtime_version: str,
time_out_in_min: int,
task_owner: str,
network: str = "default",
subnetwork: str = "default",
is_tpu_reserved: bool = False,
jax_version: Optional[str] = None,
test_suffix: Optional[str] = None,
project_name: Optional[Project] = Project.CLOUD_ML_AUTO_SOLUTIONS.value,
):
unittest_setupcmds = (
# create configuration files needed
dockerfile_build_cmd(jax_version),
# create script to run the tests inside of the container
# incluedes a basic sanity check python script which prints out TPU env info for reference
"""cat > run_tpu_tests.sh <<EOF
set -x
echo '#### Starting TPU JAX Tests'
pip freeze
JAX_PLATFORMS='tpu' python -c 'import jax; jax.print_environment_info() ; print(f"Global device count: {jax.device_count()}")'
cd /workspace/axlearn
pytest --no-header -v axlearn/common/flash_attention/
EOF
""",
"chmod +x run_tpu_tests.sh",
"sudo docker build -f Dockerfile_CI -t ml-auto-solutions/tpu_unittests .",
)
# Run the unittest as non-root user, ulimit param req to mmap TPUs inside docker (default limit is 8192)
unittest_runcmds = (
"echo '#### Start docker image - tpu_unittests'",
"sudo docker run --network=host --privileged --ulimit memlock=-1:-1 ml-auto-solutions/tpu_unittests /bin/bash -c '/workspace/run_tpu_tests.sh'",
)
job_gcp_config = gcp_config.GCPConfig(
project_name=project_name,
zone=tpu_zone,
dataset_name=metric_config.DatasetOption.XLML_DATASET,
)
if test_suffix:
test_name = f"bite_unittests_{test_suffix}"
else:
test_name = "bite_unittests"
tpu_unittests_test_config = test_config.TpuVmTest(
test_config.Tpu(
version=tpu_version,
cores=tpu_cores,
runtime_version=runtime_version,
reserved=is_tpu_reserved,
network=network,
subnetwork=subnetwork,
),
test_name=test_name,
set_up_cmds=unittest_setupcmds,
run_model_cmds=unittest_runcmds,
timeout=datetime.timedelta(minutes=time_out_in_min),
task_owner=task_owner,
gcs_subfolder=f"{GCS_SUBFOLDER_PREFIX}/jax",
)
return task.run_queued_resource_test(
task_test_config=tpu_unittests_test_config,
task_gcp_config=job_gcp_config,
)