Skip to content

Commit 2a9a494

Browse files
authored
Automated Benchmark Result Upload (#1527)
### What changed and why? This PR adds functionality to automatically upload benchmark results to an S3 bucket when benchmarks complete. The implementation includes: 1. A new `detect_result_folder()` function that determines the appropriate result folder path and source path based on Hydra's runtime configuration 2. A new `upload_results_to_s3()` function that uses AWS CLI to sync local benchmark results to the specified S3 bucket These changes enable automated collection of benchmark results in a centralized S3 location, making it easier to analyze performance trends over time. ### Does this change impact existing behavior? No. ### Does this change need a changelog entry? Does it require a version change? No --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). --------- Signed-off-by: Tadiwa Magwenzi <[email protected]>
1 parent dcbbcc1 commit 2a9a494

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

benchmark/benchmark.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import signal
66
import subprocess
77
from datetime import datetime, timezone
8+
from pathlib import Path
89
from typing import List, Dict, Any, Optional
910

1011
import hydra
12+
from hydra.core.hydra_config import HydraConfig
13+
from hydra.types import RunMode
1114
from omegaconf import DictConfig, OmegaConf
1215
import urllib.request
1316

@@ -60,6 +63,40 @@ def write_metadata(metadata: Dict[str, Any]) -> None:
6063
log.error("Failed to write metadata", exc_info=True)
6164

6265

66+
def upload_results_to_s3(bucket_name: str, region: str) -> None:
67+
"""
68+
Upload benchmark results to S3 bucket using the AWS CLI.
69+
Only uploads results from multirun directories.
70+
"""
71+
72+
hydra_config = HydraConfig.get()
73+
74+
if hydra_config.mode == RunMode.MULTIRUN:
75+
source_path = Path(hydra_config.runtime.output_dir).parent
76+
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:]
79+
80+
s3_target_path = f"s3://{bucket_name}/results/{date_part}/{time_part}"
81+
82+
aws_cmd = [
83+
"aws",
84+
"s3",
85+
"sync",
86+
str(source_path),
87+
s3_target_path,
88+
"--region",
89+
region,
90+
]
91+
result = subprocess.run(aws_cmd, capture_output=True, text=True)
92+
if result.returncode == 0:
93+
log.info("Successfully uploaded benchmark results to S3")
94+
else:
95+
log.error(f"S3 upload failed: {result.stderr.strip()}")
96+
else:
97+
log.info("Skipping benchmark upload for non-multirun")
98+
99+
63100
class ResourceMonitoring:
64101
def __init__(self, target_pid, with_bwm: bool, with_perf_stat: bool):
65102
"""Resource monitoring setup.
@@ -200,6 +237,17 @@ def run_experiment(cfg: DictConfig) -> None:
200237

201238
# Mark success if we get here without exceptions
202239
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+
203251
except Exception:
204252
log.error("Benchmark execution failed:", exc_info=True)
205253
raise

benchmark/benchmarks/benchmark_config_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def get_common_config(self) -> Dict[str, Any]:
3737
'region': getattr(self.cfg, 'region', "us-east-1"),
3838
'run_time': getattr(self.cfg, 'run_time', 30),
3939
's3_bucket': getattr(self.cfg, 's3_bucket', None),
40+
's3_result_bucket': getattr(self.cfg, 's3_result_bucket', None),
4041
's3_keys': self._parse_comma_separated_string_to_array(getattr(self.cfg, 's3_keys', None)),
4142
'with_bwm': getattr(self.cfg.monitoring, 'with_bwm', False),
4243
'write_part_size': getattr(self.cfg, 'write_part_size', 16777216), # 16 MiB

benchmark/conf/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defaults:
66

77
# ===== Common parameters for all benchmarks =====
88
s3_bucket: ???
9+
s3_result_bucket: !!null
910
application_workers: 1
1011
iteration: 0
1112
iterations: 1

0 commit comments

Comments
 (0)