Last active
June 25, 2023 09:11
-
-
Save yujiepan-work/4b3bde5d527654d892451380524612e1 to your computer and use it in GitHub Desktop.
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
import itertools | |
import subprocess | |
from argparse import Namespace | |
from dataclasses import dataclass | |
from typing import List | |
import pandas as pd | |
import re | |
@dataclass | |
class BenchmarkResult: | |
stdout: str = '' | |
stderr: str = '' | |
avg_latency: float = 0. | |
throughput: float = 0. | |
def run_benchmark(cmd): | |
with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: | |
p.wait() | |
stdout = p.stdout.read().decode() | |
stderr = p.stderr.read().decode() | |
# print(stdout) | |
# print(stderr) | |
stdout = stdout.strip() | |
avg_line = filter(None, stdout.split('\n')[-4].split()) | |
throughput_line = filter(None, stdout.split('\n')[-1].split()) | |
avg_line = list(avg_line) | |
throughput_line = list(throughput_line) | |
assert 'Average:' in avg_line and 'Throughput:' in throughput_line | |
return BenchmarkResult( | |
stdout=stdout, | |
stderr=stderr, | |
avg_latency=float(list(avg_line)[-2]), | |
throughput=float(list(throughput_line)[-2]), | |
) | |
results = [] | |
for model in ['model.onnx']: | |
print('***' * 20, model) | |
result = run_benchmark(cmd=f'benchmark_app -m {model} -niter 3 -hint latency') | |
# result = run_benchmark(cmd=f'benchmark_app -m {model} -hint throughput -t 60') | |
results.append( | |
dict( | |
model=model, | |
latency=result.avg_latency, | |
throughput=result.throughput, | |
) | |
) | |
df = pd.DataFrame(results) | |
# df.to_csv('./dgx1.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment