s6.app.cog.benchmark¶
Benchmark ONNX model inference and compare results.
Loads one or more ONNX models with onnxruntime, generates synthetic inputs matching model signatures, runs N timed inferences, and prints a side‑by‑side comparison of latency statistics.
Examples
Benchmark two models for 200 runs on CPU:
>>> python -m s6.app.cog.benchmark ./m1.onnx ./m2.onnx -n 200
- s6.app.cog.benchmark.parse_args()
Parse CLI arguments for the ONNX benchmark script.
- Returns:
Contains
models(list of paths) andnum_runs.- Return type:
argparse.Namespace
- s6.app.cog.benchmark.generate_inputs(session)
Generate random inputs that match the model’s input signatures.
Replaces dynamic axes with 1 to keep inputs concrete.
- Parameters:
session (onnxruntime.InferenceSession) – ONNXRuntime session to inspect for input metadata.
- Returns:
Mapping from input names to random arrays with compatible dtypes and shapes.
- Return type:
dict[str, np.ndarray]
- s6.app.cog.benchmark.main()
Run the benchmark and print side‑by‑side latency statistics.