OPTQ: A CCURATE P OST -T RAINING Q UANTIZATION FOR G ENERATIVE P RE - TRAINED T RANSFORMERS
Dan Alistarh
IST
& NeuralMagic
A BSTRACT
Generative Pre- trained Transformer
GPT models set themselves apart through breakthrough performance across complex language modelling tasks but also by their extremely high computational and storage costs.
Specifically, due to their massive size even inference for large highly-accurate GPT models may require multiple performant GPUs, which limits the usability of such models.
While there is emerging work on relieving this pressure via model compression the applica bility and performance of existing compression techniques is limited by the scale and complexity of GPT models.
In this paper we address this challenge, and propose
OPTQ
, a new one-shot weight quantization method based on approximate second-order information, that is both highly-accurate and highly-efficient.
Specifically
OPTQ can quantize GPT models with 175 billion parameters in approximately four GPU hours, reducing the bitwidth down to 3 or 4 bits per weight, with negligible accuracy degradation relative to the uncompressed baseline.
Our method more than doubles the compression gains relative to previously-proposed one-shot quantization methods, preserving accuracy, allowing us for the first time to execute an 175 billion-parameter model inside a single GPU for generative inference.
Moreover, we also show that our method can still provide reasonable accuracy in the extreme quantization regime, in which weights are quantized to 2-bit or even ternary quantization levels.
We show experimentally that these improvements can be leveraged for end-to-end inference speedups over FP16, of around 3.25x when using high-end GPUs (NVIDIA A100) and 4.5x when using more cost-effective ones (NVIDIA A6000).
The implementation is available at https github.
com/
IST-DASLab gptq .
I NTRODUCTION
Pre-trained generative models from the Transformer (Vaswani et al., 2017) family, commonly known as GPT or OPT (Radford et al., 2019; Brown et al., 2020; Zhang et al., 2022), have shown breakthrough performance for complex language modelling tasks, leading to massive academic and practical interest.
One major obstacle to their usability is computational and storage cost, which ranks among the highest for known models.
For instance, the best-performing model variants, e.g. GPT3175B, have in the order of 175 billion parameters and require tens-to-hundreds of GPU years to train (Zhang et al., 2022).
Even the simpler task of inferencing over a pre-trained model, which is our focus in this paper, is highly challenging: for instance, the parameters of GPT3-175B occupy 326GB (counting in multiples of 1024) of memory when stored in a compact float16 format.
This exceeds the capacity of even the highest-end single GPUs, and thus inference must be performed using more complex and expensive setups, such as multi-GPU deployments.
Although a standard approach to eliminating these overheads is model compression , e.g. (Hoefler et al., 2021; Gholami et al., 2021), surprisingly little is known about compressing such models for inference.
One reason is that more complex methods for low-bitwidth quantization or model pruning usually require model retraining , which is extremely expensive for billion-parameter models.
Alternatively, post-training methods (Nagel et al., 2020; Wang et al., 2020; Hubara et al., 2020;
Nahshan et al., 2021), which compress the model in one shot, without retraining, would be very appealing.
Unfortunately, the more accurate variants of such methods (Li et al., 2021; Hubara et al., 2021; Frantar et al., 2022) are complex and challenging to scale to billions of parameters (Yao et al.,
To date, only basic variants of round-to-nearest quantization (Yao et al., 2022; Dettmers et al., 2022) have been applied at the scale of GPT-175B; while this works well for low compression targets, e.g., 8-bit weights, they fail to preserve accuracy at higher rates.
It therefore remains open whether one-shot post-training quantization to higher compression rates is generally-feasible.
[Figure]
Contribution.
In this paper, we present a new post-training quantization method, called OPTQ,which is efficient enough to execute on models with hundreds of billions of parameters in at most a few hours, and precise enough to compress such models to 3 or 4 bits per parameter without significant loss of accuracy.
For illustration, OPTQ can quantize the largest publicly-available models, OPT-175B and BLOOM-176B, in approximately four GPU hours, with minimal increase in perplexity, known to be a very stringent accuracy metric.
Further, we show that our model can also provide robust results in the extreme quantization regime, in which models are quantized to 2 bits per component, or even ternary values .
On the practical side, we develop an execution harness which allows us to execute the resulting compressed models efficiently for generative tasks.
Specifically, we are able to run the compressed OPT-175B model for the first time on a single NVIDIA A100 GPU, or using only two more cost-effective NVIDIA
A6000 GPUs.
We also implement bespoke GPU kernels which are able to leverage compression for faster memory loading, resulting in speedups of ≈ 3 .
25 × when using A100 GPUs, and 4 .
5 × when using A6000 GPUs.
To our knowledge, we are the first to show that extremely accurate language models with hundreds of billions of parameters can be quantized to 3-4 bits/component: prior post-training methods only remain accurate at 8 bits (Yao et al., 2022; Dettmers et al., 2022), while prior training-based techniques have only tackled models that are smaller by one to two orders of magnitude (Wu et al., 2022).
This high degree of compression may appear natural, as these networks are overparametrized; yet, as we discuss in our detailed analysis of results, compression induces non-trivial tradeoffs between the accuracy of the language modeling (perplexity), bit-width, and the size of the original model.
We hope that our work will stimulate further research in this area, and can be a further step towards making these models available to a wider audience.
In terms of limitations, our method currently does not provide speedups for the actual multiplications, due to the lack of hardware support for mixed-precision operands (e.g. FP16 x INT4) on mainstream architectures.
Moreover, our current results do not include activation quantization, as they are not a significant bottleneck in our target scenarios; however, this can be supported using orthogonal techniques (Yao et al., 2022).
R ELATED W ORK
Quantization methods fall broadly into two categories: quantization during training, and posttraining methods.
The former quantize models during typically extensive retraining and/or finetuning, using some approximate differentiation mechanism for the rounding operation (Gholami et al., 2021; Nagel et al., 2021).
By contrast, post-training (“one-shot”)
methods quantize a pre- trained model using modest resources, typically a few thousand data samples and a few hours of computation.
Post-training approaches are particularly interesting for massive models, for which full model training or even finetuning can be expensive.
We focus on this scenario here.
Post-training Quantization.
Most post-training methods have focused on vision models.
Usually, accurate methods operate by quantizing either individual layers, or small blocks of consecutive layers.
(See Section 3 for more details.)
The AdaRound method (Nagel et al., 2020) computes a data-dependent rounding by annealing a penalty term, which encourages weights to move towards grid points corresponding to quantization levels.
BitSplit (Wang et al., 2020) constructs quantized values bit-by-bit using a squared error objective on the residual error, while AdaQuant (Hubara et al., 2021) performs direct optimization based on straight-through estimates.
BRECQ (Li et al., 2021) introduces Fisher information into the objective, and optimizes layers within a single residual block jointly.
Finally, Optimal Brain Quantization (OBQ) (Frantar et al., 2022) generalizes the classic
Optimal Brain Surgeon (OBS) second-order weight pruning framework (Hassibi et al., 1993; Singh & Alistarh, 2020; Frantar et al., 2021) to apply to quantization.
OBQ quantizes weights one-by-one, in order of quantization error, always adjusting the remaining weights.
While these approaches can produce good results for models up to ≈ 100 million parameters in a few GPU hours, scaling them to networks orders of magnitude larger is challenging.
Large-model Quantization.
With the recent open-source releases of language models like
BLOOM (Laurenc¸on et al., 2022) or OPT-175B (Zhang et al., 2022), researchers have started to develop affordable methods for compressing such giant networks for inference.
While all existing works—ZeroQuant (Yao et al., 2022), LLM.int8() (Dettmers et al., 2022), and nuQmm (Park et al., 2022)— carefully select quantization granularity, e.g., vector-wise, they ultimately just round weights to the nearest (RTN) quantization level, in order to maintain acceptable runtimes for very large models.
ZeroQuant further proposes layer-wise knowledge distillation, similar to AdaQuant, but the largest model it can apply this approach to has only 1.3 billion parameters.
At this scale,
ZeroQuant already takes ≈ 3 hours of compute; OPTQ quantizes models 100 × larger in ≈ 4 hours.
LLM.int8() observes that activation outliers in a few feature dimensions break the quantization of larger models, and proposes to fix this problem by keeping those dimensions in higher precision.
Lastly, nuQmm develops efficient GPU kernels for a specific binary-coding based quantization scheme.
Relative to this line of work, we show that a significantly more complex and accurate quantizer can be implemented efficiently at large model scale.
Specifically, OPTQ more than doubles the amount of compression relative to these prior techniques, at similar accuracy.
B ACKGROUND
Layer-Wise Quantization.
At a high level, our method follows the structure of state-of-the-art post-training quantization methods (Nagel et al., 2020; Wang et al., 2020; Hubara et al., 2021; Frantar et al., 2022), by performing quantization layer-by-layer, solving a corresponding reconstruction problem for each layer.
Concretely, let W ℓ be the weights corresponding to a linear layer ℓ and let
X ℓ denote the layer input corresponding to a small set of m data points running through the network.
Then, the objective is to find a matrix of quantized weights (cid:99) W which minimizes the squared error, relative to the full precision layer output.
Formally, this can be restated as
[Equation]
Further, similar to (Nagel et al., 2020; Li et al., 2021; Frantar et al., 2022), we assume that the quantization grid for (cid:99) W is fixed before the process, and that individual weights can move freely as in (Hubara et al., 2021; Frantar et al., 2022).
Optimal Brain Quantization.
Our approach builds on the recently-proposed Optimal Brain
Quanization (OBQ) method (Frantar et al., 2022) for solving the layer-wise quantization problem defined above, to which we perform a series of major modifications, which allow it to scale to large language models, providing more than three orders of magnitude computational speedup.
To aid understanding, we first briefly summarize the original OBQ method.
The OBQ method starts from the observation that Equation (1) can be written as the sum of the squared errors, over each row of W .
Then, OBQ handles each row w independently, quantizing one weight at a time while always updating all not-yet-quantized weights, in order to compensate for the error incurred by quantizing a single weight.
Since the corresponding objective is a quadratic, whose Hessian is H F = 2 X F X ⊤ F , where F denotes the set of remaining full-precision weights, the greedy-optimal weight to quantize next, which we denote by w q , and the corresponding optimal update of all weights in F , denoted by δ F , are given by the following formulas, where quant ( w ) rounds w to the nearest value on the quantization grid:
[Equation]
OBQ quantizes weights iteratively using these two equations, until all the weights of w are quantized.
This is done efficiently, avoiding expensive full recomputations of H − 1 , by removing the q th row and column of H , which is necessary after quantizing w q , directly in the inverse via one step of
Gaussian elimination.
Namely, the updated inverse is given by the formula
[Equation]
This method comes with a vectorized implementation, handling multiple rows of W in parallel.
Eventually, the algorithm can achieve reasonable runtimes on medium-sized models: for instance, it can fully quantize the ResNet-50 model (25M parameters) in ≈ 1 hour on a single GPU, which is roughly in line with other post-training methods achieving state-of-the-art accuracy (Frantar et al., 2022).
However, the fact that OBQ’s runtime for a d row × d col matrix W has cubic input dependency
O ( d row · d 3 col ) means that applying it to models with billions of parameters is extremely expensive.
T HE OPTQ A LGORITHM
Step 1: Arbitrary Order Insight.
As explained in the previous section, OBQ quantizes weights in greedy order, i.e. it always picks the weight which currently incurs the least additional quantization error.
Interestingly, we find that, while this quite natural strategy does indeed seem to perform very well, its improvement over quantizing the weights in arbitrary order is generally small, in particular on large, heavily-parametrized layers.
Most likely, this is because the slightly lower number of quantized weights with large individual error is balanced out by those weights being quantized towards the end of the process, when only few other unquantized weights that can be adjusted for compensation remain.
As we will now discuss, this insight that any fixed order may perform well , especially on large models, has interesting ramifications.
[Figure]
The original OBQ method quantizes rows of W independently, in a specific order defined by the corresponding errors.
By contrast, we will aim to quantize the weights of all rows in the same order , and will show that this typically yields results with a final squared error that is similar to the original solutions.
As a consequence, the set of unquantized weights F and similarly
H − 1 F is always the same for all rows (see Figure 2 for an illustration).
In more detail, the latter is due to the fact that H F depends only on the layer inputs X F , which are the same for all rows, and not on any weights.
Therefore, we have to perform the update of H − 1 F given by
Equation (3) only d col times, once per column, rather than d row · d col times, once per weight.
This reduces the overall runtime from O ( d row · d 3 col ) to O ( max { d row · d 2 col , d 3 col } ) , i.e., by a factor of min { d row , d col } .
For larger models, this difference consists of several orders of magnitude.
However, before this algorithm can actually be applied to very large models in practice, two additional major problems need to be addressed.
Step 2: Lazy Batch-Updates.
First, a direct implementation of the scheme described previously will not be fast in practice, because the algorithm has a relatively low compute-to-memory-access ratio.
For example, Equation (3) needs to update all elements of a potentially huge matrix using just a few FLOPs for each entry.
Such operations cannot properly utilize the massive compute capabilities of modern GPUs, and will be bottlenecked by the significantly lower memory bandwidth.
Fortunately, this problem can be resolved by the following observation: The final rounding decisions for column i are only affected by updates performed on this very column, and so updates to later columns are irrelevant at this point in the process.
This makes it possible to “lazily batch” updates together, thus achieving much better GPU utilization.
Concretely, we apply the algorithm to B = 128 columns at a time, keeping updates contained to those columns and the corresponding B × B block of H − 1 (see also Figure 2).
Only once a block has been fully processed, we perform global updates of the entire H − 1 and W matrices using the multi-weight versions of Equations (2) and (3) given below, with Q denoting a set of indices, and H − 1 − Q denoting the inverse matrix with the corresponding rows and columns removed:
[Equation]
Although this strategy does not reduce the theoretical amount of compute, it effectively addresses the memory-throughput bottleneck.
This provides an order of magnitude speedup for very large models in practice, making it a critical component of our algorithm.
Step 3: Cholesky Reformulation.
The final technical issue we have to address is given by numerical inaccuracies, which can become a major problem at the scale of existing models, especially when combined with the block updates discussed in the previous step.
Specifically, it can occur that the matrix H − 1 F becomes indefinite, which we notice can cause the algorithm to aggressively update the remaining weights in incorrect directions, resulting in an arbitrarily-bad quantization of the corresponding layer.
In practice, we observed that the probability of this happening increases with model size: concretely, it almost certainly occurs for at least a few layers on models that are larger than a few billion parameters.
The main issue appears to be the repeated applications of Equation (5), which accumulate various numerical errors, especially through the additional matrix inversion.
For smaller models, applying dampening, that is adding a small constant λ (we always choose 1% of the average diagonal value) to the diagonal elements of H appears to be sufficient to avoid numerical issues.
However, larger models require a more robust and general approach.
To address this, we begin by noting that the only information required from H − 1 F q , where F q denotes the set of unquantized weights when quantizing weight q , is row q , or more precisely, the elements in this row starting with the diagonal.
The consequence is that we could precompute all of these rows using a more numerically-stable method without any significant increase in memory consumption.
Indeed, the row removal via (3) for our symmetric H − 1 essentially corresponds to taking a Cholesky decomposition, except for the minor difference that the latter divides row q by ([ H − 1 F q ] qq ) 1 / 2 .
Hence, we can leverage state-of-the-art Cholesky kernels to compute all information we will need from H −upfront.
In combination with mild dampening, the resulting method is robust enough to execute on huge models without issues.
As a bonus, using a well-optimized Cholesky kernel also yields further speedup.
We detail all small changes necessary for the Cholesky version of the algorithm next.
The Full Algorithm.
Finally, we present the full pseudocode for OPTQ in Algorithm 1, including the optimizations discussed above.
Algorithm 1 Quantize W given inverse Hessian H − 1 = (2 XX ⊤ + λ I ) − 1 and blocksize B .
Q ← 0 d row ×
d col // quantized output E ← 0 d row × B // block quantization errors
H − 1 ← Cholesky ( H − 1 ) ⊤ //
Hessian inverse information for i = 0 , B, 2 B, . . .
do for j = i, . .
, i + B − 1 do Q : ,j ← quant ( W : ,j ) // quantize column
E : ,j − i ← ( W : ,j − Q : ,j ) /
[ H − 1 ] jj // quantization error
W : ,j :( i + B ) ← W : ,j :( i + B ) − E : ,j − i · H − 1 j,j :( i + B ) // update weights in block end for W : , ( i + B ): ← W : , ( i + B ): − E · H − 1 i :( i + B ) , ( i + B ): // update all remaining weights end for
E XPERIMENTAL V ALIDATION
Overview.
We begin our experiments by validating the accuracy of OPTQ relative to other accuratebut-expensive quantizers, on smaller models, for which these methods provide reasonable runtimes.
Next, we examine OPTQ’s runtime scaling for very large models.
Then, we present 3- and 4-bit quantization results for the entire BLOOM and OPT model families, evaluated via perplexity on challenging language generation tasks.
In addition, we show that our method is also stable for 2-bit quantization when the granularity is reduced to small blocks of consecutive weights.
To complement this perplexity analysis, we also evaluate the resulting quantized models on a series of standard zeroshot tasks.
Finally, we focus on the two largest (and interesting) openly-available models, Bloom176B and OPT-175B, where we perform a detailed evaluation on several tasks.
For these models, we also present practical improvements, namely reducing the number of GPUs required for inference as well as end-to-end speedups for generative tasks.
Setup.
We implemented OPTQ in PyTorch (Paszke et al., 2019) and worked with the HuggingFace integrations of the BLOOM (Laurenc¸on et al., 2022) and OPT (Zhang et al., 2022) model families.
We quantized all models (including the 175 billion parameter variants) using a single NVIDIA A
GPU with 80GB of memory.
Our entire OPTQ calibration data consists of 128 random 2048 token segments from the C4 dataset (Raffel et al., 2020), i.e., excerpts from randomly crawled websites, which represents generic text data.
We emphasize that this means that OPTQ does not see any task-specific data, and our results thus remain actually “zero-shot”.
We perform standard uniform per-row asymmetric quantization on the min-max grid, similar to Dettmers et al.
Additional evaluation details can be found in Appendix A.2.1.
To ensure that the entire compression procedure can be performed with significantly less GPU memory than what would be required to run the full precision model, some care must be taken.
Specifically, we always load one Transformer block, consisting of 6 layers, at a time into GPU memory and then accumulate the layer-Hessians and perform quantization.
Finally, the current block inputs are sent through the fully quantized block again to produce the new inputs for the quantization of the next block.
Hence, the quantization process operates not on the layer inputs in the full precision model but on the actual layer inputs in the already partially quantized one.
We find that this brings noticeable improvements at negligible extra cost.
Baselines.
Our primary baseline, denoted by RTN, consists of rounding all weights to the nearest quantized value on exactly the same asymmetric per-row grid that is also used for OPTQ, meaning that it corresponds precisely to the state-of-the-art weight quantization of LLM.int8().
This is currently the method of choice in all works on quantization of very large language models (Dettmers et al., 2022; Yao et al., 2022; Park et al., 2022): its runtime scales well to networks with many billions of parameters, as it simply performs direct rounding.
As we will also discuss further, more accurate methods, such as AdaRound (Nagel et al., 2020) or BRECQ (Li et al., 2021), are currently too slow for models with many billions of parameters, the main focus of this work.
Nevertheless, we also show that OPTQ is competitive with such methods for small models, while scaling to huge ones like OPT-175B as well.
Quantizing Small Models.
As a first ablation study, we compare OPTQ’s performance relative to state-of-the-art post-training quantization (PTQ) methods, on ResNet18 and ResNet50, which are standard PTQ benchmarks, in the same setup as (Frantar et al., 2022).
As can be seen in Table 1,
OPTQ performs on par at 4-bit, and slightly worse than the most accurate methods at 3-bit.
At the same time, it significantly outperforms AdaQuant, the fastest amongst prior PTQ methods.
Further, we compare against the full greedy OBQ method on two smaller language models: BERT-base (Devlin et al., 2019) and OPT-125M.
The results are shown in Appendix Table 8.
At 4 bits, both methods perform similarly, and for 3 bits, OPTQ surprisingly performs slightly better.
We suspect that this is because some of the additional heuristics used by OBQ, such as early outlier rounding, might require careful adjustments for optimal performance on non-vision models.
Overall, OPTQ appears to be competitive with state-of-the-art post-training methods for smaller models, while taking only < 1 minute rather than ≈ 1 hour.
This enables scaling to much larger models.
Runtime.
Next we measure the full model quantization time (on a single NVIDIA A100 GPU) via
OPTQ; the results are shown in Table 2.
As can be seen, OPTQ quantizes 1-3 billion parameter models in a matter of minutes and 175B ones in a few hours.
For reference, the straight-through based method ZeroQuant-LKD (Yao et al., 2022) reports a 3 hour runtime (on the same hardware) for a 1.3B model, which would linearly extrapolate to several hundred hours (a few weeks) for 175B
[Table] [Table]
models.
Adaptive rounding-based methods typically employ a lot more SGD steps and would thus be even more expensive (Nagel et al., 2020; Li et al., 2021)
Language Generation.
We begin our large-scale study by compressing the entire OPT and BLOOM model families to 3- and 4-bit.
We then evaluate those models on several language tasks including
WikiText2 (Merity et al., 2016)
(see Figure 1 as well as Tables 3 and 4), Penn Treebank (PTB) (Marcus et al., 1994) and C4 (Raffel et al., 2020) (both in Appendix A.3).
We focus on these perplexitybased tasks, as they are known to be particularly sensitive to model quantization (Yao et al., 2022).
On OPT models, OPTQ clearly outperforms RTN, by significant margins.
For example, OPTQ loses only 0.03 perplexity at 4-bit on the 175B model, while RTN drops 2.2 points, performing worse than the 10 × smaller full-precision 13B model.
At 3-bit, RTN collapses completely, while OPTQ can still maintain reasonable perplexity, in particular for larger models.
BLOOM shows a similar pattern: the gaps between methods are however usually a bit smaller, indicating that this model family might be easier to quantize.
One interesting trend (see also Figure 1) is that larger models generally (with the exception of OPT-66B 2 ) appear easier to quantize.
This is good news for practical applications, as these are the cases where compression is also the most necessary.
[Table] [Table]
175 Billion Parameter Models.
We now examine BLOOM-176B and OPT-175B, the largest dense openly-available models.
Table 5 summarizes results across Wikitext-2, PTB, C4.
We observe that, at 4 bits, OPTQ models reach only ≤ 0 .
25 lower perplexity than the full-precision versions, with a large gap to RTN results on OPT-175B. At 3-bit, RTN collapses, while OPTQ is still able to maintain good performance on most tasks, losing only 0 .
3 − 0 .
6 points for more than 5 × compression.
We note that OPTQ’s accuracy can be further improved via finer-granularity grouping (Park et al., 2022): group-size 1024 ( ≈ 0.02 extra bits) improves perplexities by about 0 .
2 on average and group-size 128 ( ≈ 0.15 extra bits) by another 0 . 1 , which is only 0 .
1 − 0 .
3 off from the uncompressed accuracy.
We note that grouping interacts very well with OPTQ, as the group parameters can be determined during the quantization process of each layer, always using the most current updated weights.
[Table]
Practical Speedups.
Finally, we study practical applications.
As an interesting use-case, we focus on the OPT-175B model: quantized to 3 bits, this model takes approximately 63GB of memory, including the embeddings and the output layer, which are kept in full FP16 precision.
Additionally, storing the complete history of keys and values for all layers, a common optimization for generation tasks, consumes another ≈ 9 GB for the maximum of 2048 tokens.
Hence, we can actually fit the entire quantized model into a single 80GB A100 GPU, which can be executed by dynamically dequantizing layers as they are required during inference (the model would not fully fit usingbits).
For reference, standard FP16 execution requires 5x80GB GPUs, and the state-of-the-art 8bit
LLM.int8() quantizer (Dettmers et al., 2022) requires 3 such GPUs.
Next, we consider language generation, one of the most appealing applications of these models, with the goal of latency reduction.
Unlike LLM.int8(), which reduces memory costs but has the same runtime as the FP16 baseline, we show that our quantized models can achieve significant speedups for this application.
For language generation, the model processes and outputs one token at-a-time, which for OPT-175B can easily take a few 100s of milliseconds per token.
Increasing the speed at which the user receives generated results is challenging, as compute is dominated by matrix-vector products.
Unlike matrix-matrix products, these are primarily limited by memory bandwidth.
We address this problem by developing a quantized-matrix full-precision-vector product kernel which performs a matrix vector product by dynamically dequantizing weights when needed.
Most notably, this does not require any activation quantization.
While dequantization consumes extra compute, the kernel has to access a lot less memory, leading to significant speedups, as shown in Table 6.
We note that almost all of the speedup is due to our kernels, as communication costs are negligible in our standard HuggingFace-accelerate-like setting (see Appendix A.2.2 for details).
[Table]
For example, using our kernels, the 3-bit OPT-175B model obtained via OPTQ running on a single
A100 is about 3 .
25 × faster than the FP16 version (running on 5 GPUs) in terms of average time per token.
More accessible GPUs, such as the NVIDIA A6000, have much lower memory bandwidth, so this strategy is even more effective: executing the 3-bit OPT-175B model on 2x A6000 GPUs reduces latency from 589 milliseconds for FP16 inference (on 8 GPUs) to 130 milliseconds, a 4 . 5 × latency reduction.
Zero-Shot Tasks.
While our focus is on language generation, we also evaluate the performance of quantized models on some popular zero-shot tasks, namely LAMBADA (Paperno et al., 2016),
ARC (Easy and Challenge) (Boratko et al., 2018) and PIQA (Tata & Patel, 2003).
Figure 3 visualizes model performance on LAMBADA (and see also “Lamb.”
results in Table 5).
We observe similar behavior as before: the outliers are that 1) quantization appears “easier” across the whole spectrum of models at 4-bit, where even RTN performs relatively well, and 2) at 3-bit, RTN breaks down, while OPTQ still provides good accuracy.
We provide additional results in Appendix A.4.
[Figure]
Additional Tricks.
While our experiments so far have focused exclusively on vanilla row-wise quantization, we want to emphasize that OPTQ is compatible with essentially any choice of quantization grid .
For example, it is easily combined with standard grouping (Alistarh et al., 2017; Park et al., 2022),
i
[Figure]
e. applying independent quantization to groups of g consecutive weights.
As shown in the last rows of Table 5, this can bring noticeable extra accuracy for the largest models at 3-bit.
Further, as visualized in Figure 4, it significantly reduces the accuracy losses for medium sized models at 4-bit precision
[Figure] [Figure]
Extreme Quantization.
Lastly, grouping also makes it possible to achieve reasonable performance for extreme quantization, to around 2-bits per component on average.
Table 7 shows results on
WikiText2 when quantizing the biggest models to 2-bit with varying group-sizes.
At ≈ 2 . 2 bit (group-size 128; using FP16 scale and 2-bit zero point per group) the perplexity increase is already less than 1.5 points, while dropping to 0.6 - 0.7 at ≈ 2 . 6 bit (group-size 32), which is only slightly worse than vanilla 3-bit and might be interesting for practical kernel implementations.
Further, if we reduce group size to 8, we can apply ternary (-1, 0, +1) quantization, which achieves 9.
WikiText2 PPL on OPT-175B, a less than 1 point drop.
While this leads to worse compression on average relative to the 2-bit numbers above, this pattern could be efficiently implemented on custom hardware such as FPGAs.
In summary, these results are an encouraging first step towards pushing highly-accurate one-shot compression of very large language models, even lower than 3 bits per value on average.
S UMMARY AND L IMITATIONS
We have presented OPTQ, an approximate second-order method for quantizing truly large language models.
OPTQ can accurately compress some of the largest publicly-available models down toand 4 bits, which leads to significant usability improvements, and to end-to-end speedups, at low accuracy loss.
We hope that our method will make these models accessible to more researchers and practitioners.
At the same time, we emphasize some significant limitations: On the technical side, our method obtains speedups from reduced memory movement, and does not lead to computational reductions.
In addition, our study focuses on generative tasks, and does not consider activation quantization.
These are natural directions for future work, and we believe this can be achieved with carefully-designed GPU kernels and existing techniques (Yao et al., 2022; Wu et al., 2022).
A CKNOWLEDGMENTS
Elias Frantar and Dan Alistarh gratefully acknowledge funding from the European Research Council (ERC) under the European Union’s Horizon 2020 programme (grant agreement No.
ScaleML), as well as experimental support from Eldar Kurtic, and from the IST Austria IT department, in particular Stefano Elefante, Andrei Hornoiu, and Alois Schloegl.
The work of Saleh
Ashkboos and Torsten Hoefler was supported by the PASC DaCeMI project, received EuroHPC-JU funding under grant MAELSTROM, No. 955513.
We thank the Swiss National Supercomputing
Center (CSCS) for supporting us with compute infrastructure.
E THICS S TATEMENT
Our work introduces a general method for compressing large language models (LLMs) via quantization, with little-to-no accuracy loss in terms of standard accuracy metrics such as perplexity.
Our method is task-agnostic, as it only uses a tiny amount of randomly-chosen data for calibration.
We therefore do not foresee any significant ethical implications arising directly from the technical details of our method.
However, one possible consideration is that our study focused on “leading accuracy” metrics that are standard in the literature, such as perplexity, which is essentially standard in the literature (Dettmers et al., 2022; Yao et al., 2022).
We believe a thorough study of the impact of compression upon secondary measures, and in particular bias effects (Bender et al., 2021) is warranted, and may be rendered easier through our work.
At the same time, our work makes inference on extremely large language models more accessible, for better or for worse.
We believe that, in time, such tools will become much easier to use and deploy, making the need to understand their power and limitations even more stringent.
R EPRODUCIBILITY S TATEMENT
In the Supplementary Materials, we provide code to reproduce all experiments in this paper.
More specifically, this includes:
• Compressing all models from the OPT and BLOOM model families to 2/3/4 bits.
• Evaluating perplexity of the quantized models.
• Our 3-bit CUDA kernel together with compressed inference benchmarking features.
• Code for the ZeroShot experiments.
• A README file providing sample commands and information on how to run all scripts.
A A PPENDIX A. A DDITIONAL C OMPARISON WITH OBQ
We now provide an additional comparison between OPTQ and OBQ on BERT-base/SQuAD Rajpurkar et al.
(2016) and OPT-125M/WikiText2, which is one of the largest models to which OBQ can be reasonably applied.
[Table]
A. E XPERIMENT D ETAILS
This section provides additional details about our experiment setup, in particular regarding the model evaluation and the setup of our timing experiments
. A.2. E VALUATION
For language generation experiments, we calculate the perplexity, in standard fashion like Radford et al.
(2019), as follows:
First, the entire validation set is concatenated using two linebreaks as separators and encoded using the default HuggingFace tokenizer of each model.
Next, the sequence is split into non-overlapping segments of width 2048, the full context size of our models.
These are sent through the model to collect the log-probabilities corresponding to the next token each.
Their exponentiated average is the final perplexity we report.
For zero-shot tasks we follow the EleutherAI evaluation harness 3 in terms of data preprocessing and final score calculation.
We note that we evaluate all individual samples separately and thus do not apply any padding.
A.2. T IMING E XPERIMENT S ETUP
Our timing experiments are performed following the standard HuggingFace/accelerate 4 setup also used by the recent work LLM.int8() (Dettmers et al., 2022).
In this setting, the model is split by distributing chunks of consecutive layers across GPUs.
Importantly, in this setup the communication costs are minimal, < 5% of the total runtime even when working with 8 GPUs.
This means almost all of the reported speedups are due to our quantized-matrix full-precision vector product kernels.
We emphasize that the only difference between the FP16 baseline and our quantized models are the kernels used to perform the underlying matrix-vector products.
This means all overheads due to HuggingFace, attention or non-quantized operations like residuals or LayerNorms are exactly the same.
Consequently, our quantized models should benefit from more advanced distribution strategies (Zheng et al., 2022) or more efficient attention kernels (Dao et al., 2022) just as much as our baseline.
In general, our kernels target generative inference in the low batch-size setting (for simplicity, we consider only batchsize 1) where the underlying (close to) matrix-vector products are memorybound.
For non-generative and large-batch applications, operations may be compute- rather than memory-bound and our kernels thus not directly applicable.
Instead, one could simply decompress the matrix before performing the corresponding matrix-matrix calculations: this takes < 1.5ms on an A100 and < 3ms on an A6000 compared to 76ms/365ms for the subsequent OPT-175B FC2 layer computation with batchsize 16 × 1024 tokens.
Hence, for such applications our methods significantly reduce the required number of GPUs at very little computational overhead.
This is similar to recent work (Dettmers et al., 2022), but we achieve a 2 .
5 × higher compression rate.
A. A DDITIONAL L ANGUAGE G ENERATION R ESULTS
Tables 9, 10, 11 and 12 show additional results for language generation tasks.
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table]
A. A DDITIONAL Z ERO S HOT R ESULTS
This section contains additional results for zero-shot tasks.
[Table] [Table]
[Table] [Table]
RTN 61.
OPTQ 61.
RTN 56.
OPTQ 59.
BLOOM
Bits 560M 1.1B 1.7B 3B 7.1B
176B full 65.
RTN 63.
OPTQ 64.
RTN 58.
OPTQ 61.
OPT
Bits 125M 350M 1.3B 2.7B 6.7B 13B 30B 66B 175B full 39.
RTN 36.
OPTQ 39.
RTN 30.
OPTQ 36.
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table] [Table] [Table] [Table]
[Table] [Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
OPTQ
[Table]