ML-Bench is a comprehensive benchmarking framework designed to evaluate machine learning models across multiple frameworks, precisions, and hardware configurations. It provides standardized performance measurements for deep learning inference workloads with support for PyTorch and ONNX Runtime.
- Multi-Framework Support: PyTorch and ONNX Runtime with automatic optimization
- Comprehensive Model Coverage: Image classification, text-to-image generation, and GPU compute operations
- Precision Testing: FP32, FP16, and mixed precision benchmarking
- Hardware Optimization: CUDA, TensorRT, and CPU execution providers
- Memory Monitoring: Real-time GPU memory usage tracking with NVML
- Automated Testing: Comprehensive benchmarking across all valid configurations
- Rich Output Formats: JSON, CSV, and human-readable summary reports
- Interactive Visualizations: Web dashboard, static reports, and CLI charts
- Extensible Architecture: Easy addition of new models and frameworks
- Installation
- Quick Start
- Supported Models
- Usage Examples
- Visualization
- Benchmark Results
- Project Structure
- Contributing
- Performance Tips
- Troubleshooting
- License
- Python 3.8+
- NVIDIA GPU (optional, for GPU benchmarks)
- CUDA 11.0+ (for GPU acceleration)
- 8GB+ RAM (16GB+ recommended for large models)
- 20GB+ disk space (for model downloads)
# Clone the repository
git clone https://github.com/your-username/ML-Bench.git
cd ML-Bench
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Set up data files (downloads models and datasets)
python setup_data.py# Test basic functionality
python benchmark.py --framework pytorch --model resnet18 --precision fp32 --batch_size 1
# Check GPU support
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"# Run all models across all use cases (comprehensive)
python3 benchmark.py
# Run all models with specific precision
python3 benchmark.py --precision fp16
# Run all models with specific batch sizes
python3 benchmark.py --batch_size 1 4# Basic ResNet-50 benchmark
python benchmark.py --framework pytorch --model resnet50 --precision fp16 --batch_size 4
# Stable Diffusion generation benchmark
python benchmark.py --usecase generation --precision fp16
# GPU compute operations benchmark
python benchmark.py --usecase compute --model gemm_ops --precision fp16# Test all models with default settings
python benchmark.py --comprehensive
# Test specific framework comprehensively
python benchmark.py --framework pytorch --comprehensive
# Test specific use case comprehensively
python benchmark.py --usecase classification --comprehensive# Fast performance overview
python benchmark.py --framework pytorch --model resnet18 --precision fp16 --batch_size 1 4 8- ResNet Family: ResNet-18, ResNet-34, ResNet-50, ResNet-101, ResNet-152
- Use Case:
classification - Precisions: FP32, FP16, Mixed
- Batch Sizes: 1, 4, 8, 16, 32+
- Stable Diffusion 1.5: High-speed image generation
- Stable Diffusion 3 Medium: Latest high-quality generation
- Use Case:
generation - Precisions: FP32, FP16, Mixed
- Memory: 4-22GB VRAM depending on model and precision
- GEMM Operations: Matrix multiplication benchmarks
- Convolution Operations: 2D convolution performance
- Memory Operations: Memory bandwidth testing
- Element-wise Operations: Point-wise computations
- Reduction Operations: Sum, mean, max operations
- Use Case:
compute
# Single model benchmark
python benchmark.py --framework pytorch --model resnet50 --precision fp16 --batch_size 4
# Multiple batch sizes
python benchmark.py --framework pytorch --model resnet50 --precision fp16 --batch_size 1 4 8 16
# Multiple precisions
python benchmark.py --framework pytorch --model resnet50 --precision fp32 fp16 mixed --batch_size 4# Image classification benchmarks
python benchmark.py --usecase classification --framework pytorch
# Text-to-image generation benchmarks
python benchmark.py --usecase generation --precision fp16
# GPU compute benchmarks
python benchmark.py --usecase compute --framework pytorch --precision fp16# Compare PyTorch vs ONNX for ResNet
python benchmark.py --framework pytorch onnx --model resnet50 --precision fp16 --batch_size 4
# Compare all frameworks for classification
python benchmark.py --usecase classification --framework pytorch onnx --comprehensive# ONNX with specific execution provider
python benchmark.py --framework onnx --model resnet50 --execution_provider TensorrtExecutionProvider
# Comprehensive benchmarking with custom output
python benchmark.py --comprehensive --output_dir custom_results/
# Memory-optimized Stable Diffusion
python benchmark.py --usecase generation --model sd15 --precision fp16 --batch_size 1ML-Bench includes powerful visualization tools to analyze benchmark results through interactive dashboards, static reports, and CLI summaries.
# Run benchmarks and launch interactive dashboard
python benchmark.py --visualize
# Generate static HTML report
python benchmark.py --visualize --viz-mode static
# Create CLI summary
python benchmark.py --visualize --viz-mode cli# Interactive web dashboard (recommended)
python visualize.py
# CLI analysis
python visualize.py --mode cli
# Static HTML report
python visualize.py --mode static- π Interactive Dashboard: Real-time filtering, interactive charts, data export
- π Performance Analysis: Throughput, latency, memory usage comparisons
- π₯ Framework Heatmaps: Performance matrices across models and frameworks
- β‘ Precision Impact: FP32 vs FP16 vs Mixed precision analysis
- π Batch Size Scaling: Optimal batch size identification
- πΎ Memory Analysis: VRAM usage patterns and requirements
- π― Model Radar Charts: Multi-dimensional performance comparison
See VISUALIZATION.md for complete documentation and examples.
ML-Bench generates results in multiple formats:
- JSON Files: Raw benchmark data with full metrics
- CSV Files: Tabular data for analysis and plotting
- Summary Reports: Human-readable performance summaries
- Console Output: Real-time progress and results
============================================================
BENCHMARK RESULTS SUMMARY
============================================================
Framework: PyTorch | Model: resnet50 | Precision: fp16 | Batch Size: 4
β
PASS | Inference Time: 12.34 ms | Throughput: 324.2 samples/sec
GPU Memory: 2.1 GB | Latency: 3.08 ms/sample
============================================================
STABLE DIFFUSION BENCHMARK SUMMARY
============================================================
β
Stable Diffusion 1.5: 2.34 images/sec, 3.9 GB VRAM
β
Stable Diffusion 3 Medium: 0.81 images/sec, 14.2 GB VRAM
============================================================
benchmark_results/
βββ benchmark_pytorch_resnet50_20241201_143022.json # Raw results
βββ benchmark_pytorch_resnet50_20241201_143022.csv # Tabular data
βββ benchmark_pytorch_comprehensive_summary.txt # Human-readable summary
βββ performance_comparison_20241201_143022.json # Framework comparison
ML-Bench/
βββ benchmark.py # Main benchmarking script (1,104 lines)
βββ requirements.txt # Python dependencies
βββ setup_data.py # Model and data setup
βββ README.md # This file
βββ LICENSE # Project license
β
βββ utils/ # Core utilities (194 lines total)
β βββ config.py # Model and framework configuration
β βββ logger.py # Colored logging system
β βββ results.py # Results processing and output
β βββ shared_device_utils.py # GPU memory monitoring
β βββ download.py # Model download utilities
β
βββ benchmarks/ # Benchmark implementations
β βββ pytorch/ # PyTorch benchmarks
β β βββ resnet/ # ResNet classification
β β βββ stable_diffusion/ # Stable Diffusion generation
β β βββ gpu_ops/ # GPU compute operations
β βββ onnx/ # ONNX Runtime benchmarks
β βββ resnet/ # ResNet classification
β βββ gpu_ops/ # GPU compute operations
β
βββ benchmark_results/ # Generated benchmark results
βββ data/ # Downloaded models and datasets
βββ .venv/ # Virtual environment (gitignored)
benchmark.py: Main orchestrator handling test execution and result aggregationutils/config.py: Central configuration for models, frameworks, and simple VRAM checkingutils/results.py: Comprehensive result processing and output generationbenchmarks/{framework}/: Framework-specific benchmark implementations
We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes and test thoroughly
- Submit a pull request with a clear description
- Create benchmark script:
benchmarks/{framework}/{model_family}/{mode}/{usecase}/main.py - Update configuration: Add model to
utils/config.py - Follow existing patterns for argument parsing and output formatting
- Test with the main framework:
python benchmark.py --model your_model
- Use FP16 precision on CUDA GPUs for optimal speed/memory balance
- Enable TensorRT for ONNX models:
--execution_provider TensorrtExecutionProvider - Optimize batch sizes based on your GPU memory capacity
- Close other applications to free GPU memory
- Use latest NVIDIA drivers and CUDA toolkit
# For large models like Stable Diffusion 3
python benchmark.py --usecase generation --model sd3 --precision fp16 --batch_size 1
# Enable CPU offload for SD3 if needed
python benchmarks/pytorch/stable_diffusion/inference/generation/main.py --model sd3 --cpu-offload| Model Type | GPU Memory | Recommended Batch Size |
|---|---|---|
| ResNet-50 FP16 | 8GB | 16-32 |
| ResNet-50 FP32 | 8GB | 8-16 |
| Stable Diffusion 1.5 | 8GB | 1-2 |
| Stable Diffusion 3 | 16GB+ | 1 |
CUDA Out of Memory
# Reduce batch size
python benchmark.py --model resnet50 --batch_size 1
# Use FP16 precision
python benchmark.py --model resnet50 --precision fp16Model Download Failures
# Re-run setup with verbose output
python setup_data.py --verbose
# Check internet connection and disk space
df -h # Check disk spaceTensorRT Compilation Errors
# Fall back to CUDA provider
python benchmark.py --framework onnx --execution_provider CUDAExecutionProviderImport Errors
# Reinstall dependencies
pip install -r requirements.txt --force-reinstall
# Check virtual environment activation
which python # Should point to .venv/bin/python- Check existing issues
- Review troubleshooting documentation
- Open a new issue with:
- System information (
nvidia-smi,python --version) - Full error message and stack trace
- Command that caused the issue
- System information (
This project is licensed under the MIT License - see the LICENSE file for details.
- PyTorch Team for the excellent deep learning framework
- ONNX Runtime Team for high-performance inference
- Hugging Face for model hosting and diffusers library
- NVIDIA for CUDA and TensorRT optimization tools
Ready to benchmark? Start with: python3 benchmark.py for comprehensive testing across all models and use cases, or python3 benchmark.py --framework pytorch --model resnet18 --precision fp16 --batch_size 4 for specific model testing.
For more examples and advanced usage, see our documentation and examples directories.
Simple VRAM checking is enabled by default to prevent out-of-memory crashes by skipping Stable Diffusion configurations that require more VRAM than available.
- Large models (Stable Diffusion): Checked against available VRAM and skipped if insufficient
- Small models (ResNet, GPU operations): Run without VRAM checking as they use minimal memory
| Model | FP32 | FP16 | Mixed |
|---|---|---|---|
| Stable Diffusion 1.5 | 12.0GB | 6.0GB | 9.0GB |
| Stable Diffusion 3 | >24GB | 20.0GB | >24GB |
Requirements scale with batch size (each additional batch adds ~80% more VRAM)
# SD3 FP32 will be skipped automatically
python3 benchmark.py --model sd3 --precision fp32 --batch_size 1
# β οΈ SKIPPED - VRAM insufficient: Requires >24GB VRAM (available: 23.4GB)
# SD3 FP16 will run if you have enough VRAM
python3 benchmark.py --model sd3 --precision fp16 --batch_size 1
# β 1.00 samples/sec