Skip to content

Commit 5c08454

Browse files
committed
Automicatic S3 Benchmark upload - error handling
Signed-off-by: Tadiwa Magwenzi <[email protected]>
1 parent a21ca7f commit 5c08454

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

benchmark/benchmark.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ def upload_results_to_s3(bucket_name: str, region: str) -> None:
7272
hydra_config = HydraConfig.get()
7373

7474
if hydra_config.mode == RunMode.MULTIRUN:
75-
parts = Path(hydra_config.runtime.output_dir).parent.parts
75+
source_path = Path(hydra_config.runtime.output_dir).parent
7676

77-
date_part, time_part = parts[-2:]
77+
assert len(source_path.parts) >= 2, "Source path must have at least 2 parts for date/time extraction"
78+
date_part, time_part = source_path.parts[-2:]
7879

7980
s3_target_path = f"s3://{bucket_name}/results/{date_part}/{time_part}"
8081

81-
source_path = Path(hydra_config.runtime.output_dir).parent
82-
8382
aws_cmd = [
8483
"aws",
8584
"s3",
@@ -91,7 +90,7 @@ def upload_results_to_s3(bucket_name: str, region: str) -> None:
9190
]
9291
result = subprocess.run(aws_cmd, capture_output=True, text=True)
9392
if result.returncode == 0:
94-
log.info("Successfully uploaded multirun benchmark results to S3")
93+
log.info("Successfully uploaded benchmark results to S3")
9594
else:
9695
log.error(f"S3 upload failed: {result.stderr.strip()}")
9796
else:
@@ -238,6 +237,17 @@ def run_experiment(cfg: DictConfig) -> None:
238237

239238
# Mark success if we get here without exceptions
240239
metadata["success"] = True
240+
241+
result_bucket_name = common_config.get("s3_result_bucket")
242+
243+
# If region is not specified, default to 'us-east-1' as that is the only region we can be relavtively assued that tranium instances are available
244+
region = common_config.get("region", "us-east-1")
245+
if result_bucket_name:
246+
log.info(f"Uploading benchmark results to S3 bucket '{result_bucket_name}'")
247+
upload_results_to_s3(result_bucket_name, region)
248+
else:
249+
log.info("No results bucket specified (s3_result_bucket), skipping upload")
250+
241251
except Exception:
242252
log.error("Benchmark execution failed:", exc_info=True)
243253
raise
@@ -250,17 +260,6 @@ def run_experiment(cfg: DictConfig) -> None:
250260
write_metadata(metadata)
251261
metadata["end_time"] = datetime.now(tz=timezone.utc)
252262

253-
result_bucket_name = common_config.get("s3_result_bucket")
254-
255-
# If region is not specified, default to 'us-east-1' as that is the only region we can be relavtively assued that tranium instances are available
256-
region = common_config.get("region", "us-east-1")
257-
258-
if result_bucket_name:
259-
log.info(f"Uploading benchmark results to S3 bucket '{result_bucket_name}'")
260-
upload_results_to_s3(result_bucket_name, region)
261-
else:
262-
log.info("No results bucket specified (s3_result_bucket), skipping upload")
263-
264263

265264
if __name__ == "__main__":
266265
run_experiment()

0 commit comments

Comments
 (0)