LiteRT Quantizer
Overview: Manages model compression, low-bit weight quantization, precision formats, and quantization transformations.
- Old Revision: v0.4.2 (Commit 96dcc54)
- New Revision: v0.9.0 (Commit 8d9c7a9)
- Repository: google-ai-edge/ai-edge-quantizer
🔹New Features
Quantization Algorithms & Recipes
- GPTQ algorithm: Added GPTQ support
- Blockwise Quantization & Scale Recovery: Implemented scale recovery and blockwise quantization in weight recovery algorithms, providing ready-to-use 4-bit and 8-bit named recipes
- 2-Bit Quantization: Added recipes and buffer packing for 2-bit model quantization
- Hadamard Transformations: Added int4 matrix multiplication Hadamard transforms, matrix caching, max_hadamard_size control, forced all Hadamard matrices of the same size to utilize single tensor, changed all inserted Hadamard matrices to float
Calibration - Profiler-Based Calibration: Added CALIBRATION_PROFILER_BASED calibration mode to Calibrator and Quantizer, enabling faster and more memory efficient XNNPACK-assisted calibration
- CalibrationInterpreter API: Added new calibration API with CalibrationInterpreter allowing to reuse inference pipeline for calibration
- Metadata: Added calibration metadata tracking
Evaluation & Validation - Introduced multi-metric model validation support
- Progress Bars & Reporting: Added progress bars and reports for quantization steps and calibration passes
Tooling & Model Formats - Command-Line Interface: Introduced the aeq.py CLI for running model quantization workflows directly from the terminal
- LiteRT-LM Integration: Added support for reading, quantizing, and writing .litertlm files, extracting serialized TFLite models, and applying recipes across TFLiteModel sections
🔹Performance & Memory Optimizations
- Zero-Copy & In-Place Operations: Removed unnecessary deep copies, replaced array copies with zero-copy array views and refactored core quantization operations to execute in-place, significantly lowering peak memory usage
- Memory-Mapped I/O (map): Replaced RAM-heavy model serialization with disk-backed memory mappings (mmap_utils) and chunk-by-chunk file writing, preventing OOM errors on large LLMs
- Immediate Memory Reclamation: Added explicit garbage collection for floating-point and intermediate quantized tensor buffers immediately after output buffer writing
- Chunked Quantization: Processed large tensors in chunks along the leading dimension to avoid generating large intermediate values
- Buffer Deduplication: Pre-computed producer/consumer ops, tracked buffer mapping IDs, and pruned empty buffers to shrink serialized file size and parsing overhead
🔹Packaging & Dependency Changes
- Updated the build and packaging system to use pyproject.toml and uv
🔹Bug Fixes
- Fixed crashes in float casting operations when encountering non-constant weights
- Prevented accidental double-quantization of input tensors
- Fixed an issue where output tensors were inadvertently rotated during fully connected op processing