A framework for mixed-precision quantization that automatically finds optimal bit-width allocation to minimize computational cost while preserving image quality.
Uniform quantization severely degrades image quality, while manual mixed-precision configuration is infeasible for models with hundreds of layers. QuantDiff automates this process using a three-phase approach:
- FLOPs Analysis - Profile layer-wise computational costs (BOPs)
- Sensitivity Analysis - Quantify layer sensitivity using FID and CLIP metrics
- Optimization - Allocate bits via a greedy Bang-for-Buck algorithm
Key features:
- Automated mixed-precision quantization for Stable Diffusion U-Net
- Budget-constrained optimization (control cost vs. quality tradeoff)
- Support for 4/8/16-bit precision levels
- Comprehensive sensitivity scoring (FID + CLIP metrics)
The research paper describing this methodology is available at: https://github.com/federicobrancasi/quantdiff-paper
# Clone the repository
git clone https://github.com/federicobrancasi/quantdiff.git
cd quantdiff
# Install dependencies
pip install -r requirements.txtpython main.py --eval_flops --device cudapython main.py --eval_sensitivity --device cuda --num_prompts 100python main.py --optimize_mixed_precision --budget_multiplier 0.5See the docs/ folder for detailed documentation:
- Phase 1: FLOPs Analysis
- Phase 2: Sensitivity Analysis
- Phase 3: Mixed-Precision Optimization
- Phase 4: Image Generation Experiments
- CLI Reference
- Python 3.8+
- PyTorch 2.0+
- CUDA GPU recommended (also supports CPU)
If you use this software in your research, please cite:
@software{brancasi2026quantdiff,
title={QuantDiff: Efficient Mixed-Precision Quantization for Stable Diffusion via Sensitivity-Driven Optimization},
author={Brancasi, Federico and Pierini, Maurizio and Segal, Shai and Janco, Roy and Klempner, Anat and Radiano, Eyal},
year={2026},
url={https://github.com/federicobrancasi/quantdiff}
}This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome. Please see CONTRIBUTING.md for guidelines.