Quantization in Large Language Models

The landscape of artificial intelligence has been significantly transformed by the emergence of Large Language Models (LLMs). These sophisticated models, exemplified by architectures like GPT-4, Llama 2, and PaLM, have demonstrated remarkable capabilities in understanding and generating human-like text, revolutionizing various applications within natural language processing.1 Their proficiency in tasks ranging from text generation and translation to summarization has positioned them as pivotal tools in both research and industry. However, the immense size and computational demands associated with these models present substantial hurdles for their widespread adoption, particularly when considering deployment on devices with limited resources such as smartphones, laptops, and embedded systems.1 The sheer scale, with parameter counts often reaching into the billions, translates to significant memory footprints and intensive computational requirements, making efficient deployment a critical challenge.

To address these limitations, researchers and engineers have increasingly focused on model optimization techniques. Among these, quantization has emerged as a promising strategy. Quantization is a model compression technique that fundamentally alters how the numerical values representing an LLM’s parameters are stored and processed.1 Instead of relying on high-precision floating-point numbers, quantization techniques convert these values to lower-precision formats, such as integers. This reduction in precision has profound implications for the model’s size, speed, and overall efficiency.

At its core, quantization in LLMs involves converting the weights and activation values from high-precision data types, typically 32-bit floating point (FP32) or 16-bit floating point (FP16), to lower-precision data types like 8-bit integer (INT8) or even lower, such as 4-bit integer (INT4) or 2-bit.1 Model weights, which are the parameters that define the strength of connections between neurons in the network, are the primary target of quantization.7 Activation values, on the other hand, are the numerical outputs of these neurons as they process information.6 By reducing the number of bits required to represent these weights and activations, the overall size of the model can be significantly decreased.

A helpful way to understand quantization is through the analogy of image compression.7 Just as compressing an image reduces its file size by discarding some information, quantizing an LLM reduces its memory footprint by using less precise numerical representations. While this process might introduce a slight loss of detail or accuracy, the gains in efficiency often outweigh this trade-off, making it possible to deploy powerful language models in resource-constrained environments. The fundamental principle is to map a continuous range of high-precision floating-point values to a smaller, discrete set of lower-precision integer values.1

Why Quantize Large Language Models?

The application of quantization to Large Language Models is driven by a multitude of compelling reasons, all centered around enhancing their practicality and accessibility. One of the most significant benefits is the reduced memory usage. Lower precision data types inherently require fewer bits for storage, which directly translates to a smaller overall model size.1 For instance, a model whose weights are stored in 32-bit floating-point format will occupy four times the memory compared to the same model with 8-bit integer weights.1 This reduction is crucial for deploying LLMs on devices with limited RAM and storage capacity, such as mobile phones or embedded systems.

Furthermore, quantization leads to faster inference speeds. Computational operations performed on lower-precision data are generally much quicker than those on higher-precision floating-point numbers.1 This acceleration in processing time results in lower latency, meaning the LLM can generate responses to user queries more rapidly.6 This speed advantage is particularly vital for applications that demand real-time interactions, such as chatbots, voice assistants, and live translation services.

The use of lower-precision arithmetic also translates to lower computational costs. Processing fewer bits requires less computational power, which in turn reduces the energy consumption of running the model.2 This increased energy efficiency is especially important for battery-powered devices, as it helps to extend their operational lifespan. Moreover, for large-scale deployments in data centers, lower computational demands can lead to significant cost savings in terms of energy consumption and hardware requirements.

The reduced memory footprint and computational demands of quantized LLMs also contribute to enhanced scalability. Smaller models are easier to manage, distribute, and deploy across a wider range of hardware platforms, including edge devices and mobile platforms that might not have the resources to handle full-precision models efficiently.2 This broadens the potential applications of LLMs, making them accessible in scenarios where they were previously infeasible.

Finally, quantization can improve compatibility with hardware. Many hardware architectures, including older CPUs and modern consumer-grade GPUs, have optimized support for integer arithmetic.6 By converting LLMs to use lower-precision integer formats, quantization can enable these models to run more efficiently on a wider variety of hardware, without requiring specialized and expensive high-end GPUs designed primarily for floating-point computations.

In essence, quantization serves as a powerful optimization technique that addresses several key challenges associated with deploying and running large language models. By reducing model size, accelerating inference, lowering computational costs, and enhancing hardware compatibility, quantization plays a crucial role in making these advanced AI models more practical and accessible for a wide range of applications.

BenefitDescription
Reduced Memory UsageLower precision formats require fewer bits for storage, leading to smaller model sizes.
Faster Inference SpeedsOperations on lower-precision data are faster, resulting in lower latency and quicker response times.
Lower Computational CostsProcessing fewer bits requires less computational power, reducing energy consumption and operational expenses.
Enhanced ScalabilitySmaller models are easier to deploy on a wider range of hardware, including resource-constrained devices.
Improved Energy EfficiencyLower computational demands lead to less power consumption, crucial for battery-powered devices.
Hardware CompatibilityQuantized models using integer arithmetic can run efficiently on hardware optimized for such operations.

Steps Involved in Quantization

The process of quantizing an LLM typically involves a series of steps to convert the model from its original high-precision format to a lower-precision representation. While the exact steps can vary depending on the specific quantization technique and software library used, a general workflow can be outlined.7

First, a pre-trained model and its corresponding tokenizer are selected and loaded. This involves choosing an existing LLM that has already been trained on a large dataset and loading its architecture and weights, along with the tokenizer necessary for processing text input for that specific model.7

The next crucial step is the actual quantization of the model. This involves converting the model’s weights and sometimes activations to use lower-precision arithmetic. For instance, using a library like Quanto by Hugging Face, the quantize() method can be applied to convert the model to a specified lower-precision data type, such as torch.int8 for 8-bit integer quantization.7 This step often includes an implicit calibration process to determine the optimal parameters for the quantization.

Following the quantization, a freezing step is often performed. The freeze() method embeds the determined quantization parameters directly into the model. This effectively converts the weights to the target lower-precision data type. Before freezing, the weights might still appear in their original format when inspected, but after this step, they will be represented within the range of the chosen lower-precision data type.7

Finally, final checks and evaluations are conducted to verify the quantization process and assess its impact on the model. This typically includes checking the reduced model size to quantify the compression achieved and evaluating the model’s performance on relevant tasks to ensure that the quantization has not resulted in an unacceptable degradation in accuracy.3

Techniques for Quantization

There are two primary techniques employed for quantizing Large Language Models: Post-Training Quantization (PTQ) and Quantization-Aware Training (QAT).6

Post-Training Quantization (PTQ) refers to methods that quantize an LLM after it has already been fully trained.8 This approach is generally easier to implement and faster compared to QAT, as it does not require any additional training or fine-tuning of the model.4 The core idea of PTQ is to convert the pre-trained model’s weights and activations from a high-precision format (like FP32) to a lower-precision format (like INT8 or INT4).8

One common method within PTQ is affine quantization, which involves mapping the range of floating-point weight values to the integer space using a scaling factor and a zero-point.6 The scaling factor determines the step size between the quantized values, while the zero-point ensures that the floating-point value of zero is accurately represented in the integer format.1 To determine the optimal scaling factor and zero-point, a small calibration dataset is often used. This dataset is passed through the pre-trained model to observe the range of weight and activation values, which then informs the quantization parameters.6 Techniques like quantizing in blocks are also used in PTQ to mitigate the impact of outlier values in the weight distribution.8 While PTQ offers the advantages of simplicity and speed, it can sometimes lead to a reduction in model accuracy due to the inherent loss of precision during the conversion.3

In contrast, Quantization-Aware Training (QAT) integrates the weight conversion process directly into the training or fine-tuning stage of an LLM.4 During training, the model simulates the effects of quantization by converting weights and activations to lower precision but retains the ability to update weights in high precision.1 This allows the model to “be aware” of the quantization that will be applied and to adjust its weights during training to minimize the potential loss of accuracy.8 QAT typically involves steps like calibration, range estimation, clipping, and rounding of weights within the training loop.8 By accounting for quantization errors during training, QAT often results in quantized models with higher accuracy compared to PTQ techniques.4 However, QAT is generally more computationally demanding as it requires fine-tuning the model with the quantization constraints in place.6

Various techniques build upon these fundamental approaches to achieve different trade-offs between model size, inference speed, and accuracy. For example, Low-Rank Adaptation (LoRA) is a parameter-efficient fine-tuning technique that can be combined with quantization to further reduce memory requirements.8 QLoRA (Quantized Low-Rank Adaptation) takes this a step further by quantizing the original weights to 4-bit while fine-tuning a small set of additional weights.8 GPTQ (General Pre-Trained Transformer Quantization) is another popular PTQ technique that aims to reduce model size so that it can run on a single GPU, often using mixed precision like INT4 for weights and FP16 for activations.8 AWQ (Activation-Aware Weight Quantization) selectively quantizes weights based on the activations of the model, preserving the precision of the most salient weights.8

Examples of Quantized LLMs and Size Reduction

Several examples illustrate how quantization has been successfully applied to popular LLMs to reduce their size and improve efficiency.8 QLoRA, as mentioned earlier, quantizes the base LLM weights to 4-bit NormalFloat (NF4) and employs double quantization of quantization constants to 8-bit, achieving significant memory savings. For instance, double quantization alone can save 3 GB of memory in a 65B parameter LLM.8 GPTQ uses a mixed INT4/FP16 quantization, where weights are quantized to 4-bit integers while activations remain in FP16. This technique is designed to allow large models to run on a single GPU.8

Libraries like GGML and its successor GGUF are specifically designed for quantizing Llama models (and with GGUF, extending to non-Llama models) to run efficiently on CPUs.8 They utilize a k-quant system with various quantization methods employing different bit widths. Examples include q2_k which converts the largest weights to 4-bit and the rest to 2-bit, q5_0 which uses 5-bit for all weights, and q8_0 which uses 8-bit.8 The size reduction achieved depends on the specific quantization method chosen. AWQ identifies and keeps less than 1% of the weights in FP16 precision, while quantizing the remaining weights to INT3 or INT4, leading to reduced memory requirements.8

Impact of Quantization Levels on Accuracy and Latency

The impact of different quantization levels (e.g., 8-bit, 4-bit, 2-bit) on the accuracy and latency of LLMs is a critical consideration when choosing a quantization strategy.20 Generally, lower bit quantization leads to greater reductions in model size and potentially faster inference, but it can also result in a more significant drop in accuracy.

Research has shown that 8-bit quantization often allows LLMs to maintain performance comparable to their non-quantized (e.g., BFloat16) counterparts across a variety of benchmarks.12 In some cases, 8-bit quantized models have even shown slightly better performance than the baseline.20 This level of quantization provides a good balance between efficiency gains and minimal accuracy loss.

Moving down to 4-bit quantization, LLMs can still retain a significant portion of their original performance on many tasks.20 While there might be a slight decrease in accuracy compared to 8-bit quantization, the reduction in model size and potential for faster inference make it an attractive option for many applications. Techniques like GPTQ and SpQR have demonstrated promising results at this level.20

2-bit quantization represents a more extreme level of compression and typically has a more pronounced impact on accuracy.20 While some methods, like GPTQ, might lead to a substantial degradation in performance at 2 bits, other techniques, such as SpQR, which focuses on isolating and preserving outlier weights at higher precision, have shown more resilience.20 The trade-off at this level is a very significant reduction in model size, but it comes with a higher risk of accuracy loss.

The impact on latency (inference speed) can also vary with the quantization level and the specific technique used.20 While the expectation is that lower bit quantization should lead to faster inference due to reduced memory bandwidth and simpler arithmetic operations, the actual speedup can depend on hardware support and the overhead of mixed-precision computations. For instance, some implementations of 8-bit and 4-bit quantization might result in a slight slowdown compared to the original models, while others, particularly at very low bit levels or with optimized hardware, can offer significant speed improvements.12

Software Libraries and Tools for Quantization

Several software libraries and tools facilitate the quantization of LLMs, making this optimization technique more accessible to developers and researchers.19 Hugging Face’s Transformers library, along with its integration with libraries like BitsAndBytes and Quanto, provides a convenient way to quantize pre-trained models to various bit levels (e.g., 8-bit, 4-bit) using techniques like LLM.int8().7

llama.cpp is a C++ library specifically designed for efficient inference of LLMs on CPUs, and it includes extensive support for quantization in formats like GGML and GGUF.8 It offers a wide range of quantization methods, including the k-quant system with different bit widths.19 AutoAWQ is another tool focused on activation-aware weight quantization for LLMs, enabling fast and accurate low-bit (INT3/4) quantization.19

The Any-Precision LLM project provides a software solution for quantizing LLMs to varying bit-widths (e.g., 3 to 8 bits) and includes a custom CUDA kernel for efficient serving of these quantized models.22 It supports incremental upscaling for quantization and offers scripts for quantization, inference, and evaluation.

Current Research and Future Directions

Current research in LLM quantization is a dynamic field with numerous ongoing efforts and promising future directions.10 A significant area of focus is on improving Post-Training Quantization (PTQ) techniques to minimize the accuracy loss associated with direct quantization of pre-trained models.11 Methods like SmoothQuant, which aims to enable 8-bit weight and activation quantization by smoothing activation outliers, and QuIP, which leverages the properties of weight and Hessian matrices for better quantization, represent advancements in this area.11 GPTQ continues to be refined to achieve even lower bit quantization with minimal accuracy degradation.11

Research is also actively exploring Quantization-Aware Training (QAT) to achieve better accuracy retention, particularly at very low bitrates.11 Techniques like EfficientQAT, which aims to reduce memory consumption during training, and LLM-QAT, which focuses on reducing quantization errors in the Key-Value (KV) caches, are examples of this direction.11

Future directions include investigating the impact of different precision configurations for various parts of the model, exploring combinations of different PTQ and QAT methods, and developing hardware-aware quantization techniques that are tailored to specific hardware architectures.24 There is also a growing interest in quantization for different tasks beyond just text generation and in reducing the reliance on calibration data in PTQ methods.24 Furthermore, improving the efficiency of QAT and exploring novel quantization granularities are areas of ongoing and future research.

Mathematical Basis of Quantization

The mathematical basis of quantization involves mapping a continuous range of floating-point values to a discrete set of lower-precision values.1 A common approach is linear quantization, where the mapping is uniform.7 This often involves calculating a scale factor and a zero-point.1 The scale factor determines the size of the quantization step, while the zero-point ensures that the value zero in the original range is accurately represented in the quantized range.1 The formula for affine quantization, a common linear quantization scheme, is:

x_q = round(x/S + Z)

where x_q is the quantized value, x is the original floating-point value, S is the scaling factor, and Z is the zero-point.8 The scaling factor is typically calculated based on the range of the floating-point values and the number of quantization levels available in the target lower-precision format.1

In Post-Training Quantization (PTQ), calibration data plays a crucial role in determining the optimal quantization parameters.2 This is a small set of unlabeled examples used to generate layer activations in the pre-trained model.17 By passing this data through the model, statistics about the range of weight and activation values can be collected.16 These statistics are then used to calculate the scaling factors and zero-points for quantization. The choice of calibration data can significantly impact the performance of the quantized model.15 Data that is representative of the model’s training data or the intended use case generally leads to better results.15 If the calibration data is not representative, it might not adequately reflect the LLM’s broad capabilities, leading to suboptimal quantization.15

GGML (Georgi Gerganov Machine Learning) is a C-based library designed to support weight quantization of Llama models for efficient CPU inference.19 GGUF (GPT-Generated Unified Format) is a successor to GGML that extends support to non-Llama models.19 Both libraries utilize a k-quant system, which employs value representations of different bit widths depending on the chosen quantization method.19 This allows for a more nuanced approach to quantization, where different parts of the model can be quantized to different precision levels. For example, in the q2_k method, the most important weights might be quantized to 4-bit integers, while the remaining weights are quantized to 2-bit.8 Other k-quant methods like q5_0 (5-bit) and q8_0 (8-bit) use a uniform bit width across all weights.8 More recent k-quants, such as Q4_K_M, use a mixed quantization approach where some layers are quantized more than others, and bits can be shared between weights within blocks.23 I-quants (e.g., IQ4_S) represent another advancement, potentially offering better accuracy at very low bit widths but sometimes with a trade-off in CPU performance.34

Hardware Implications of Quantization

The implications of different quantization levels on hardware are significant.12 Lower bit quantization generally reduces the memory bandwidth requirements and can increase cache utilization, leading to faster inference on compatible hardware.4 For instance, quantizing to 8-bit integer format (W8A8-INT) is well-suited for server deployments on older hardware like Nvidia Ampere GPUs, offering a balance of compression and speedup.12 Quantization to 4-bit integer format with 16-bit activations (W4A16-INT) is often optimal for latency-critical applications and edge devices where model size and single-request response time are key.12 However, achieving the full benefits of very low-bit quantization (e.g., 2-bit or 3-bit) often requires specialized hardware support to efficiently perform the low-precision arithmetic operations.13 The overhead of dequantization, where weights are temporarily converted to a higher precision for computation, can also impact performance.13

Security Implications of Quantization

While quantization offers numerous benefits, it’s important to acknowledge potential security implications.35 Research has revealed that widely used quantization methods can be exploited to produce harmful quantized LLMs, even if the full-precision counterpart appears benign.35 An adversary could develop an LLM that only exhibits malicious behavior when quantized, distributing the seemingly safe full-precision version on platforms like Hugging Face.35 Users who then download and quantize the model on their local machines might inadvertently activate this malicious behavior.37 This highlights the need for careful consideration of security aspects in the development and deployment of quantized LLMs.

Takeaways

In conclusion, quantization stands as a pivotal technique in the evolution of Large Language Models. By reducing the precision of model parameters, it addresses the critical challenges of memory usage, inference speed, and computational cost, thereby enabling the deployment of these powerful models on a wider range of devices and making them more accessible for various applications. While different quantization techniques and levels offer varying trade-offs between efficiency and accuracy, ongoing research continues to push the boundaries of what is achievable, with a focus on minimizing performance degradation and enhancing hardware utilization. As LLMs continue to grow in size and complexity, quantization will undoubtedly remain a cornerstone of their optimization and a key enabler for their widespread adoption in the future.

Works cited

  1. Quantization : What Is LLM Quantization ? | by 1kg – Medium,  https://medium.com/@1kg/quantization-what-is-llm-quantization-abc54b5dd181
  2. Understanding Model Quantization in Large Language Models | DigitalOcean,  https://www.digitalocean.com/community/tutorials/model-quantization-large-language-models
  3. Top LLM Quantization Methods and Their Impact on Model Quality – Deepchecks,  https://www.deepchecks.com/top-llm-quantization-methods-impact-on-model-quality/
  4. What is Quantization in LLM – Medium,  https://medium.com/@techresearchspace/what-is-quantization-in-llm-01ba61968a51
  5. www.ibm.com,  https://www.ibm.com/think/topics/quantization#:~:text=Quantization%20is%20a%20technique%20utilized,%2Dbit%20integer%20(INT8).
  6. What is Quantization? | IBM,  https://www.ibm.com/think/topics/quantization
  7. Quantization for Large Language Models (LLMs): Reduce AI Model …,  https://www.datacamp.com/tutorial/quantization-for-large-language-models
  8. A Guide to Quantization in LLMs | Symbl.ai,  https://symbl.ai/developers/blog/a-guide-to-quantization-in-llms/
  9. Ultimate Guide to LLM Quantization for Faster, Leaner AI Models – Lamatic Labs,  https://blog.lamatic.ai/guides/llm-quantization/
  10. What Makes Quantization for Large Language Models Hard? An Empirical Study from the Lens of Perturbation – arXiv,  https://arxiv.org/html/2403.06408v1
  11. A Comprehensive Study on Quantization Techniques for Large Language Models – arXiv,  https://arxiv.org/html/2411.02530v1
  12. We ran over half a million evaluations on quantized LLMs—here’s what we found,  https://developers.redhat.com/articles/2024/10/17/we-ran-over-half-million-evaluations-quantized-llms
  13. Advances to low-bit quantization enable LLMs on edge devices – Microsoft Research,  https://www.microsoft.com/en-us/research/blog/advances-to-low-bit-quantization-enable-llms-on-edge-devices/
  14. Introduction to Large Language Models (LLMs) Quantization | by Netra Prasad Neupane,  https://netraneupane.medium.com/introduction-to-large-language-models-llms-quantization-b2217094d860
  15. Beware of Calibration Data for Pruning Large Language Models – OpenReview,  https://openreview.net/forum?id=x83w6yGIWb
  16. Quantization Aware Training (QAT) vs. Post-Training Quantization (PTQ) | by Jaideep Ray | Better ML | Medium,  https://medium.com/better-ml/quantization-aware-training-qat-vs-post-training-quantization-ptq-cd3244f43d9a
  17. On the Impact of Calibration Data in Post-training Quantization and Pruning – AIModels.fyi,  https://www.aimodels.fyi/papers/arxiv/impact-calibration-data-post-training-quantization-pruning
  18. On the Impact of Calibration Data in Post-training Quantization and Pruning – ACL Anthology,  https://aclanthology.org/2024.acl-long.544/
  19. LLMs Quantization : Tools & Techniques | by Netra Prasad Neupane | Medium,  https://netraneupane.medium.com/llms-quantization-tools-techniques-ff6ddeda8b46
  20. arxiv.org,  https://arxiv.org/abs/2402.16775
  21. A Comprehensive Evaluation of Quantization Strategies for Large Language Models – arXiv,  https://arxiv.org/html/2402.16775v1
  22. SNU-ARC/any-precision-llm: [ICML 2024 Oral] Any … – GitHub,  https://github.com/SNU-ARC/any-precision-llm
  23. Llama Quantization Methods – Akemi Izuko,  https://noway.moe/llama/quantization/
  24. arxiv.org,  https://arxiv.org/abs/2411.02530
  25. [2402.18158] Evaluating Quantized Large Language Models – arXiv,  https://arxiv.org/abs/2402.18158
  26. ICML Poster Extreme Compression of Large Language Models via Additive Quantization,  https://icml.cc/virtual/2024/poster/34964
  27. How Does Quantization Affect Multilingual LLMs? – ACL Anthology,  https://aclanthology.org/2024.findings-emnlp.935/
  28. LLMC: Benchmarking Large Language Model Quantization with a Versatile Compression Toolkit | Cool Papers,  https://papers.cool/venue/2024.emnlp-industry.12@ACL
  29. What Makes Quantization for Large Language Model Hard? An Empirical Study from the Lens of Perturbation – AAAI Publications,  https://ojs.aaai.org/index.php/AAAI/article/view/29765/31318
  30. [2411.17691] Low-Bit Quantization Favors Undertrained LLMs: Scaling Laws for Quantized LLMs with 100T Training Tokens – arXiv,  https://arxiv.org/abs/2411.17691
  31. QBB: Quantization with Binary Bases for LLMs – OpenReview,  https://openreview.net/forum?id=Kw6MRGFx0R¬eId=uiZSJSg4lN
  32. Exploring LLM Low-Bit Quantization Degradation for Mathematical Reasoning – arXiv,  https://arxiv.org/html/2501.03035v2
  33. On the Impact of Calibration Data in Post-training Quantization and Pruning – arXiv,  https://arxiv.org/html/2311.09755v2
  34. Overview of GGUF quantization methods : r/LocalLLaMA – Reddit,  https://www.reddit.com/r/LocalLLaMA/comments/1ba55rj/overview_of_gguf_quantization_methods/
  35. NeurIPS Poster Exploiting LLM Quantization,  https://neurips.cc/virtual/2024/poster/95767
  36. Exploiting LLM Quantization,  https://proceedings.neurips.cc/paper_files/paper/2024/hash/496720b3c860111b95ac8634349dcc88-Abstract-Conference.html
  37. Exploiting LLM Quantization – NIPS papers,  https://proceedings.neurips.cc/paper_files/paper/2024/file/496720b3c860111b95ac8634349dcc88-Paper-Conference.pdf
  38. Exploiting LLM Quantization – ICML 2025,  https://icml.cc/virtual/2024/37508
  39. Exploiting LLM Quantization | OpenReview,  https://openreview.net/forum?id=ISa7mMe7Vg&referrer=%5Bthe%20profile%20of%20Jingxuan%20He%5D(%2Fprofile%3Fid%3D~Jingxuan_He1)
Share this article