FlattenQuant: Breaking through the Inference Compute-bound for Large Language Models with Per-tensor Quantization

Yi Zhang, Fei Yang, Shuang Peng, Fangyu Wang, Aimin Pan

TL;DR

This paper introduces FlattenQuant, a novel per-tensor quantization method designed to overcome the compute-bound bottleneck in Large Language Model (LLM) inference. By strategically flattening outlier channels in tensors and then applying per-tensor quantization, FlattenQuant achieves significant speedups and memory reductions with minimal accuracy loss, enabling more efficient deployment of LLMs.

What Problem Does This Paper Address?

Large Language Models (LLMs) have achieved remarkable performance, but their deployment is hindered by high inference latency and substantial GPU memory consumption. While existing quantization techniques like GPTQ effectively reduce memory usage, they often struggle with compute-bound scenarios, especially when dealing with large batch sizes or long sequences. This is because these scenarios are dominated by matrix multiplication, and methods that rely on fine-grained quantization (like per-channel) require dequantization to FP16 for computation, negating the benefits of low-bit weights. The paper aims to address this compute-bound issue by enabling efficient low-bit computation for LLM inference.

Methods

The core innovation of FlattenQuant is its "flattening" operation. It identifies channels within activation tensors that contain outlier values (significantly larger than others). These outlier channels are then expanded, and corresponding weight channels are repeated to accommodate these values. This process effectively reduces the maximum value within the tensor, making it more amenable to per-tensor quantization without significant information loss.

The overall quantization framework involves:

  1. Channel Smoothing: A pre-processing step to relocate high-value activation data into weights, promoting more uniform distributions.
  2. Truncation Threshold Selection: Using statistical methods (like boxplots) to identify a threshold for flattening, balancing precision and resource usage.
  3. Flattening and Repeating: Applying the core FlattenQuant operation to activations and weights.
  4. Per-Tensor Quantization: Quantizing the flattened tensors to INT4 or INT8.
  5. Precision Selection: A layer-wise assessment to determine if INT4 or INT8 quantization is appropriate, using KL divergence to balance accuracy and resource consumption.

This approach allows for direct INT4/INT8 matrix multiplication using Tensor Cores, bypassing the need for dequantization and directly tackling the compute-bound problem.

Datasets

The paper evaluates FlattenQuant on the OPT model family, using five zero-shot evaluation tasks: OpenBookQA, LAMBADA, PIQA, HellaSwag, and WinoGrande. Additionally, the WikiText-2 language modeling dataset was used for evaluating algorithm settings.

Key Insights and Ideas

  • Compute-bound is the new bottleneck: As LLMs scale and batch sizes increase, inference latency shifts from being memory-bound to compute-bound, making efficient matrix multiplication crucial.
  • Per-tensor quantization is key for compute-bound: Unlike fine-grained methods that require dequantization, per-tensor quantization allows direct low-bit computation, unlocking significant speedups.
  • Outliers are the enemy of per-tensor quantization: Large outlier values in activation channels prevent effective per-tensor quantization. FlattenQuant directly tackles this by "flattening" these outliers.
  • Flattening enables efficient INT4: By making tensors flatter and more uniform, FlattenQuant paves the way for reliable INT4 quantization, which offers substantial computational gains.
  • Accuracy can be preserved: The method carefully balances flattening and quantization to minimize accuracy degradation, especially when combined with techniques like GPTQ for weight optimization.

Key Results

FlattenQuant achieves significant improvements:

  • Speedup: Up to 2x speedup compared to FP16 baselines.
  • Memory Reduction: Up to 2.3x memory reduction.
  • Quantization Ratio: Achieves nearly 50% layer quantization using INT4 for OPT models (e.g., 48.29% for OPT-66b).
  • Accuracy: Minimal accuracy loss, with the O3 setting (using INT4 and GPTQ) compensating for any degradation. For instance, on WikiText-2, the perplexity is comparable to or better than baselines.

Limitations and Future Work

  • Hardware Dependency: The method relies on hardware with Tensor Core capabilities that support INT4 data types for optimal performance.
  • Operator Fusion: For industrial deployment, further optimization through deep operator fusion (combining tensor flattening, channel repeat, and matrix multiplication into a single kernel) is suggested.
  • Model Scaling: While the paper hypothesizes comparable improvements for models beyond 100 billion parameters, this remains an area for future investigation.
  • Key-Value Cache: The current experiments did not include the key-value cache, which is a significant memory consumer in LLM inference, especially for long sequences. Future work could explore quantization strategies for this component.

Summary updated

BibTeX
@inproceedings{zhang2024flattenquant,
  author = {Yi Zhang and Fei Yang and Shuang Peng and Fangyu Wang and Aimin Pan},
  title = {{FlattenQuant: Breaking through the Inference Compute-bound for Large Language Models with Per-tensor Quantization}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2024},
}
Figure