Add benchmark harness: run_benchmark.py - CLI entry point
Browse files- benchmark/run_benchmark.py +112 -0
benchmark/run_benchmark.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Cortex Benchmark Harness — CLI Entry Point
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
# Quick test (10 examples, fast tasks only)
|
| 7 |
+
python -m benchmark.run_benchmark --n 10 --tasks hellaswag piqa
|
| 8 |
+
|
| 9 |
+
# Standard suite (50 examples, all tasks)
|
| 10 |
+
python -m benchmark.run_benchmark --n 50
|
| 11 |
+
|
| 12 |
+
# Full evaluation (all examples)
|
| 13 |
+
python -m benchmark.run_benchmark --n 0 --tasks hellaswag piqa arc-easy arc-challenge winogrande mmlu
|
| 14 |
+
|
| 15 |
+
# Custom model
|
| 16 |
+
python -m benchmark.run_benchmark --model meta-llama/Llama-3.2-1B --n 50
|
| 17 |
+
|
| 18 |
+
# Save results
|
| 19 |
+
python -m benchmark.run_benchmark --n 50 --output results.json
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
import argparse
|
| 23 |
+
import json
|
| 24 |
+
import sys
|
| 25 |
+
import os
|
| 26 |
+
|
| 27 |
+
# Ensure parent directory is on path for imports
|
| 28 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
parser = argparse.ArgumentParser(description="Cortex Benchmark Harness")
|
| 33 |
+
parser.add_argument(
|
| 34 |
+
"--model", type=str, default="HuggingFaceTB/SmolLM2-135M",
|
| 35 |
+
help="HuggingFace model ID to evaluate",
|
| 36 |
+
)
|
| 37 |
+
parser.add_argument(
|
| 38 |
+
"--tasks", nargs="+",
|
| 39 |
+
default=["hellaswag", "piqa", "arc-easy", "winogrande"],
|
| 40 |
+
help="Tasks to run (choices: hellaswag, piqa, arc-easy, arc-challenge, winogrande, mmlu, halueval)",
|
| 41 |
+
)
|
| 42 |
+
parser.add_argument(
|
| 43 |
+
"--n", type=int, default=50,
|
| 44 |
+
help="Number of examples per task (0 = all available)",
|
| 45 |
+
)
|
| 46 |
+
parser.add_argument(
|
| 47 |
+
"--no-memory", action="store_true",
|
| 48 |
+
help="Skip memory benchmarks (passkey, multi-hop)",
|
| 49 |
+
)
|
| 50 |
+
parser.add_argument(
|
| 51 |
+
"--passkey-lengths", nargs="+", type=int, default=[128, 256, 512],
|
| 52 |
+
help="Context lengths for passkey retrieval test",
|
| 53 |
+
)
|
| 54 |
+
parser.add_argument(
|
| 55 |
+
"--n-passkey", type=int, default=5,
|
| 56 |
+
help="Number of passkey examples per context length",
|
| 57 |
+
)
|
| 58 |
+
parser.add_argument(
|
| 59 |
+
"--device", type=str, default="auto",
|
| 60 |
+
help="Device: cuda, cpu, or auto",
|
| 61 |
+
)
|
| 62 |
+
parser.add_argument(
|
| 63 |
+
"--dtype", type=str, default="float32",
|
| 64 |
+
choices=["float32", "float16", "bfloat16"],
|
| 65 |
+
help="Model dtype",
|
| 66 |
+
)
|
| 67 |
+
parser.add_argument(
|
| 68 |
+
"--output", type=str, default=None,
|
| 69 |
+
help="Path to save JSON results",
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
args = parser.parse_args()
|
| 73 |
+
|
| 74 |
+
from benchmark.runner import BenchmarkRunner
|
| 75 |
+
|
| 76 |
+
runner = BenchmarkRunner(
|
| 77 |
+
model_name=args.model,
|
| 78 |
+
device=args.device,
|
| 79 |
+
dtype=args.dtype,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
n = args.n if args.n > 0 else None
|
| 83 |
+
|
| 84 |
+
results = runner.run_comparison(
|
| 85 |
+
tasks=args.tasks,
|
| 86 |
+
n=n,
|
| 87 |
+
include_memory=not args.no_memory,
|
| 88 |
+
n_passkey=args.n_passkey,
|
| 89 |
+
passkey_lengths=args.passkey_lengths,
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
BenchmarkRunner.print_summary(results)
|
| 93 |
+
|
| 94 |
+
if args.output:
|
| 95 |
+
# Filter out non-serializable items
|
| 96 |
+
def make_serializable(obj):
|
| 97 |
+
if isinstance(obj, dict):
|
| 98 |
+
return {k: make_serializable(v) for k, v in obj.items()}
|
| 99 |
+
elif isinstance(obj, list):
|
| 100 |
+
return [make_serializable(v) for v in obj]
|
| 101 |
+
elif isinstance(obj, (bool, int, float, str, type(None))):
|
| 102 |
+
return obj
|
| 103 |
+
else:
|
| 104 |
+
return str(obj)
|
| 105 |
+
|
| 106 |
+
with open(args.output, "w") as f:
|
| 107 |
+
json.dump(make_serializable(results), f, indent=2)
|
| 108 |
+
print(f"\nResults saved to {args.output}")
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
main()
|