ChatPaper.aiChatPaper

LLM-FP4: Trasformatori Quantizzati a Virgola Mobile a 4 Bit

LLM-FP4: 4-Bit Floating-Point Quantized Transformers

October 25, 2023
Autori: Shih-yang Liu, Zechun Liu, Xijie Huang, Pingcheng Dong, Kwang-Ting Cheng
cs.AI

Abstract

Proponiamo LLM-FP4 per quantizzare sia i pesi che le attivazioni nei grandi modelli linguistici (LLM) fino a valori in virgola mobile a 4 bit, in modalità post-addestramento. Le soluzioni esistenti di quantizzazione post-addestramento (PTQ) sono principalmente basate su numeri interi e faticano a gestire larghezze di bit inferiori a 8 bit. Rispetto alla quantizzazione intera, la quantizzazione in virgola mobile (FP) è più flessibile e può gestire meglio distribuzioni a coda lunga o a campana, ed è emersa come scelta predefinita in molte piattaforme hardware. Una caratteristica della quantizzazione FP è che le sue prestazioni dipendono in larga misura dalla scelta dei bit dell'esponente e dall'intervallo di clipping. A tal proposito, costruiamo una solida baseline FP-PTQ cercando i parametri di quantizzazione ottimali. Inoltre, osserviamo un modello di elevata varianza inter-canale e bassa varianza intra-canale nelle distribuzioni delle attivazioni, il quale aumenta la difficoltà della quantizzazione delle attivazioni. Riconosciamo che questo modello è coerente in una gamma di modelli transformer progettati per diverse attività, come LLM, BERT e modelli Vision Transformer. Per affrontare questo problema, proponiamo una quantizzazione delle attivazioni per canale e dimostriamo che questi fattori di scala aggiuntivi possono essere riparametrizzati come bias esponenziali dei pesi, con un costo trascurabile. Il nostro metodo, per la prima volta, può quantizzare sia i pesi che le attivazioni nel LLaMA-13B a soli 4 bit e raggiunge un punteggio medio di 63,1 nei compiti di ragionamento zero-shot di senso comune, che è solo 5,8 inferiore al modello a precisione completa, superando significativamente lo stato dell'arte precedente di 12,7 punti. Il codice è disponibile all'indirizzo: https://github.com/nbasyl/LLM-FP4.
English
We propose LLM-FP4 for quantizing both weights and activations in large language models (LLMs) down to 4-bit floating-point values, in a post-training manner. Existing post-training quantization (PTQ) solutions are primarily integer-based and struggle with bit widths below 8 bits. Compared to integer quantization, floating-point (FP) quantization is more flexible and can better handle long-tail or bell-shaped distributions, and it has emerged as a default choice in many hardware platforms. One characteristic of FP quantization is that its performance largely depends on the choice of exponent bits and clipping range. In this regard, we construct a strong FP-PTQ baseline by searching for the optimal quantization parameters. Furthermore, we observe a high inter-channel variance and low intra-channel variance pattern in activation distributions, which adds activation quantization difficulty. We recognize this pattern to be consistent across a spectrum of transformer models designed for diverse tasks, such as LLMs, BERT, and Vision Transformer models. To tackle this, we propose per-channel activation quantization and show that these additional scaling factors can be reparameterized as exponential biases of weights, incurring a negligible cost. Our method, for the first time, can quantize both weights and activations in the LLaMA-13B to only 4-bit and achieves an average score of 63.1 on the common sense zero-shot reasoning tasks, which is only 5.8 lower than the full-precision model, significantly outperforming the previous state-of-the-art by 12.7 points. Code is available at: https://github.com/nbasyl/LLM-FP4.
PDF140December 14, 2025