TL;DR
Meta researchers introduce any4, a novel 4-bit weight quantization method for Large Language Models (LLMs) that learns the optimal numeric representation for each row of a weight matrix. By dynamically clustering weights rather than forcing them into pre-defined formats (like int4 or nf4), any4 achieves state-of-the-art accuracy without requiring complex weight pre-processing. It runs efficiently using a newly open-sourced GPU matrix multiplication library called tinygemm.
The Memory Bottleneck in LLM Inference
LLM inference is notoriously memory-bound; the speed of generating tokens is largely dictated by how fast weights can be loaded from GPU memory. To alleviate this, researchers quantize weights from 16-bit floating-point down to 4-bit formats.
However, standard 4-bit formats force weights into rigid distributions. Uniform integer quantization (int4) assumes weights are evenly spaced, which they rarely are. NormalFloat4 (nf4) assumes weights follow a perfect Gaussian distribution—a closer approximation, but still imperfect. Other state-of-the-art methods (like AWQ or GPTQ) achieve high accuracy but require complex, offline pre-processing of weights and activations to handle outliers.
The authors ask a fundamental question: Can we just learn the optimal 4-bit representation directly from the data itself, without heavy pre-processing, and still run it efficiently on hardware?
Methods: The any4 Approach
Instead of using a fixed data type, any4 uses a Lookup Table (LUT) approach. For a 4-bit format, there are only 16 possible values. any4 learns the optimal 16 floating-point values for every single row of a weight matrix.
- Modified K-Means Clustering: To find these 16 values, the authors use a K-means clustering algorithm. Crucially, they don't just minimize the reconstruction error of the weights. They mathematically derive a modified K-means objective that minimizes the expected error of the output activations. This means the clustering is weighted by the scaling factors of the weights and the expected magnitude of the input activations.
- Single-Prompt Calibration: To estimate the expected input activations, the model needs calibration data. Instead of using massive datasets, the authors hand-crafted a single, 88-word prompt covering diverse topics (fiction, news, code, math, facts).
tinygemmLibrary: A per-row LUT sounds like a nightmare for GPU memory access. To make it fast, the authors builttinygemm, a custom CUDA library. It loads the 16-entry LUT into a single GPU register and uses lightning-fast warp shuffle instructions to dequantize the 4-bit codes into floating-point values on the fly, right before matrix multiplication.
Datasets Used
- Calibration: A custom, single 88-word hand-written prompt. Ablation studies also tested WikiText-2, the Pile, and C4.
- Evaluation (Perplexity): WikiText-2, C4, Penn Treebank (PTB), and CodeParrot.
- Evaluation (Downstream Tasks): Eleuther Harness (MMLU, HellaSwag, GSM8K, BBH) and BigCode Harness (HumanEval, MBPP).
Key Insights
- Data-driven beats theoretical distributions: Learning the exact distribution of weights per row consistently outperforms fitting them to an a priori distribution like nf4. Real neural network weights are messy, and dynamic LUTs capture that messiness better.
- Less is more for calibration: One of the most surprising findings is that calibrating the model using a single, highly diverse 88-word prompt actually yielded better perplexity than calibrating on thousands of tokens from standard datasets like C4 or WikiText-2.
- Hardware-software co-design is vital: The
any4algorithm is only practical because of how it maps to hardware. By proving that a 16-value LUT can live entirely in GPU registers without hitting shared memory bank conflicts, the authors bridged the gap between theoretical compression and actual latency reduction.
Key Results
any4 consistently achieves the lowest perplexity across multiple model families (Llama 2, Llama 3, Mistral, Mixtral) and sizes (1B to 70B) compared to int4, fp4, and nf4.
- Concrete Example: On Llama 3 8B,
any4achieves a C4 perplexity of 9.40, outperforming nf4 (9.52), int4 (9.89), and fp4 (10.22). - Competitive with Heavyweights: Despite not using orthogonal pre-processing techniques,
any4remains highly competitive with (and often beats) complex algorithms like GPTQ, AWQ, and QuIP. - Speed: Using the
tinygemmlibrary on an A100 GPU,any4achieves up to a 2x speedup over standard 16-bit float inference. It matches the speed of nf4, though it is slightly slower than pure int4 (which reaches ~3x speedup) due to the LUT lookup overhead.
Limitations and Future Work
Because any4 requires a LUT lookup, its maximum hardware speedup is slightly lower than native uniform int4 quantization. Additionally, the authors note they have not yet evaluated if their novel single-prompt calibration method introduces any specific biases into the model's outputs.
Looking ahead, because any4 is an orthogonal numeric representation, it can theoretically be combined with pre-processing techniques like AWQ, GPTQ, or QuaRot (which currently use int4). The authors plan to explore these combinations to push 4-bit (and sub-4-bit) accuracy even further.
Summary updated