designwithfocus

AI & ML development

What Is Quantization in AI? Fewer Bits, Smaller Models

By Design With Focus Team 5 min read
Tall weight bars shrinking into shorter bars on a card

Short answer

Quantization stores model weights and activations in fewer bits so the model uses less memory. Hugging Face describes it as lower-precision types such as 8-bit integers, and Transformers supports 8-bit and 4-bit quantization with bitsandbytes. That library's guide says 8-bit halves memory use and 4-bit reduces it by 4x.

Last verified against the sources listed below.

Key takeaways

  • Quantization represents weights with lower-precision types, such as 8-bit integers.
  • Transformers supports 8-bit and 4-bit quantization through bitsandbytes, plus AWQ and GPTQ.
  • The bitsandbytes guide says 8-bit halves memory use and 4-bit reduces it by 4x.
  • PyTorch is moving quantization work to torchao and plans to remove the old API in 2.10.
  • ONNX Runtime documents 8-bit linear quantization and a separate 4-bit path for some ops.

A direct definition of what is quantization in ai is storing a model’s numbers in fewer bits. Hugging Face says quantization reduces memory and compute cost by representing weights and activations with lower-precision types such as 8-bit integers, written int8.

The same page says this can make it possible to load larger models, and that it can speed up inference. It does not publish one speedup percentage for every model. It names AWQ, GPTQ, and 8-bit and 4-bit quantization with bitsandbytes.

What gets stored in fewer bits?

Weights and activations get stored in fewer bits. QuantoConfig, on that Hugging Face page, defaults weights to int8 and also allows float8, int4, and int2. Activations can be left unset, or set to int8 or float8.

You can also list modules that must stay in their original precision. The page gives examples such as a Whisper encoder, a Llava encoder, and Mixtral gate layers. Those exceptions are part of the config, not a separate file format.

Machine learning is the broader field these models come from. Quantization does not change the task the model was trained for. It changes the numeric type used when you load or run it.

What do 8-bit and 4-bit change?

They change how much memory the quantized layers occupy. The bitsandbytes guide says quantizing a model in 8-bit halves the memory use. It says quantizing in 4-bit reduces memory use by 4x.

Setting Memory note on that page
8-bit Halves memory use
4-bit Reduces memory use by 4x
Nested quantization Saves an additional 0.4 bits per parameter

The guide names two features. LLM.int8 is an 8-bit method meant to keep inference usable without a large quality drop, by keeping higher precision for critical computations. QLoRA is a 4-bit method that compresses further and stays trainable by adding a small set of low-rank weights.

Nested quantization, on the same page, quantizes the already quantized weights again and saves an additional 0.4 bits per parameter. The page says that extra saving has no additional performance cost. It also shows a specific setup, a Llama-2-13b model on a 16GB NVIDIA T4, as an example of when that option is used. That example is not a general speed claim.

The guide says 8-bit and 4-bit training is supported only for training extra parameters. For large models it tells you to set device_map to auto so weights can be placed across available GPUs.

Where is PyTorch moving this work?

PyTorch is moving quantization into torchao. The PyTorch quantization page, last updated May 11, 2026, says development is being centralized there. It plans to delete torch.ao.quantization in version 2.10 if there are no blockers.

The page lists the older flows it wants people to leave. Eager mode and FX graph mode should move to torchao APIs. The pt2e flow has already moved. The old reference stays only because the functions are still public.

torchao’s docs, created March 25, 2026, call the library a place to quantize and sparsify weights, gradients, optimizers, and activations with native PyTorch. One line on that page is a model-specific result, not a blanket promise. It says quantizing Llama-3-8B to int4 gave 1.89x faster inference with 58 percent less memory.

Another line says pretraining Llama-3.1-70B was 1.5x faster with float8 training. Those lines name specific models.

How does ONNX Runtime define it?

ONNX Runtime defines its main path as 8-bit linear quantization. Its quantization guide maps a floating-point value with a scale and a zero point. The zero point must be able to represent a real zero exactly, because zero padding is common and a missing zero causes accuracy errors.

The same guide also quantizes some operators to 4-bit integers. MatMul and Gather are the supported cases it lists, with block-wise weight-only quantization. Int4 and UInt4 need ONNX opset 21, and the guide says an older model is upgraded to that opset. Running GatherBlockQuantized nodes needs ONNX Runtime 1.20.

A separate limit is about an optimization step, not about the bit width. The guide says model optimization cannot output a model larger than 2GB, so that step must be skipped for large models. It also says quantization is not lossless and can hurt accuracy. Dynamic and static quantization differ in when the scale and zero point for activations are calculated.

How do you load a quantized model?

You pass a config when you load the model in Transformers. The bitsandbytes page shows BitsAndBytesConfig with load_in_8bit or load_in_4bit, then from_pretrained. How to use Hugging Face is the broader walk through finding and running a model. Quantization is one argument on that load, not a separate website.

After a model is quantized to 8-bit, the guide says you can push the weights to the Hub if you are on a current Transformers and bitsandbytes. The quantization config is pushed first, then the weights. A 4-bit model can be saved with save_pretrained and pushed the same way when the library is current.

Dequantize returns a model toward its original precision, and the page warns that this can lose quality and that you need enough GPU memory for the larger result. That is the reverse direction. It is not required just to run the quantized copy.

Compressing a picture is a different shrink. The Image Compressor reduces an image file.

It does not turn 32-bit floating-point weights into 8-bit or 4-bit integers. Use it on images, and use a quantization config on models.

Frequently asked questions

Does quantization always make inference faster?

The Transformers page says lower precision can speed up inference, and it does not give one percentage for every model. The memory figures on the bitsandbytes guide are separate. Eight-bit quantization halves memory use, and 4-bit quantization reduces memory use by 4x, for the cases that guide describes. Check the model and the hardware before you expect a faster run.

Which bit widths do the Hugging Face docs name?

The overview names 8-bit integers, written int8, and says Transformers supports 8-bit and 4-bit quantization with bitsandbytes. The QuantoConfig class lists weight targets of float8, int8, int4, and int2. Activations can stay unset or use int8 or float8. bitsandbytes names LLM.int8 as the 8-bit method and QLoRA as the 4-bit method that stays trainable.

What did the PyTorch docs say about the old API?

The stable quantization page, last updated May 11, 2026, says quantization work is being centralized in torchao. It asks readers to migrate eager mode, FX graph mode, and pt2e flows to the torchao APIs. It also says the project plans to delete torch.ao.quantization in version 2.10 if nothing blocks that removal. The old functions stay public for now.

How does ONNX Runtime describe the same idea?

ONNX Runtime says its quantization is 8-bit linear quantization of an ONNX model. Floating-point values are mapped with a scale and a zero point so that a real zero stays representable. The same guide also documents quantizing some operators, including MatMul and Gather, to 4-bit integer types. Model optimization cannot write a model larger than 2GB, so large models skip that step.

Is quantizing weights the same as compressing an image?

No. Quantization changes how model weights and activations are stored, using fewer bits for those numbers. An image compressor shrinks a picture file. The two operations can both make a download smaller, and they do not share a format or a bit width. Use the compressor on a picture. Use a quantization config on a model.

Sources