Abstract
Deploying Large Language Models (LLMs) is often limited by memory constraints, specifically model weights and the Key/Value (KV) cache. While weight-only quantization maintains accuracy, it offers limited memory savings. Conversely, weight-activation quantization (W4A4) significantly reduces memory but often at the cost of model intelligence due to activation outliers. WKVQuant introduces a novel post-training quantization (PTQ) framework that targets 4-bit weights and 4-bit KV cache (W4KV4) while keeping temporary activations in full precision. This approach achieves the memory efficiency of W4A4 with the accuracy of weight-only methods.
Introduction: The Memory Wall in LLM Deployment
The primary challenge in deploying LLMs like LLaMA is the "memory wall." VRAM is consumed by two main components: billions of model parameters and the KV cache, which stores previous keys and values to enable efficient auto-regressive generation. As sequence lengths and batch sizes increase, the KV cache often becomes the dominant memory bottleneck.
Existing quantization methods typically fall into two categories. Weight-only quantization (e.g., GPTQ, AWQ) preserves accuracy but neglects the KV cache. Weight-activation quantization (e.g., SmoothQuant) reduces both but suffers from accuracy degradation caused by outliers in temporary activations. WKVQuant identifies that temporary activations are short-lived and occupy minimal memory, suggesting they should remain in high precision to preserve model performance while focusing quantization efforts on weights and the KV cache.
Methodology: The W4KV4 Strategy
WKVQuant employs a "W4KV4" strategy—4-bit weights and 4-bit KV cache—utilizing three core innovations to mitigate quantization errors.
Past-Only Quantization (POQ)
In auto-regressive generation, the "current" token's Key and Value are most critical for immediate computation accuracy. POQ maintains the current token in FP16 during the forward pass and only quantizes it when it is appended to the "past" KV cache. This ensures that the most recent, and often most sensitive, information remains precise.
Two-Dimensional (2D) Quantization
The KV cache exhibits significant variance across both channels and tokens. WKVQuant addresses this with 2D-Quantization:
- Static Channel Smoothing: Aligns values across different channels to reduce inter-channel variance.
- Dynamic Token-wise Quantization: Adapts to variations between individual tokens, ensuring robust representation across long sequences.
Cross-block Reconstruction Regularization (CRR)
Standard quantization often optimizes parameters block-by-block using Mean Squared Error (MSE). CRR instead optimizes across multiple transformer blocks (typically five) and utilizes Mean Absolute Error (MAE). This broader optimization window and the use of MAE make the model significantly more resilient to outliers compared to local MSE-based methods.
Experimental Results
WKVQuant was evaluated on LLaMA and LLaMA-2 (7B and 13B) across benchmarks including WikiText2, LongBench, and various common-sense reasoning tasks.
Accuracy and Memory Efficiency
On LLaMA-2-7B, WKVQuant achieved a zero-shot average accuracy of 58.38%, nearly matching the FP16 baseline (58.30%) and vastly outperforming W4A4 methods like OmniQuant (45.45%). In terms of memory, WKVQuant (W4KV4) reduces the footprint of a LLaMA-2-13B model from 32.1 GB (FP16) to 8.0 GB, matching the efficiency of W4A4 without the performance penalty.
Long-Context Performance
Testing with the LongBench framework demonstrated that WKVQuant's 2D-quantization and POQ strategies effectively preserve model "memory" over long sequences, consistently outperforming alternative KV-cache quantization techniques.
Conclusion and Future Work
WKVQuant demonstrates that focusing quantization on weights and the KV cache—the true memory bottlenecks—yields superior results compared to full activation quantization. While the current implementation does not fully utilize INT4 tensor core acceleration for all operations due to FP16 activations, the substantial memory savings enable the deployment of larger models on consumer-grade hardware. Future research will explore scaling these techniques to 70B+ parameter models and further optimizing the PTQ process.
Summary updated