-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
- Loading branch information
1 parent
675fb8f
commit cf4b61e
Showing
8 changed files
with
243 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
target_hour=22 | ||
target_min=00 | ||
while true | ||
do | ||
current_hour=$(date +%H) | ||
current_min=$(date +%M) | ||
if [ $current_hour -eq $target_hour ] && [ $current_min -eq $target_min ] ; then | ||
echo "Cron job started at $(date)" | ||
sh cron_script.sh > local_cron_log 2>local_cron_err | ||
echo "Cron job executed at $(date)" | ||
fi | ||
sleep 60 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import io | ||
import json | ||
from functools import lru_cache | ||
import boto3 | ||
from typing import Any | ||
import gzip | ||
|
||
@lru_cache | ||
def get_s3_resource() -> Any: | ||
return boto3.resource("s3") | ||
|
||
def upload_to_s3( | ||
bucket_name: str, | ||
key: str, | ||
json_path: str, | ||
) -> None: | ||
print(f"Writing {json_path} documents to S3") | ||
data = [] | ||
with open(f"{os.path.splitext(json_path)[0]}.json", "r") as f: | ||
for l in f.readlines(): | ||
data.append(json.loads(l)) | ||
|
||
body = io.StringIO() | ||
for benchmark_entry in data: | ||
json.dump(benchmark_entry, body) | ||
body.write("\n") | ||
|
||
try: | ||
get_s3_resource().Object( | ||
f"{bucket_name}", | ||
f"{key}", | ||
).put( | ||
Body=body.getvalue(), | ||
ContentType="application/json", | ||
) | ||
except e: | ||
print("fail to upload to s3:", e) | ||
return | ||
print("Done!") | ||
|
||
if __name__ == "__main__": | ||
import argparse | ||
import datetime | ||
parser = argparse.ArgumentParser(description="Upload benchmark result json file to clickhouse") | ||
parser.add_argument("--json-path", type=str, help="json file path to upload to click house", required=True) | ||
args = parser.parse_args() | ||
today = datetime.date.today() | ||
today = datetime.datetime.combine(today, datetime.time.min) | ||
today_timestamp = str(int(today.timestamp())) | ||
print("Today timestamp:", today_timestamp) | ||
import subprocess | ||
# Execute the command and capture the output | ||
output = subprocess.check_output(['hostname', '-s']) | ||
# Decode the output from bytes to string | ||
hostname = output.decode('utf-8').strip() | ||
upload_to_s3("ossci-benchmarks", f"v3/pytorch/ao/{hostname}/torchbenchmark-torchbench-" + today_timestamp + ".json", args.json_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import json | ||
import torch | ||
import platform | ||
import os | ||
import time | ||
import datetime | ||
import hashlib | ||
|
||
def get_arch_name() -> str: | ||
if torch.cuda.is_available(): | ||
return torch.cuda.get_device_name() | ||
else: | ||
# This returns x86_64 or arm64 (for aarch64) | ||
return platform.machine() | ||
|
||
|
||
def write_json_result(output_json_path, headers, row): | ||
""" | ||
Write the result into JSON format, so that it can be uploaded to the benchmark database | ||
to be displayed on OSS dashboard. The JSON format is defined at | ||
https://github.com/pytorch/pytorch/wiki/How-to-integrate-with-PyTorch-OSS-benchmark-database | ||
""" | ||
mapping_headers = {headers[i]: v for i, v in enumerate(row)} | ||
today = datetime.date.today() | ||
sha_hash = hashlib.sha256(str(today).encode("utf-8")).hexdigest() | ||
first_second = datetime.datetime.combine(today, datetime.time.min) | ||
workflow_id = int(first_second.timestamp()) | ||
job_id = workflow_id + 1 | ||
record = { | ||
"timestamp": int(time.time()), | ||
"schema_version": "v3", | ||
"name": "devvm local benchmark", | ||
"repo": "pytorch/ao", | ||
"head_branch": "main", | ||
"head_sha": sha_hash, | ||
"workflow_id": workflow_id, | ||
"run_attempt": 1, | ||
"job_id": job_id, | ||
"benchmark": { | ||
"name": "TorchAO benchmark", | ||
"mode": "inference", | ||
"dtype": mapping_headers["dtype"], | ||
"extra_info": { | ||
"device": mapping_headers["device"], | ||
"arch": mapping_headers["arch"], | ||
"min_sqnr": None, | ||
"compile": mapping_headers["compile"], | ||
}, | ||
}, | ||
"model": { | ||
"name": mapping_headers["name"], | ||
"type": "model", | ||
# TODO: make this configurable | ||
"origins": ["torchbench"], | ||
}, | ||
"metric": { | ||
"name": mapping_headers["metric"], | ||
"benchmark_values": [mapping_headers["actual"]], | ||
"target_value": mapping_headers["target"], | ||
}, | ||
} | ||
|
||
with open(f"{os.path.splitext(output_json_path)[0]}.json", "a") as f: | ||
print(json.dumps(record), file=f) | ||
|
||
def benchmark_and_write_json_result(model, args, kwargs, quantization, device, compile=True): | ||
print(quantization + " run") | ||
from torchao.utils import benchmark_model, profiler_runner | ||
if compile: | ||
model = torch.compile(model, mode="max-autotune") | ||
benchmark_model(model, 20, args, kwargs) | ||
elapsed_time = benchmark_model(model, 100, args, kwargs) | ||
print("elapsed_time: ", elapsed_time, " milliseconds") | ||
|
||
if hasattr(model, "_orig_mod"): | ||
name = model._orig_mod.__class__.__name__ | ||
else: | ||
# eager | ||
name = model.__class__.__name__ | ||
|
||
headers = ["name", "dtype", "compile", "device", "arch", "metric", "actual", "target"] | ||
arch = get_arch_name() | ||
dtype = quantization | ||
performance_result = [name, dtype, compile, device, arch, "time_ms(avg)", elapsed_time, None] | ||
_OUTPUT_JSON_PATH = "benchmark_results" | ||
write_json_result(_OUTPUT_JSON_PATH, headers, performance_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters