論文解説
LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale
LLM.int8():大規模Transformerのための8-bit行列積
- 課題 大規模Transformerの行列積を8-bitにするとメモリは減りますが、6.7B以上では大きな値をもつoutlier特徴のために性能が崩れます。
- 手法 行と列ごとにスケールを分けるベクトル単位の量子化と、大きさ6.0以上のoutlier特徴次元だけを16-bitで計算する混合精度分解を組み合わせます。
- 結果 C4 perplexityでは、13BモデルのLLM.int8()(vector-wise + decomp)が12.45で、32-bitのベースライン12.45と同じです。Int8 absmax vector-wiseは16.48でベースラインより高くなります。OPTのゼロショット評価では、LLM.int8()が125Mから175Bまで16-bitと同程度の性能を保つと報告されています。
大規模モデルで8-bit量子化が崩れる地点
大規模Transformerの推論メモリは、フィードフォワードとアテンション射影層の重みがほとんどを占めます。6.7B以上のTransformerでは、この層と行列積が使用パラメータの95%と全演算の65-85%を担うため、ここを低ビットにすることがメモリ問題の中心になります。既存の8-bit量子化手法はメモリを減らしますが性能を下げ、主に350Mパラメータ以下のモデルでしか研究されてきませんでした。
この研究が狙う課題は、規模が大きくなるときに現れる体系的な大きな値の特徴です。約6.7Bパラメータから、hidden stateの特定の特徴次元に大きな値が現れ、その値がすべてのTransformerレイヤーに広がって量子化の精度を崩します。テンソル全体に1つのスケーリング定数を使うと、この大きな値1つが残りの値の表現精度を下げます。
この問題に対処するため、量子化の手順を2つに分ける方法が提案されています。1つ目は、行列積を独立した内積の連続とみなし、より多くのスケーリング定数を使うベクトル単位の量子化です。2つ目は、大きな値をもつoutlier特徴次元だけを16-bitで別に計算する混合精度分解です。この論文でLLM.int8()が扱う範囲は、推論時のInt8行列積で、対象はフィードフォワードとアテンション射影層です。
行と列にスケールを持たせるベクトル単位量子化
ベクトル単位の量子化は、行列積を独立した内積の連続として扱います。入力hidden state Xの各行には1つのスケーリング定数\(c_x \in \mathbb{R}^s\)を、重みWの各列には1つの定数\(c_w \in \mathbb{R}^o\)を置きます。そのためスケーリング定数はテンソル全体で1つにはならず、内積の単位に対応する数だけ増えます。
各値は絶対値の最大値をもとにInt8の範囲に合わせられます。1つのテンソルに対するabsmax量子化は次のように書けます。 \[ X^{i8} = \left\lfloor 127 \cdot \frac{X^{f16}}{\max_{ij}\left|X^{f16}_{ij}\right|} \right\rceil \] ここで⌊ ⌉は最も近い整数に丸める記号です。ベクトル単位では最大値を行または列ごとに計算するため、ある行の大きな値が別の行のスケールを変えることはありません。
Int8行列積の結果はInt32で計算された後、スケーリング定数の外積によって元に戻されます。逆量子化の式は次のとおりです。 \[ C^{f16} \approx \frac{1}{c_x^{f16} \otimes c_w^{f16}} \cdot C^{i32} \] したがって実際の流れは、16-bitの入力から行と列の定数を求め、値を量子化してからInt8行列積を行い、外積の定数で元に戻す順序です。この方法はoutlier次元を別に扱わないため、大きな値をもつ列は次節の分解と組み合わせる必要があります。
outlier次元を16-bitで分離する混合精度分解
ベクトル単位の量子化だけでは、大きな値をもつ列を扱いにくいです。この方法は、outlier特徴がほぼすべてのシーケンス位置で同じ特徴次元に現れるという観察に基づき、その次元だけを切り出します。分離する次元の集合Oは、大きさが閾値α以上の値を1つでももつ特徴次元として定義され、α = 6.0が性能低下をほぼなくす値として報告されています。
分解された行列積は次のように書けます。 \[ C^{f16} \approx \sum_{h \in O} X^{h}_{f16} W^{h}_{f16} + S_{f16} \cdot \sum_{h \notin O} X^{h}_{i8} W^{h}_{i8} \] Oに属する次元は16-bitで掛けて足し合わせます。Oに属さない残りの次元はInt8行列積を行った後、逆正規化項\(S_{f16}\)で元に戻します。2つの結果を足し合わせて、最終的な16-bit出力を作ります。

Figure 2 : Schematic of LLM.int8(). Given 16-bit floating-point inputs Xf 16 and weights Wf 16, the features and weights are decomposed into sub-matrices of large magnitude features and other values. The outlier feature matrices are multiplied in 16-bit. All other values are multiplied in 8-bit. We perform 8-bit vector-wise multiplication by scaling by row and column-wise absolute maximum of Cx and Cw and then quantizing the outputs to Int8. The Int32 matrix multiplication outputs Outi32 are dequantization by the outer product of the normalization constants Cx⊗ Cw. Finally, both outlier and regular outputs are accumulated in 16-bit floating point outputs.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの3ページ目から図の部分を抽出しています。分解のコストは小さく抑えられています。13B以下のTransformerでは|O| ≤ 7のため、分解による追加メモリは約0.1%です。値全体の99.9%以上が8-bitで掛けられるので、メモリ削減の大部分は維持されます。ベクトル単位の量子化とこの分解を組み合わせた方法がLLM.int8()です。
C4 perplexityで見る規模による失敗と回復
言語モデリングの検証は、C4の検証データにおけるperplexityで測定し、125Mから13Bパラメータまでの事前学習済みモデルを使います。この設定は量子化のベースラインを比べるためのものです。重要な点は、1つのモデルの結果よりも、モデル規模に応じた傾向です。
Table 1の13B列を見ると、32-bit Floatのベースラインは12.45です。Int8 absmax vector-wiseは16.48で、perplexityは低いほど良いため、この値はベースラインより劣化した結果です。Int8 zeropoint vector-wiseは13.47です。同じ13B列で、Absmax LLM.int8()(vector-wise + decomp)とZeropoint LLM.int8()(vector-wise + decomp)はどちらも12.45で、ベースラインと同じ値になっています。

Table 1 : C4 validation perplexities of quantization methods for different transformer sizes ranging from 125M to 13B parameters. We see that absmax, row-wise, zeropoint, and vector-wise quantization leads to significant performance degradation as we scale, particularly at the 13B mark where 8-bit 13B perplexity is worse than 8-bit 6.7B perplexity. If we use LLM.int8(), we recover full perplexity as we scale. Zeropoint quantization shows an advantage due to asymmetric quantization but is no longer advantageous when used with mixed-precision decomposition.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの6ページ目から図の部分を抽出しています。分解を使わない方法は、規模が大きくなると崩れます。absmax行の13B値19.08は6.7Bの14.59より高くなっています。zeropoint vector-wiseの13B値13.47も6.7Bの13.38より高く、6.7Bを超えたところで失敗が現れます。zeropointは小さい規模では非対称な分布をうまく扱えますが、表からは、分解と併用すると、その利点が消えていることが分かります。
OPTモデルのゼロショット精度の規模別傾向
perplexityとは別に、OPTモデルについてはEleutherAI language model evaluation harnessでゼロショット精度を評価します。Figure 1では、WinoGrande、HellaSwag、PIQA、LAMBADAの4つのデータセットの平均精度を、125Mから175Bまで示しています。比較対象は、16-bitのベースライン、8-bitのベースラインとして使うAbsmaxベクトル単位量子化、そしてLLM.int8()です。
Figure 1では、LLM.int8()が125Mから175Bまで16-bitと同程度を保つとされています。一方、Absmaxベクトル単位のベースラインは6.7B付近でoutlierが現れた後、規模が大きくなるにつれて低下し、ランダムに近い性能まで劣化します。この結果は、4つのデータセットの平均を1本の曲線にまとめたものです。データセットごとの数値は、本文では個別の表として示されていません。

Figure 1 : OPT model mean zeroshot accuracy for WinoGrande, HellaSwag, PIQA, and LAMBADA datasets. Shown is the 16-bit baseline, the most precise previous 8-bit quantization method as a baseline, and our new 8-bit quantization method, LLM.int8(). We can see once systematic outliers occur at a scale of 6.7B parameters, regular quan- tization methods fail, while LLM.int8() maintains 16-bit accuracy.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの2ページ目から図の部分を抽出しています。大きな値の特徴が現れる規模とperplexityとの関係
outlier特徴を見つけるため、3つの条件が設定されています。特徴次元の大きさが6.0以上であること、同じ次元が少なくとも25%のレイヤーに影響すること、少なくとも6%のシーケンス次元に現れることです。この分析はアテンション射影とフィードフォワードの拡張層を対象とし、この基準は最も小さい125Mモデルで1つのoutlierだけを見つけるように定められています。
分析の結果、6.7B付近で相転移が現れます。影響を受けるレイヤーの割合は65%から100%に増え、影響を受けるシーケンス次元の割合は35%から75%に増えます。モデルのパラメータ数を軸にとると、この変化は急に見えます。一方、C4 perplexityを軸にとると、perplexityが下がるにつれて指数的に緩やかに現れます。著者らは、この結果を、outlierの出現は単純な規模よりperplexityと関係するという解釈と結び付けています。

Figure 3 : Percentage of layers and all sequence dimensions affected by large magnitude outlier features across the transformer by (a) model size or (b) C4 perplexity. Lines are B-spline interpolations of 4 and 9 linear segments for (a) and (b). Once the phase shift occurs, outliers are present in all layers and in about 75% of all sequence dimensions. While (a) suggest a sudden phase shift in parameter size, (b) suggests a gradual exponential phase shift as perplexity decreases. The stark shift in (a) co-occurs with the sudden degradation of performance in quantization methods.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの7ページ目から図の部分を抽出しています。Figure 4では、さらに2つの点が見て取れます。最大のoutlierの中央値の大きさは、すべてのレイヤーに現れた後、急速に大きくなります。outlier特徴次元の数は、分析したすべてのモデルで、perplexityが下がるほど厳密に単調増加し、モデル規模との関係は単調ではありません。

Figure 4 : The median magnitude of the largest outlier feature in (a) indicates a sudden shift in outlier size. This appears to be the prime reason why quantization methods fail after emergence. While the number of outlier feature dimensions is only roughly proportional to model size, (b) shows that the number of outliers is strictly monotonic with respect to perplexity across all models analyzed. Lines are B-spline interpolations of 9 linear segments.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの8ページ目から図の部分を抽出しています。outlier次元の除去による影響
このアブレーション実験は、outlier次元が実際に重要かどうかを確かめます。outlier次元を0に設定したうえでアテンション射影層に入力し、得られたtop-1 softmax確率を通常のsoftmax確率と比べます。各レイヤーは独立して処理し、前の層の誤差が累積しないようにします。また、outlierを除いたhidden stateを伝播させたperplexityも併せて測定します。対照群としては、同じ数のランダムな非outlier特徴次元を取り除きます。
6.7Bパラメータ、シーケンス長2048のTransformerでは、モデル全体で約150k個のoutlier特徴が現れますが、それらは6つのhidden次元に集中しています。outlierを取り除くと、平均top-1 softmax確率は約40%から約20%に下がり、validation perplexityは600-1000%悪化します。同じ実験でランダムな7次元を取り除いた場合、top-1確率は0.02-0.3%しか下がらず、perplexityは約0.1%増加するだけです。
表4の6.7B行は、同じ除去比較で、top-1 softmax確率をoutlierありの場合35%、なしの場合13%として報告しています。本文の約40%と約20%とは値が異なります。ただし、どちらの値でも、outlierを除去すると確率が下がるという方向は同じです。

Table 4 : Summary statistics of outliers with a magnitude of at least 6 that occur in at least 25% of all layers and at least 6% of all sequence dimensions. We can see that the lower the C4 validation perplexity, the more outliers are present. Outliers are usually one-sided, and their quartiles with maximum range show that the outlier magnitude is 3-20x larger than the largest magnitude of other feature dimensions, which usually have a range of [-3.5, 3.5]. With increasing scale, outliers become more and more common in all layers of the transformer, and they occur in almost all sequence dimensions. A phase transition occurs at 6.7B parameters when the same outlier occurs in all layers in the same feature dimension for about 75% of all sequence dimensions (SDim). Despite only making up about 0.1% of all features, the outliers are essential for large softmax probabilities. The mean top-1 softmax probability shrinks by about 20% if outliers are removed. Because the outliers have mostly asymmetric distributions across the sequence dimension s, these outlier dimensions disrupt symmetric absmax quantization and favor asymmetric zeropoint quantization. This explains the results in our validation perplexity analysis. These observations appear to be universal as they occur for models trained in different software frameworks (fairseq, OpenAI, Tensorflow-mesh), and they occur in different inference frameworks (fairseq, Hugging Face Transformers). These outliers also appear robust to slight variations of the transformer architecture (rotary embeddings, embedding norm, residual scaling, different initializations).
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの17ページ目から図の部分を抽出しています。非対称分布とabsmax・zeropointの違い
行単位とベクトル単位の量子化は、hidden stateのシーケンス次元である行ごとにスケールを決めます。一方、outlierは特徴次元である列に現れます。そのため、2つの方式はoutlierをうまく扱えず、規模が大きくなるとabsmax方式は速やかに失敗します。
outlierの大部分は厳密に非対称で、片方の符号だけをもちます。zeropoint量子化は、この分布を全体の[-127, 127]の範囲に合わせられるため、Table 1では強い性能が出ています。しかし13Bでは、蓄積された量子化誤差とoutlierの大きさの急速な増加により、zeropointも失敗します。
混合精度分解を使うと、残りの分解特徴は対称になり、zeropointの利点は失われます。それでもベクトル単位は行単位より優れています。著者らは、これを、完全な予測性能には重みのより高い量子化精度が必要だという解釈と結び付けています。また、著者らは、outlierが16-bit浮動小数点での学習も不安定にしうるという仮説を提示しています。大きさ60程度の値をもつベクトルと掛け合わせるとき、16-bitの最大値65535を容易に超えうるという説明です。
メモリ削減と実行速度の条件
メモリの面では、16-bitで計算される次元は約0.1%にすぎないため、大部分の重みは8-bitのまま残ります。著者らは、BLOOM-176Bのメモリ使用量が1.96倍減ると報告しており、これは16-bit比で約50%の削減に当たると説明しています。表2は、GPUメモリを基準に、8-bitと16-bitで実行できる最大モデルをまとめたものです。たとえば、8x RTX 3090 24 GB構成では、8-bitでOPT-175B/BLOOMを、16-bitではOPT-66Bを実行対象として示しています。

Table 2 : Different hardware setups and which methods can be run in 16-bit vs. 8-bit precision. We can see that our 8-bit method makes many models accessible that were not accessible before, in particular, OPT-175B/BLOOM.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの10ページ目から図の部分を抽出しています。速度は、メモリとは別の条件で測定されています。Table 5は、GPT-3のサイズごとに、最初のhidden layerのfeed-forward行列積を16-bitのベースラインと比較しています。モデル次元12288では、LLM.int8()(vector-wise+decomp)が1.81x、量子化と逆量子化のオーバーヘッドを除いてInt8行列積だけを見たInt8 without overheadが2.29xです。モデル次元2560では、量子化オーバーヘッドを含む4行すべてが1.0xを下回っています。
本文では、175Bモデルに当たる大きな行列積で、LLM.int8()が約2倍速いと記されています。Table 5のモデル次元12288の列では、同じ手法のLLM.int8()の値が1.81xとして示されているため、2つの記述は異なる値を指すものとして一緒に読む必要があります。
BLOOM-176Bのend-to-end推論では、Table 6がbatch size 1の条件で、bfloat16のベースラインを8xA100 80GBで239、LLM.int8()を8xA100 80GBで253、4xA100 80GBで246、3xA100 80GBで247と報告しています。この値はトークンごとの生成速度をミリ秒で表したものです。著者らは、通信オーバーヘッドの大きい分散推論のため、差が小さく現れると説明しています。
適用範囲と残された課題
第一に、分析はInt8データ型に限られており、8-bit浮動小数点(FP8)は調べていません。現在のGPUとTPUがこのデータ型に対応していないためです。著者らは、Int8で得られた多くの知見がFP8にもそのまま当てはまると考えています。
第二に、モデル規模は175Bまでに限られています。175Bモデルは性能を落とさずに量子化できましたが、さらに大きい規模では、追加の創発的特性が現在の手法の妨げになる可能性があります。
第三に、アテンション関数にはInt8の乗算を使っていません。アテンション関数はパラメータを持たないため、メモリ削減の必須対象ではありませんでした。ただ、アテンションまでInt8に置き換える初期の検討では、追加の量子化手法が必要だという結果が出たと報告されています。
第四に、この結果は推論を中心としたものです。付録Eの初期学習実験では、アテンションまで8-bitに変えた設定で性能が大きく下がりました。表7の209Mモデルで、アテンションを8-bitのままにした行は2%分解でperplexity 24.33を示しており、8-bitを使わない基準行の16.74より高くなっています。

Table 7 : Initial results on small and large-scale language modeling. Doing attention in 8-bit severely degrades performance and performance cannot fully recovered with mixed-precision decomposition. While small-scale language models is close to baseline performance for both 8-bit FFN and 8-bit linear projects in the attention layers performance degrades at the large scale.
出典 · CC BY 4.0 · Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale · 論文の図を引用 · 元のPDFの19ページ目から図の部分を抽出しています。論文情報
- 著者
- Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer
- 学会・ジャーナル
- arXiv · プレプリント
- 公開日
- 2022年8月15日
- 登録日
- 2026年10月20日
- 更新日
- 2022年11月10日
- バージョン
- v2
- arXiv
- 2208.07339
- カテゴリ
- cs.LG · cs.AI
- ライセンス
- CC BY 4.0
- 掲載内容
- 論文情報・解説・論文の図
この解説は、Refivuの韓国語解説をAIで翻訳したものです。不正確な翻訳や誤りが含まれる可能性があります。論文と図の利用条件は各出典に従います。
アブストラクト
Large language models have been widely adopted but require significant GPU memory for inference. We develop a procedure for Int8 matrix multiplication for feed-forward and attention projection layers in transformers, which cut the memory needed for inference by half while retaining full precision performance. With our method, a 175B parameter 16/32-bit checkpoint can be loaded, converted to Int8, and used immediately without performance degradation. This is made possible by understanding and working around properties of highly systematic emergent features in transformer language models that dominate attention and transformer predictive performance. To cope with these features, we develop a two-part quantization procedure, LLM.int8(). We first use vector-wise quantization with separate normalization constants for each inner product in the matrix multiplication, to quantize most of the features. However, for the emergent outliers, we also include a new mixed-precision decomposition scheme, which isolates the outlier feature dimensions into a 16-bit matrix multiplication while still more than 99.9% of values are multiplied in 8-bit. Using LLM.int8(), we show empirically it is possible to perform inference in LLMs with up to 175B parameters without any performance degradation. This result makes such models much more accessible, for example making it possible to use OPT-175B/BLOOM on a single server with consumer GPUs. We open-source our software.
この論文を引用
Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer (2022). LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale. arXiv:2208.07339v2. https://arxiv.org/abs/2208.07339v2
BibTeX
@misc{dettmers2022int8,
title = {{LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale}},
author = {Tim Dettmers and Mike Lewis and Younes Belkada and Luke Zettlemoyer},
year = {2022},
eprint = {2208.07339},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2208.07339v2}
}