Zero Labs
Industry News / AI

LLM Quantization Explained: How Do We Make Large Language Models Smaller and More Efficient?

Source · Towards AI By Dibika Dahal

From the publisher’s feed, collected in the ZeroLabs newsroom.

Understanding how quantization works, why it matters, and how it helps us run large language models on devices with limited resources.Have you ever wondered why some AI tools run smoothly on your phone or laptop, while others need powerful, expensive computers just to work? Imagine downloading an AI assistant, excited to try it out, only to discover that your device isn’t powerful enough to run it. Now, what if I told you that the same AI could be made almost eight times smaller, without necessarily losing much of what makes it useful? No need to completely rebuild it or teach it everything from scratch. Just a clever change in how it stores information. Sounds interesting, right? This is where quantization comes into the picture, and the idea behind it is surprisingly simple.1. Why Do We Need Quantization?Consider a language model with 7 billion parameters. If each parameter is stored using 32-bit floating-point numbers (FP32), the model’s weights alone require approximately 28 GB of memory. That is a substantial amount of memory, even before accounting for other requirements such as activations and temporary computations. Storing the same weights using 16-bit numbers (FP16) reduces this to approximately 14 GB. With 8-bit integers, the requirement falls to around 7 GB, and with 4-bit integers, it can be approximately 3.5 GB.This is where quantization becomes useful. Instead of storing every model parameter using a relatively large numerical representation, quantization represents those values using fewer bits. The goal is to reduce memory requirements and, where the hardware and software support it, improve computational efficiency without significantly affecting the model’s ability to produce useful answers.This is particularly important for edge AI. Imagine wanting to run an AI assistant on a laptop without a dedicated high-end GPU, or deploying a language model in an environment where a reliable internet connection is unavailable. A smaller, quantized model can make local inference more practical.2. What Exactly Is Quantization?To understand quantization, it helps to first understand how computers represent numbers. Computers do not store numbers in the same way we write them on paper. They represent numerical values using binary digits, commonly called bits. A bit can hold either a 0 or a 1, and the number of bits available determines how many different values can be represented.For example, an 8-bit unsigned integer can represent 256 different values, from 0 to 255. A 4-bit unsigned integer can represent only 16 different values, from 0 to 15. When fewer bits are available, there are fewer possible numerical values to choose from.Now imagine a model parameter with a value of 0.734829. A floating-point format can represent values with decimal precision, whereas a small integer format cannot directly represent that exact value. Quantization solves this by mapping the original value to a smaller set of representable values. The result is an approximation rather than an exact copy of the original number.In simple terms, quantization is the process of converting a large set of possible numerical values into a smaller set of representative values. It is similar to reducing the number of colours in an image. An image with millions of possible colours can be represented using a much smaller colour palette. The image may lose some subtle colour differences, but it can still look very similar to the original. Quantization applies a related idea to the numerical values used inside a machine learning model.A simple illustration showing a continuous range of values being mapped to a smaller set of discrete values3. Understanding Floating-Point and Integer FormatsBefore looking at the actual quantization process, we need to understand the numerical formats commonly used in machine learning. We may have come across terms such as FP32, FP16, BF16, INT8 and INT4. These names describe how numerical values are represented.FP32, also known as 32-bit floating point, uses 32 bits to represent a number. It provides a relatively high level of precision and a wide numerical range, which makes it useful in many training and computing tasks. However, storing every model weight in FP32 requires a considerable amount of memory.FP16 uses 16 bits instead of 32, reducing the storage requirement by half. It is commonly used in deep learning because it can reduce memory consumption and support faster computation on compatible hardware. BF16, or Brain Floating Point 16, also uses 16 bits, but distributes those bits differently. It keeps a wider numerical range than FP16, although it has fewer bits available for precision. This can make BF16 useful in deep learning workloads where avoiding numerical overflow is important.INT8 and INT4 are different because they represent values using 8-bit and 4-bit integers rather than floating-point numbers. Since they use fewer bits, they can significantly reduce the memory needed to store model weights. However, converting floating-point values into integers means that some numerical detail is lost.It is important to distinguish between reducing precision and reducing numerical range. Precision refers to how closely a format can represent nearby values, while range refers to the smallest and largest values it can represent. For example, BF16 has a wider numerical range than FP16, but FP16 has more precision bits. These are two different properties, and both matter when selecting a numerical format.4. How Does Quantization Actually Work?Quantization is not simply a matter of replacing every floating-point number with an integer. The model’s original values can be very small, very large, positive or negative, so we need a way to map them into the available integer range. This is where two important concepts come in: scale and zero-point.ScaleScale determines the relationship between the original floating-point values and the quantized integer values. In other words, it tells us how much one integer step represents in the original numerical space. For a symmetric quantization scheme, the scale can be calculated as:Scale = Maximum absolute value / Maximum absolute integer valueFor example, if our original range is [-1, 1] and we use the symmetric INT8 range [-127, 127]:Scale = 1 / 127Scale ≈ 0.007874This means that each integer step represents approximately 0.007874 in the original numerical space.Zero PointThe zero-point identifies which integer value represents zero in the original floating-point space. For symmetric quantization, the zero-point is generally zero. For asymmetric quantization, it can be a different integer. This becomes useful when the original numerical values are not distributed evenly around zero.The Quantization FormulaA commonly used affine quantization formula is:q = round(x / S) + ZWhere:q = quantized integer valuex = original floating-point valueS = scaleZ = zero-pointLet’s take a simple example.Original value = 0.5Scale = 0.007874Zero-point = 0Therefore:q = round(0.5 / 0.007874)q ≈ 64So, our original value of 0.5 is represented by the integer 64.We have successfully mapped a floating-point value into an integer representation.Floating-point weights being converted into quantized integer weights5. Dequantization and Quantization ErrorIf quantization converts floating-point values into integers, how does the model use those values during computation? This brings us to dequantization.Dequantization is the reverse process of quantization. It reconstructs an approximate floating-point value from its quantized integer representation. The formula is:x ≈ S × (q — Z)Using our previous example:Quantized value = 64Scale = 0.007874Zero-point = 0The reconstructed value becomes:x ≈ 0.007874 × 64x ≈ 0.5039Notice something? Our original value was 0.5, but the reconstructed value is approximately 0.5039. They are not exactly the same. The difference between the original value and the reconstructed value is called quantization error.A small amount of error may not noticeably affect the model’s output. However, a model contains millions or billions of parameters, and changes across many values can influence its overall behaviour. This is why reducing a model to fewer bits must be done carefully. The objective is not simply to make the model as small as possible, but to find a balance between memory savings and model quality. Hence this proves that quantization cannot preserve every original numerical value perfectly.6. Symmetric and Asymmetric QuantizationNot all numerical values in a neural network behave in the same way. Some values are distributed around zero, while others may be concentrated on the positive or negative side. Because of this, different quantization approaches are used.Two common approaches are: Symmetric Quantization and Asymmetric QuantizationSymmetric QuantizationIn symmetric quantization, the numerical range is centered around zero. For example: [-127, 127]The positive and negative sides have equal magnitudes, and zero is represented by integer zero. This approach is commonly used for quantizing model weights.Asymmetric QuantizationIn asymmetric quantization, the numerical range does not necessarily have to be centered around zero. For example, consider values ranging from 0 to 6. We could map this range into the unsigned INT8 range of 0 to 255.The zero-point and scale are adjusted to represent the original values. This is useful when the distribution of values is uneven. For example, the ReLU activation function converts negative values to zero, producing non-negative outputs. Therefore, asymmetric quantization can be useful when dealing with certain activation distributions.7. Calibration, Weight and ActivationWeights and ActivationsWeights are learned numerical parameters within a neural network. They are stored as part of the model and determine how information is processed.Activations are intermediate numerical values generated when the model processes input data. For example, when we provide a sentence to an LLM, its different layers perform computations and generate intermediate values. These are called activations. Both weights and activations can be quantized, although they are not always treated in the same way.Quantization can be applied to weights, activations, or both. Weight-only quantization reduces the memory needed to store the model’s parameters. Quantizing activations can also reduce memory use and computation requirements, but it introduces additional considerations because activation values depend on the input data.CalibrationCalibration is the process of estimating suitable quantization parameters, such as scales and zero-points. To understand why calibration matters, imagine that a model produces activation values ranging from -0.5 to 2.5. We need to determine an appropriate numerical range for representing these values using a lower-bit format. A calibration dataset provides representative inputs that we can pass through the model to observe its activation distributions. Based on these observations, we can determine suitable quantization parameters. This is particularly important for techniques that quantize activations or use calibration to improve weight quantization.8. Post Training Quantization and Quantization-Aware TrainingThere are two broad approaches to quantizing a model: Post-Training Quantization (PTQ) and Quantization-Aware Training (QAT).Post Training QuantizationPost-Training Quantization is performed after the model has already been trained. Rather than training the model again from the beginning, we take an existing model and convert its weights, activations, or both into a lower-precision representation. This makes PTQ attractive because it can reduce memory requirements without requiring the full training process to be repeated. Many commonly used quantization workflows follow this approach. The general workflow looks like:Obtain a pre-trained model.Prepare calibration data if the chosen model requires it.Apply quantization.Evaluate the quantized model.Deploy it for inference.The main advantage is that we can optimize an existing model without repeating its original training process.Advantages of PTQReduced computational cost: Does not require retraining the entire model, significantly reducing computational requirements.Time efficiency: Quantization can be performed relatively quickly on an already-trained model.Lower resource requirements: Requires fewer computational resources compared to training-based quantization approaches.Disadvantages of PTQPotential accuracy degradation: Reducing numerical precision can introduce quantization errors, negatively affecting model performance.Limited adaptability: Since the model is not retrained to compensate for quantization errors, it may struggle to maintain its original performance at lower precisions.Quantization-Aware TrainingQuantization-Aware Training works differently. During training or fine-tuning, the model is exposed to the effects of quantization through simulated lower-precision operations. This allows the model to adjust to the numerical errors that may occur when it is eventually quantized. QAT can help preserve model quality in situations where straightforward post-training quantization causes too much degradation. However, it generally requires additional training resources and a more involved workflow.Advantages of QATImproved accuracy retention: Simulating quantization effects during training allows the model to adapt to reduced numerical precision.Reduced quantization error: Model parameters are adjusted during training to compensate for errors introduced by quantization.Support for lower precision: Can help maintain model performance under aggressive quantization, including INT8 and INT4 configurations.Disadvantages of QATHigh computational requirements: Requires additional training or fine-tuning, increasing computational costs.Increased training time: The quantization-aware training process adds time compared to conventional post-training quantization.Resource-intensive process: May require substantial GPU memory and processing capabilities, particularly for large language models.9. Understanding GGUF, GPTQ and AWQGGUF (GGML Universal File)GGUF is a file format used to store model weights, metadata and other information required for inference. It is widely used with llama.cpp and local LLM applications such as Ollama.We might encounter a filename like:Qwen2.5-7B-Instruct-Q4_K_M.ggufHere, Q4 indicates a 4-bit quantization family, while K_M identifies a particular quantization variant.GPTQ (GPT Quantization)GPTQ is a post-training quantization method that aims to identify how quantizing one weight affects the model’s output and adjusts other weights to compensate for the resulting error. It commonly supports 4-bit weight quantization and is frequently used for GPU-based inference.AWQ (Activation-aware Weight Quantization)AWQ is another post-training quantization method. It is based on the observation that not all weights contribute equally to the model’s performance. Some weights are associated with activation channels that have a greater influence on the model’s output. Quantizing these weights carelessly can introduce more significant errors. This helps reduce the performance degradation that can occur when model weights are compressed.The important distinction is:GGUF is a model file format.GPTQ is a quantization method.AWQ is a quantization method.They belong to different parts of the model compression and deployment process.10. How much Memory can Quantization Save?The memory savings become easier to understand when we compare a model stored using different numerical formats. Consider a model containing 7 billion parameters. If we assume all parameters are stored using the same number of bits, we can estimate the required memory using:Memory = (Number of parameters × Bits per parameter) / 8Here,Number of parameter = Total number of weights in the modelbits per parameter = Number of bits used to represent each parameter8 = the number of bits in one byteIf each parameter is stored using 32 bits, the weights require approximately 28 GB. With 16-bit storage, the requirement becomes approximately 14 GB. At 8 bits, it falls to around 7 GB, and at 4 bits, it becomes approximately 3.5 GB.These are approximate decimal GB values for raw weights only. We can notice that moving from FP16 to INT4 reduces the theoretical weight storage requirement by approximately 75%. This is a considerable improvement.11. Does Quantization Always make Inference faster?Not necessarily.Quantization can improve inference speed because fewer bits need to be transferred between memory and processing units. It can also enable more efficient low-precision operations on supported hardware.However, the actual speed improvement depends on several factors:CPU or GPU architecture.Hardware support for lower-bit operations.Quantization method.Inference framework.Memory bandwidth.For example, a 4-bit model may require considerably less memory than its FP16 counterpart, but it will not necessarily generate tokens faster on every device.Therefore, model size and inference speed should be evaluated separately.12. Why does Quantization matter for EdgeAI?One of the most interesting applications of quantization is edge AI. Edge AI refers to running AI models directly on local devices rather than relying entirely on remote cloud infrastructure. Think about devices such as laptops, smartphones, embedded computers and other resource-constrained systems. These devices often have limited memory and computational capabilities. Running a large language model on them can be challenging. Quantization helps address this limitation by reducing the amount of memory required to store and run models.This creates opportunities for:Running LLMs locally.Reducing dependence on cloud APIs.Developing offline AI applications.Reducing deployment costs.Making AI more accessible on lower-resource hardware.However, as discussed earlier, quantization alone does not make every large model suitable for every edge device. Model size, available RAM, processing power and inference software still matter.13. ConclusionLLM quantization is more than simply converting floating-point numbers into integers. It is about finding a balance between model size, computational efficiency and performance. By representing model weights and sometimes activations using fewer bits, we can significantly reduce memory requirements and make local deployment more practical.However, reducing numerical precision introduces quantization error, which means we must carefully evaluate how much model performance is affected. As LLMs continue to grow, techniques such as PTQ, QAT, GPTQ and AWQ will remain important parts of making AI models more efficient and accessible. For anyone interested in local LLM deployment, model optimization or edge AI, understanding quantization is an excellent place to start.The real challenge is not just making an LLM smaller. It is making it smaller while preserving the capabilities that make it useful.LLM Quantization Explained: How Do We Make Large Language Models Smaller and More Efficient? was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.