Overview
Thebenchmark.py module provides comprehensive performance profiling for neural network models, measuring training time, inference latency, throughput, memory usage, CPU utilization, and energy consumption.
run_benchmarks
Runs a complete benchmark suite across multiple configurations and saves results to CSV.Parameters
List of batch sizes to benchmark, e.g.,
[16, 32, 64]List of precision modes to test, e.g.,
["float32", "float16", "int8"]List of model architectures to benchmark, e.g.,
[[784, 64, 10], [784, 128, 10]]Activation functions for each layer transition
Output CSV filename (saved to
benchmarks/ directory)Number of synthetic samples to generate for benchmarking
Number of training epochs per benchmark
Random seed for reproducible benchmarks
Enable detailed profiling reports (requires
profiler module)Returns
Path to the generated CSV file
List of benchmark result dictionaries
Example Usage
Output Format
Benchmark results are saved as CSV with the following columns:Result Fields
Random seed used for this benchmark run
Model architecture in
"AxBxC" format (e.g., "784x64x10")Precision used:
"float32", "float16", or "int8"Training batch size
Number of training epochs
Total number of training samples
Average training time per epoch in seconds (6 decimal places)
Average inference time per sample in seconds (8 decimal places)
Number of samples processed per second during inference (3 decimal places)
Peak memory usage during training in megabytes (3 decimal places)
Average CPU utilization percentage during training (3 decimal places)
Final training accuracy after all epochs (6 decimal places)
Estimated energy consumption per epoch in joules (6 decimal places)
Path to detailed profiling report (only present if
enable_profiling=True)Example CSV Output
CLI Usage
Run benchmarks from the command line:CLI Arguments
Global seed for reproducible benchmark generation
Output CSV filename (saved under
benchmarks/ directory)Default Configuration
When run from CLI, the benchmark uses these defaults:- Batch sizes:
[16, 32] - Precision modes:
["float32", "float16", "int8"] - Model sizes:
[[16, 32, 4], [16, 64, 4]] - Samples:
256 - Epochs:
1
Helper Functions
benchmark_one_setup
Runs a single benchmark configuration and returns metrics.make_synthetic_data
Generates synthetic training data for benchmarking.Number of samples to generate
Number of input features
Number of output classes
Random seed
(X, y) where X is features array and y is labels array.
measure_inference_latency_per_sample
Measures average inference time per sample.runs iterations).
measure_batch_throughput
Measures inference throughput in samples per second.measure_training_time_per_epoch
Measures average training time per epoch.(history, time_per_epoch) where history is training metrics and time_per_epoch is seconds per epoch.