-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_benchmark.py
More file actions
executable file
·106 lines (86 loc) · 3.66 KB
/
Copy pathrun_benchmark.py
File metadata and controls
executable file
·106 lines (86 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""
Script to run the benchmark and visualization process
"""
import argparse
import os
import subprocess
import sys
from datetime import datetime
def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Run benchmark and visualization process")
parser.add_argument("--original", required=True, help="Path to the original model (required)")
parser.add_argument("--quantized", required=True, help="Path to the quantized model (required)")
parser.add_argument("--device", required=True, help="Device to use for benchmarking (cpu, cuda, mps) (required)")
parser.add_argument("--max_tokens", required=True, type=int, help="Maximum number of tokens to generate (required)")
parser.add_argument("--output_dir", required=True, help="Directory to save benchmark results (required)")
parser.add_argument("--quiet", action="store_true", help="Run in quiet mode with minimal output")
parser.add_argument("--update-model-card", action="store_true", help="Update the model card with benchmark results")
return parser.parse_args()
def run_benchmark(args):
"""Run the benchmark process."""
# Create output directory
os.makedirs(args.output_dir, exist_ok=True)
# Set timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
results_file = os.path.join(args.output_dir, f"benchmark_results_{timestamp}.json")
report_dir = os.path.join(args.output_dir, f"report_{timestamp}")
print("Starting benchmark process...")
print(f"Original model: {args.original}")
print(f"Quantized model: {args.quantized}")
print(f"Device: {args.device}")
print(f"Max tokens: {args.max_tokens}")
print(f"Results file: {results_file}")
print(f"Report directory: {report_dir}")
if args.update_model_card:
print("Model card will be updated with benchmark results")
# Run benchmark
benchmark_cmd = [
"benchmark-model",
"--original", args.original,
"--quantized", args.quantized,
"--device", args.device,
"--max_new_tokens", str(args.max_tokens),
"--output", results_file
]
if args.quiet:
benchmark_cmd.append("--quiet")
print("Running benchmark in quiet mode...")
else:
print("Running benchmark...")
if args.update_model_card:
benchmark_cmd.append("--update-model-card")
benchmark_result = subprocess.run(benchmark_cmd, check=False)
if benchmark_result.returncode != 0:
print("Benchmark failed. Exiting.")
return False
print(f"Benchmark completed. Results saved to {results_file}")
# Generate visualization
print("Generating visualization report...")
visualize_cmd = [
"visualize-benchmark",
"--input", results_file,
"--output_dir", report_dir
]
visualize_result = subprocess.run(visualize_cmd, check=False)
if visualize_result.returncode != 0:
print("Visualization failed. Exiting.")
return False
report_path = os.path.join(report_dir, "benchmark_report.html")
print(f"Visualization completed. Report saved to {report_path}")
# Open the report if on macOS
if sys.platform == "darwin":
print("Opening report...")
subprocess.run(["open", report_path], check=False)
else:
print(f"Report is available at {report_path}")
print("Benchmark process completed successfully.")
return True
def main_cli():
"""Entry point for the command-line interface."""
args = parse_args()
success = run_benchmark(args)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main_cli()