FlexQuant: A Flexible and Efficient Dynamic Precision Switching Framework for LLM Quantization

Fangxin Liu, Zongwu Wang, JinHong Xia, Junping Zhao, Jian Liu, Haibing Guan, Li Jiang · DOI

TL;DR

This paper introduces FlexQuant, a novel framework that dynamically adjusts the precision of LLM weights during inference. By leveraging perplexity entropy and KL divergence, FlexQuant achieves a 1.3x speedup on long-context generation tasks with negligible accuracy loss, addressing the critical memory bottleneck in LLMs.

What Problem Does This Paper Address?

Large Language Models (LLMs) have become incredibly powerful, but their massive size creates a significant memory bottleneck. As LLMs grow exponentially, they outpace the development of memory hardware, making deployment challenging and expensive. While quantization techniques can reduce memory usage, existing methods often use static precision (e.g., always 8-bit or 4-bit) throughout inference. This is suboptimal because the model's precision requirements change dynamically during the generation process. For instance, early in generation, higher precision might be needed for accuracy, while later stages can tolerate lower precision without significant performance degradation. This static approach fails to strike the optimal balance between speed and accuracy across the entire inference pipeline.

Methods

FlexQuant tackles this problem by introducing a dynamic, token-wise precision switching mechanism. The core ideas are:

  • Perplexity Entropy (PPLE) for Precision Guidance: The paper proposes using perplexity entropy as a proxy for the model's "fault tolerance" or confidence in its predictions. As more tokens are generated, the PPLE tends to decrease, indicating that the model is becoming more confident and can potentially tolerate lower precision.
  • KL Divergence for Layer-wise Switching: To determine which layers to switch to lower precision, FlexQuant uses Kullback-Leibler (KL) divergence. By analyzing the KL divergence between original and quantized weights offline, the framework identifies layers that are less sensitive to precision changes. This allows for fine-grained, layer-specific quantization adjustments.
  • Dynamic Switching Framework: During inference, FlexQuant monitors the sliding average of PPLE over a window of 20 tokens. If this average drops below a predefined threshold (determined from the prefill stage), it triggers a switch to lower precision (e.g., from INT8 to INT4) for specific layers identified by KL divergence. This process is integrated into the standard transformer inference pipeline.
  • Two-Stage Inference: The framework leverages the typical LLM inference stages:
  • Prefill Stage: Uses W8A8 quantization to efficiently process the initial prompt, taking advantage of hardware like Tensor Cores.
  • Decode Stage: Dynamically switches precision based on PPLE and KL divergence to optimize token generation.

Datasets

The paper evaluates FlexQuant on several standard LLM benchmarks:

  • CNN/DM: For news summarization.
  • DialogSum: For dialogue summarization.
  • IWSLT Fr-En: For translation.
  • LongWriter: A newly introduced benchmark for long-context generation, specifically designed to test the effectiveness of dynamic precision scheduling.

Key Insights and Ideas

  • Dynamic Precision is Key: The most significant insight is that LLM precision requirements are not static. By dynamically adapting precision based on real-time metrics like perplexity, significant performance gains can be achieved without sacrificing accuracy.
  • PPLE as a Proxy for Confidence: Using perplexity entropy as a measure of model confidence is an elegant way to guide dynamic quantization. It provides a lightweight, online metric that correlates well with the model's ability to tolerate lower precision.
  • KL Divergence for Targeted Optimization: The use of KL divergence for offline layer analysis is crucial for ensuring that precision switches are applied to the most appropriate layers, minimizing accuracy loss.
  • Long-Context Generation is the Real Test: While static quantization might perform adequately on shorter tasks, the paper highlights that long-context generation tasks are where dynamic precision scheduling truly shines, revealing the limitations of static approaches.

Key Results

  • Speedup: FlexQuant achieves up to a 1.3x end-to-end speedup on long-context generation tasks (like LongWriter) compared to baseline models.
  • Accuracy: The framework maintains negligible accuracy loss across various tasks, often matching or closely approaching INT8 performance while using lower precision. For example, on the LongWriter task, FlexQuant achieved comparable performance to INT8 models with more aggressive compression.
  • Flexibility: The precision-perplexity threshold is tunable, allowing for a controllable trade-off between compression and quality, which is a significant advantage over static methods.

Limitations and Future Work

  • KV Cache Not Quantized: The paper acknowledges that the current evaluation does not apply quantization to the KV cache. This is identified as a factor that limits the full potential of weight quantization gains, especially at longer sequence lengths where KV cache overhead becomes significant. Future work could explore quantizing the KV cache.
  • Offline KL Divergence Analysis: While effective, the KL divergence analysis is performed offline. Integrating this analysis online or developing more efficient offline methods could further enhance the framework.
  • INT4 Kernel Efficiency: The paper notes that the ExLlama-v1 INT4 kernel shows limited improvements due to additional handling overhead. Improving the efficiency of low-bit kernels is an area for future development.
  • Hard Disk Dynamic Preloading: For scenarios with extremely constrained memory, adapting a hard disk dynamic preloading mechanism is suggested to manage model weights.

Summary updated

BibTeX
@inproceedings{liu2025flexquant,
  author = {Fangxin Liu and Zongwu Wang and JinHong Xia and Junping Zhao and Jian Liu and Haibing Guan and Li Jiang},
  title = {{FlexQuant: A Flexible and Efficient Dynamic Precision Switching Framework for LLM Quantization}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
  url = {https://openreview.net/forum?id=FzhrrKtedR},
}
Figure