-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathtest_mason.py
More file actions
185 lines (174 loc) · 7.06 KB
/
test_mason.py
File metadata and controls
185 lines (174 loc) · 7.06 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
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
import unittest
from argparse import Namespace
import beaker
import parameterized
import mason
class TestBuildCommandWithoutArgs(unittest.TestCase):
@parameterized.parameterized.expand(
[
(
"remove_arg_without_value",
["python", "script.py", "--with_tracking", "--output", "out.txt"],
{"--with_tracking": False},
["python", "script.py", "--output", "out.txt"],
),
(
"remove_arg_with_value",
["python", "script.py", "--checkpoint_state_dir", "/path/to/dir", "--output", "out.txt"],
{"--checkpoint_state_dir": True},
["python", "script.py", "--output", "out.txt"],
),
(
"remove_multiple_args",
["python", "script.py", "--with_tracking", "--checkpoint_state_dir", "/path", "--output", "out.txt"],
{"--with_tracking": False, "--checkpoint_state_dir": True},
["python", "script.py", "--output", "out.txt"],
),
(
"arg_not_present",
["python", "script.py", "--output", "out.txt"],
{"--nonexistent": True},
["python", "script.py", "--output", "out.txt"],
),
("empty_command", [], {"--with_tracking": False}, []),
(
"empty_args_to_remove",
["python", "script.py", "--output", "out.txt"],
{},
["python", "script.py", "--output", "out.txt"],
),
(
"remove_all_cache_excluded_args",
[
"python",
"open_instruct/grpo_fast.py",
"--with_tracking",
"--checkpoint_state_freq",
"200",
"--checkpoint_state_dir",
"/weka/path",
"--gs_checkpoint_state_dir",
"gs://bucket",
"--output",
"out.txt",
],
mason.CACHE_EXCLUDED_ARGS,
["python", "open_instruct/grpo_fast.py", "--output", "out.txt"],
),
(
"arg_at_end_without_value",
["python", "script.py", "--output", "out.txt", "--with_tracking"],
{"--with_tracking": False},
["python", "script.py", "--output", "out.txt"],
),
(
"arg_at_end_with_value",
["python", "script.py", "--output", "out.txt", "--checkpoint_dir", "/path"],
{"--checkpoint_dir": True},
["python", "script.py", "--output", "out.txt"],
),
]
)
def test_build_command_without_args(self, name, command, args_to_remove, expected):
result = mason.build_command_without_args(command, args_to_remove)
self.assertEqual(result, expected)
class TestExperimentSpec(unittest.TestCase):
@parameterized.parameterized.expand(
[
(
"single_gpu",
{
"cluster": ["ai2/jupiter", "ai2/saturn", "ai2/ceres"],
"image": "test-user/open-instruct-integration-test",
"description": "Single GPU on Beaker test script.",
"pure_docker_mode": True,
"workspace": "ai2/open-instruct-dev",
"priority": "urgent",
"num_nodes": 1,
"max_retries": 0,
"timeout": "15m",
"env": [{"name": "VLLM_ALLOW_LONG_MAX_MODEL_LEN", "value": "1"}],
"budget": "ai2/oe-adapt",
"gpus": 1,
"no_host_networking": False,
"beaker_datasets": [],
"secret": [],
"shared_memory": "10.24gb",
"task_name": "beaker_mason",
"hostname": None,
"preemptible": False,
"mount_docker_socket": False,
},
),
(
"large_test",
{
"cluster": ["ai2/jupiter"],
"image": "test-user/open-instruct-integration-test",
"description": "Large (multi-node) test script.",
"pure_docker_mode": True,
"workspace": "ai2/open-instruct-dev",
"priority": "urgent",
"num_nodes": 2,
"max_retries": 0,
"timeout": "1h",
"env": [{"name": "VLLM_ALLOW_LONG_MAX_MODEL_LEN", "value": "1"}],
"budget": "ai2/oe-adapt",
"gpus": 8,
"no_host_networking": False,
"beaker_datasets": [],
"secret": [],
"shared_memory": "10.24gb",
"task_name": "beaker_mason",
"preemptible": True,
"hostname": None,
"mount_docker_socket": False,
},
),
]
)
def test_experiment_spec(self, name, args_dict):
args = Namespace(**args_dict)
full_command = "test command"
beaker_secrets = ["test-user"]
whoami = "test-user"
resumable = False
actual_spec = mason.make_task_spec(args, full_command, 0, beaker_secrets, whoami, resumable)
expected_spec = beaker.BeakerTaskSpec(
name=f"{args.task_name}__0",
image=beaker.BeakerImageSource(beaker=args.image),
command=["/bin/bash", "-c"],
arguments=[full_command],
result=beaker.BeakerResultSpec(path="/output"),
datasets=mason.get_datasets(args.beaker_datasets, args.cluster),
context=beaker.BeakerTaskContext(
priority=beaker.BeakerJobPriority[args.priority], preemptible=args.preemptible
),
constraints=beaker.BeakerConstraints(cluster=args.cluster)
if args.hostname is None
else beaker.BeakerConstraints(hostname=args.hostname),
env_vars=mason.get_env_vars(
args.pure_docker_mode,
args.cluster,
beaker_secrets,
whoami,
resumable,
args.num_nodes,
args.env,
args.secret,
),
resources=beaker.BeakerTaskResources(gpu_count=args.gpus, shared_memory=args.shared_memory),
replicas=args.num_nodes,
timeout=args.timeout,
)
if args.num_nodes > 1:
expected_spec.leader_selection = True
expected_spec.propagate_failure = True
expected_spec.propagate_preemption = True
if args.no_host_networking:
expected_spec.host_networking = False
else:
expected_spec.host_networking = True
self.assertEqual(actual_spec, expected_spec)
if __name__ == "__main__":
unittest.main()