Skip to content

Commit 4d4a70c

Browse files
committed
fixed timeout, added num_cpus as argument, handled stdout and stderr
1 parent bbfa975 commit 4d4a70c

File tree

9 files changed

+32
-15
lines changed

9 files changed

+32
-15
lines changed

commit0/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def main() -> None:
7878
test_ids,
7979
config.backend,
8080
config.timeout,
81+
config.num_cpus,
8182
stdout=True,
8283
)
8384
elif command == "evaluate" or command == "evaluate-reference":
@@ -91,6 +92,7 @@ def main() -> None:
9192
config.branch,
9293
config.backend,
9394
config.timeout,
95+
config.num_cpus,
9496
config.num_workers,
9597
)
9698
elif command == "save":

commit0/configs/base.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ num_workers: 8
1616
backend: local
1717
branch: ai
1818
timeout: 1_800
19+
num_cpus: 1
1920

2021
# save related
2122
github_token: null

commit0/configs/config_class.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Commit0Config:
2222
branch: str
2323
# timeout for running pytest
2424
timeout: int
25+
num_cpus: int
2526

2627
# save related
2728
github_token: Optional[str]

commit0/configs/user.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ defaults:
22
- base
33
- _self_
44

5-
backend: local
5+
backend: modal

commit0/harness/docker_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def create_container(
247247
image_name: str,
248248
container_name: Optional[str] = None,
249249
user: Optional[str] = None,
250-
command: Optional[str] = None,
250+
command: Optional[str] = "tail -f /dev/null",
251251
nano_cpus: Optional[int] = None,
252252
logger: Optional[Union[str, logging.Logger]] = None,
253253
) -> Container:
@@ -312,7 +312,7 @@ def log_info(x: str) -> None:
312312
image=image_name,
313313
name=container_name,
314314
user=user,
315-
command="tail -f /dev/null",
315+
command=command,
316316
nano_cpus=nano_cpus,
317317
detach=True,
318318
)

commit0/harness/evaluate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def main(
2626
branch: str,
2727
backend: str,
2828
timeout: int,
29+
num_cpus: int,
2930
num_workers: int,
3031
) -> None:
3132
dataset: Iterator[RepoInstance] = load_dataset(dataset_name, split=dataset_split) # type: ignore
@@ -52,6 +53,7 @@ def main(
5253
test_dir,
5354
backend,
5455
timeout,
56+
num_cpus,
5557
stdout=False,
5658
): None
5759
for repo, test_dir in pairs

commit0/harness/execution_context.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
spec: Spec,
5353
logger: logging.Logger,
5454
timeout: int,
55+
num_cpus: int,
5556
log_dir: Path,
5657
files_to_copy: Optional[Files] = None,
5758
):
@@ -63,6 +64,7 @@ def __init__(
6364
self.spec = spec
6465
self.logger = logger
6566
self.timeout = timeout
67+
self.num_cpus = num_cpus
6668
self.log_dir = log_dir
6769

6870
@abstractmethod
@@ -102,16 +104,18 @@ def __init__(
102104
spec: Spec,
103105
logger: logging.Logger,
104106
timeout: int,
107+
num_cpus: int,
105108
log_dir: Path,
106109
files_to_copy: Optional[Files] = None,
107110
):
108-
super().__init__(spec, logger, timeout, log_dir)
111+
super().__init__(spec, logger, timeout, num_cpus, log_dir)
109112

110113
self.client = docker.from_env()
111114
self.container = create_container(
112115
client=self.client,
113116
image_name=spec.repo_image_key,
114117
container_name=spec.get_container_name(),
118+
nano_cpus=num_cpus,
115119
logger=logger,
116120
)
117121
self.container.start()
@@ -153,10 +157,11 @@ def __init__(
153157
spec: Spec,
154158
logger: logging.Logger,
155159
timeout: int,
160+
num_cpus: int,
156161
log_dir: Path,
157162
files_to_copy: Optional[Files] = None,
158163
):
159-
super().__init__(spec, logger, timeout, log_dir)
164+
super().__init__(spec, logger, timeout, num_cpus, log_dir)
160165

161166
self.app = modal.App()
162167

@@ -181,19 +186,22 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
181186
"-c",
182187
f"{command} && cp {str(report_file)} /vol/report.json",
183188
image=self.image,
184-
cpu=4.0,
189+
cpu=self.num_cpus,
185190
timeout=self.timeout,
186191
app=self.app,
187192
volumes={"/vol": vol},
188193
)
189194
self.sandbox.wait()
190195

191-
stdout = read_stream(self.sandbox.stdout)
192-
# stderr = read_stream(self.sandbox.stderr)
196+
# stdout has been redirected to stderr
197+
stdout = read_stream(self.sandbox.stderr)
193198

194-
# return_code = self.sandbox.returncode
195-
# maybe use return_code for timeout info?
196-
# i dont know if sandboxes throw modal.TimeoutError
199+
return_code = self.sandbox.returncode
200+
# https://github.com/modal-labs/modal-client/blob/d577b2916b5c3bf4ebbcb58fadced84d85e1cf8c/modal/sandbox.py#L413
201+
if return_code == 124:
202+
timed_out = True
203+
else:
204+
timed_out = False
197205

198206
# copy over report.json from mount
199207
with (self.log_dir / "report.json").open("wb") as f:
@@ -204,8 +212,7 @@ def exec_run_with_timeout(self, command: str) -> tuple[str, bool, float]:
204212

205213
end_time = time.time()
206214

207-
# TODO: add check for timeout
208-
return stdout, False, end_time - start_time
215+
return stdout, timed_out, end_time - start_time
209216

210217
def __exit__(
211218
self,

commit0/harness/run_pytest_ids.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def main(
3636
test_ids: str,
3737
backend: str,
3838
timeout: int,
39+
num_cpus: int,
3940
stdout: bool,
4041
) -> str:
4142
"""Runs the pytests for repos in a dataset.
@@ -93,7 +94,7 @@ def main(
9394

9495
try:
9596
with execution_context(
96-
spec, logger, timeout, log_dir, files_to_copy
97+
spec, logger, timeout, num_cpus, log_dir, files_to_copy
9798
) as context:
9899
output, timed_out, total_runtime = context.exec_run_with_timeout(
99100
"/bin/bash /eval.sh"
@@ -103,7 +104,8 @@ def main(
103104
output, "--json-report --json-report-file=report.json"
104105
)
105106
context.write_test_output(test_output, timed_out)
106-
print(test_output)
107+
if stdout:
108+
print(test_output)
107109
except EvaluationError as e:
108110
error_msg = (
109111
f"Error in running pytest for {repo}: {e}\n"

commit0/harness/spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def make_eval_script_list(instance: RepoInstance, repo_directory: str) -> list[s
157157
f"git reset --hard {instance['base_commit']}",
158158
"git status",
159159
]
160+
for i in range(len(eval_script_list)):
161+
eval_script_list[i] = f"{eval_script_list[i]} 1>&2"
160162
return eval_script_list
161163

162164

0 commit comments

Comments
 (0)