Abstract
As Large Language Models (LLMs) scale to hundreds of billions of parameters, memory bandwidth and storage capacity have become the primary bottlenecks for deployment. While 2-bit quantization offers a path toward extreme compression, existing methods often suffer from significant accuracy degradation or prohibitive inference latency due to "on-the-fly" dequantization overhead. This paper introduces CodeGEMM, a novel matrix multiplication (GEMM) kernel that shifts the computational paradigm from weight reconstruction to direct lookup. By utilizing a "Psumbook"—a cache of precomputed inner products stored in GPU SRAM—CodeGEMM achieves up to an 8.93× speedup on Llama-3 70B compared to current state-of-the-art methods, while maintaining high accuracy through synergy with codebook-based quantization and PV-Tuning.
Introduction
The deployment of state-of-the-art LLMs, such as Llama-3 405B, presents a massive infrastructure challenge. Storing the weights for such a model in 16-bit precision requires over 800GB of VRAM, exceeding the capacity of standard 8-GPU nodes. Quantization is the standard solution to this problem, yet it introduces a difficult trade-off: 4-bit quantization is efficient but offers limited compression, while 2-bit quantization significantly reduces memory footprint but typically results in a "quantization tax" of either lower accuracy or slower execution.
Codebook-based quantization (e.g., AQLM) has emerged as a solution for maintaining accuracy at 2-bit levels by mapping weight groups to centroids in a lookup table. However, these methods are historically slow because they rely on dequantization-based kernels. These kernels must fetch centroids from memory and reconstruct weights before performing multiplication, creating a bottleneck in memory bandwidth and cache pressure. CodeGEMM addresses this by rethinking the GEMM operation to be "codebook-centric."
Methodology: The Codebook-Centric Paradigm
CodeGEMM eliminates the need for weight reconstruction by flipping the traditional GEMM logic. Instead of dequantizing weights to multiply them by activations, CodeGEMM focuses on the relationship between the input and the codebook.
1. The Psumbook (Partial Sum Book)
The core innovation is the Psumbook. Before the main computation phase, CodeGEMM precomputes the inner products between the input activation vectors and every possible centroid in the codebook. These precomputed values are stored in the GPU's fast, programmable cache (SRAM). Because the Psumbook stores scalars rather than high-dimensional vectors, it is lightweight enough to reside in the fastest levels of the memory hierarchy.
2. Direct Retrieval and Accumulation
During the execution of the kernel, the system no longer performs standard floating-point multiplications for the weights. Instead, it uses the 2-bit codes (indices) stored in memory to directly retrieve the corresponding precomputed partial sum from the Psumbook. This value is then added to the accumulator. This process effectively replaces expensive arithmetic and memory-heavy dequantization with simple memory lookups and additions.
3. Complexity and Flexibility
Standard GEMM complexity is defined as $O(MNK)$. CodeGEMM reduces the effective computational load to approximately $O(MNK \cdot \frac{m}{v})$, where $m$ represents the number of codebooks and $v$ is the vector length. Since $m$ is typically much smaller than $v$, the actual mathematical operations required during the main loop are drastically reduced. Furthermore, the CodeGEMM implementation is unified and flexible, supporting various hyperparameters (codebook counts, vector lengths, and group sizes) within a single kernel, allowing developers to tune the latency-accuracy trade-off for specific hardware targets.
Experimental Results
The researchers evaluated CodeGEMM using the Llama-3 and Llama-3.1 model families (8B and 70B) across a variety of benchmarks, including MMLU, WikiText-2, and the lm-eval-harness suite (WinoGrande, HellaSwag, ARC).
Performance and Speedup
CodeGEMM demonstrates its greatest strengths in the "decode" phase of inference, where batch sizes are small and memory bandwidth is the limiting factor. Compared to AQLM, the previous state-of-the-art for codebook quantization, CodeGEMM delivered:
- 1.83× speedup for the Llama-3 8B model.
- 8.93× speedup for the Llama-3 70B model.
Energy and Memory Efficiency
The kernel achieved a remarkable 19.36 GFLOPS/W, nearly doubling the efficiency of AQLM-2x8 (10.18) and quadrupling that of standard FP16 cuBLAS (4.95). Memory utilization also saw a massive improvement, reaching nearly 50% utility, whereas traditional dequantization-based baselines often struggled at approximately 6%.
Accuracy Preservation
When paired with PV-Tuning (a post-quantization calibration method), CodeGEMM allows 2-bit models to achieve accuracy levels remarkably close to their uncompressed counterparts. For Llama-3 8B at approximately 2.1 bits per weight, the system achieved an average accuracy of 63.96%, vastly outperforming uniform 2-bit quantization, which collapsed to 41.65%.
Discussion and Limitations
While CodeGEMM represents a significant leap in 2-bit inference, it is currently optimized for small batch sizes ($M \le 32$). At larger batch sizes, standard cuBLAS utilizing Tensor Cores remains more efficient because CodeGEMM currently executes on standard CUDA cores. Additionally, the size of the Psumbook is limited by the GPU's shared memory; extremely large codebooks (e.g., 16-bit indices) would exceed this capacity, making 8-bit indices the current recommended maximum.
Conclusion
CodeGEMM demonstrates that by shifting from a dequantization-heavy approach to a lookup-centric approach, 2-bit LLMs can become not only viable but significantly faster and more energy-efficient than their higher-precision counterparts. This methodology paves the way for running massive models on consumer-grade hardware and suggests a future where AI-specific hardware (ASICs) could further optimize these lookup-based operations for even greater performance gains.
Summary updated