TL;DR
This paper introduces an automated method for selecting optimal mixed-precision (MP) configurations for neural networks during post-training quantization (PTQ). It achieves this by developing a novel sensitivity metric to estimate loss degradation and a hardware-aware approach to predict time gains, both of which are then optimized using Integer Programming to maximize performance while adhering to accuracy constraints.
What Problem Does This Paper Address?
Neural network compression techniques like quantization are crucial for deploying models on resource-constrained devices. However, aggressive quantization (reducing bit-widths) often leads to a significant drop in accuracy. Mixed Precision (MP) offers a solution by allowing different layers to use varying bit-widths. The challenge lies in automatically finding the best MP configuration that balances performance gains (speed, memory) with minimal accuracy loss, especially for complex models like Large Language Models (LLMs). Existing methods often struggle with accurately predicting performance gains and ensuring accuracy constraints are met.
Methods
The paper proposes a two-pronged approach:
- Novel Sensitivity Metric for Loss MSE: They introduce a new metric to estimate the Mean Squared Error (MSE) of the loss function due to quantization. This metric is derived from a first-order Taylor series expansion of the loss with respect to quantization errors in weights and activations. It's efficiently computed using high-precision forward and backward passes on a small calibration dataset. A key aspect is that this metric is designed to be additive across layers, simplifying its calculation and reducing memory overhead.
- Hardware-Aware Time Gain Prediction with Model Partitioning: To accurately predict performance gains, especially for inference time, they propose modeling time gain as additive across sequential sub-graphs of the model. An algorithm partitions the model's computation graph into these sub-graphs. The time gain for each sub-graph is then measured for various MP configurations using a few samples. This approach accounts for hardware-specific optimizations and dependencies that simple per-layer summation misses.
These two components are then integrated into an Integer Programming (IP) problem. The objective is to maximize a chosen performance metric (empirical time gain, theoretical time gain, or memory gain) subject to a constraint on the estimated loss MSE (derived from their sensitivity metric).
Datasets
The paper evaluates their approach on several Large Language Models (LLMs) across four tasks: HellaSwag, LAMBADA, Winogrande, and PIQA. They use a calibration dataset for sensitivity measurements and a full dataset for evaluation. Specific model sizes mentioned are Llama-3.2-1B-Instruct and Llama-3.1-8B-Instruct.
Key Insights and Ideas
- Per-layer sensitivity isn't enough for time gain: The paper highlights that simply summing per-layer time gains doesn't accurately predict the overall time gain of a model segment (like an attention block). This is because hardware accelerators and compilers can exploit parallelism and fuse operations within sub-graphs, leading to non-additive time gains at the per-layer level.
- Sequential sub-graphs are key for additive time gains: By partitioning the model into sequential sub-graphs (single-entry, single-exit blocks), the authors find that time gains are additive across these groups. This allows for more accurate prediction and optimization of inference speed.
- MSE as a proxy for accuracy: Using the Mean Squared Error (MSE) of the loss as a constraint is a practical way to manage accuracy degradation, as it's more amenable to additive modeling than direct accuracy metrics.
- IP for optimal trade-offs: Integer Programming proves to be a powerful tool for finding the optimal balance between performance gains and accuracy constraints, considering the complex interactions between layer-wise precision choices.
Key Results
- The proposed IP-ET (Empirical Time Gain) strategy consistently outperforms baseline strategies (Random and Prefix) in achieving better accuracy at comparable latency across various LLMs and tasks.
- For example, on the 8B model, IP-ET achieves accuracy loss below 0.1% at 450ms TTFT, while other strategies require ~600ms for similar accuracy, representing a ~30% speedup.
- The novel loss MSE metric and its additive property are validated, showing good correlation with measured loss MSE.
- The empirical time gain prediction based on sequential sub-graphs is also validated, demonstrating its additive nature across groups.
- The IP-based methods consistently outperform baselines, even the IP-M (Memory Gain) strategy, which only quantizes linear layers.
Limitations and Future Work
- Additivity Assumption: While the paper validates the additivity of loss MSE across layers and empirical time gain across sequential sub-graphs, these are still approximations. Complex interactions within sub-graphs or across different hardware components might introduce deviations.
- Hardware Specificity: The time gain prediction is hardware-aware, meaning the models and measurements are specific to the Intel Gaudi 2 accelerator. Adapting this to other hardware might require re-calibration.
- Future Work: The paper suggests further exploration of per-task time gains, MAC-based gains, and memory gains. They also implicitly point towards exploring more sophisticated partitioning strategies or handling non-additive effects more directly. The paper also mentions that the improvement for the 1B model was better than the 8B model because the gap between FP8 and BF16 accuracies is larger for the 1B model, suggesting that the effectiveness of MP might depend on the inherent precision gap.
Summary updated