liveBook · Manning

Quantization

As explained in Domain-Specific Small Language Models

Methods that reduce numeric precision or representational size of model values to improve efficiency, especially for inference; here the absmax method is a specific quantization procedure.

Model quantization reduces the numeric precision of model weights or activations, typically replacing floating-point values with lower-bit representations. It trades some quantization error for lower memory use, potentially faster inference, and deployment on more constrained hardware. section 6.2 section 6.5

The main choices are precision format, quantization scheme, timing, and execution hardware. Post-training quantization (PTQ) modifies a trained model, while quantization-aware training (QAT) accounts for quantization during training; PTQ is especially practical for pretrained models that need only adaptation. section 6.1 section 6.2

Operational tradeoffs shape the deployment choice:

  • Use lower bit widths to reduce model memory requirements; 8-bit values can store roughly four times as many numbers as 32-bit floats in the same memory. section 6.2
  • Expect a balance among precision, memory footprint, inference speed, hardware support, and output quality rather than a universally best format. section 4.2 section 6.2
  • Choose domain-specific methods when ordinary quantization cannot satisfy the target environment; GPTQ supports efficient 3- or 4-bit weight quantization, while CPU and edge runtimes offer their own formats. section 6.4.1 section 11.4.2
  • Validate quality and serving behavior after conversion using measures such as perplexity, latency, throughput, and memory consumption. section 4.2 section 6.2.1

Absmax quantization

For an FP32 tensor X, calculate a scale as 127 divided by the tensor’s absolute maximum. Multiply X by that scale and round to obtain INT8 values; divide the rounded values by the scale to dequantize them. Applying this procedure layer by layer creates a dequantized model copy for comparison with the original. A GPT-2 example inspects weight histograms, generates text from both models, and compares perplexity; the quantized weights visibly differ, demonstrating that the method is lossy. section 6.2.1

Quantization fits into broader deployment pipelines. Models can be converted to ONNX, optimized or quantized, and then executed by a compatible runtime; specialized libraries such as AutoGPTQ, BitsAndBytes, and mllm target different model sizes and hardware environments. section 5.1 section 6.4.1 section 8.3

How Domain-Specific Small Language Models covers it

How deep it goes
Explains precision formats, PTQ and QAT, schemes, hands-on absmax steps, 4-bit methods, and evaluation, without formal derivations.
Examples
Demonstrates FP32-to-INT8 GPT-2 conversion, GPTQ quantization of GPT-2 XL, and 8-bit antibody-model deployment.
What it assumes
Assumes familiarity with pretrained language models, tensors, inference, and basic Python libraries; introduces precision formats and quantization mechanics.
What you can do after
Apply it via PyTorch, Transformers, AutoGPTQ, BitsAndBytes, or ONNX-compatible runtimes, then evaluate quality and serving performance.
How it connects
Connects precision formats, inference optimization, ONNX, knowledge distillation, GPTQ, perplexity, and model serving.

Also explained in

Compare how 13 books explain quantization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.