LLM-FP4: 4비트 부동소수점 양자화 트랜스포머
LLM-FP4: 4-Bit Floating-Point Quantized Transformers
October 25, 2023
저자: Shih-yang Liu, Zechun Liu, Xijie Huang, Pingcheng Dong, Kwang-Ting Cheng
cs.AI
초록
우리는 대규모 언어 모델(LLM)의 가중치와 활성화를 4비트 부동소수점 값으로 양자화하는 LLM-FP4를 사후 학습 방식으로 제안한다. 기존의 사후 학습 양자화(PTQ) 솔루션은 주로 정수 기반이며 8비트 미만의 비트 폭에서 어려움을 겪는다. 정수 양자화와 비교하여 부동소수점(FP) 양자화는 더 유연하며 긴 꼬리 또는 종형 분포를 더 잘 처리할 수 있어 많은 하드웨어 플랫폼에서 기본 선택으로 부상했다. FP 양자화의 한 가지 특징은 그 성능이 지수 비트와 클리핑 범위의 선택에 크게 의존한다는 점이다. 이와 관련하여, 우리는 최적의 양자화 매개변수를 탐색함으로써 강력한 FP-PTQ 베이스라인을 구축했다. 또한, 우리는 활성화 분포에서 높은 채널 간 분산과 낮은 채널 내 분산 패턴을 관찰했으며, 이는 활성화 양자화의 어려움을 가중시킨다. 우리는 이 패턴이 LLM, BERT, Vision Transformer 모델과 같은 다양한 작업을 위해 설계된 트랜스포머 모델 전반에 걸쳐 일관되게 나타남을 확인했다. 이를 해결하기 위해, 우리는 채널별 활성화 양자화를 제안하고 이러한 추가 스케일링 인자가 가중치의 지수 편향으로 재매개변수화될 수 있음을 보여주며, 이는 무시할 수 있는 비용을 발생시킨다. 우리의 방법은 처음으로 LLaMA-13B의 가중치와 활성화를 모두 4비트로 양자화할 수 있으며, 상식적인 제로샷 추론 작업에서 평균 점수 63.1을 달성하여 전체 정밀도 모델보다 단 5.8 낮은 수치를 기록하며, 이전 최신 기술을 12.7점 크게 능가한다. 코드는 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.