liveBook · Manning

Post-training quantization

As explained in Transformers in Action

Posttraining quantization converts a pretrained model to lower-precision representations without additional model training.

Post-training quantization converts a pretrained model to lower-precision representations without additional training, reducing inference memory and supporting resource-constrained or rapid deployment scenarios. section 8.3.3

Quantization choices involve distinct trade-offs:

  • Nonuniform quantization uses variable-sized intervals adapted to weight or layer distributions, potentially reducing quantization error. section 8.3.3
  • Quantization-aware training retrains with quantized weights and activations, preserving performance at lower precision but increasing computational cost. section 8.3.3
  • Post-training quantization avoids retraining and is less computationally demanding, but typically remains at 8-bit or 6-bit precision. section 8.3.3

Loading a 4-bit model

A bitsandbytes configuration loads Falcon 7B with 4-bit weights, selects FP4 quantization, uses bfloat16 computation, and records GPU memory before and after loading. section 8.3.3

Table 8.1 Comparison of data types
Data type
Bit width
Range
Memory reduction from FP32
float32
32 bits
≈ ± 3.4 × 10^{38}
–
float16
16 bits
≈ ± 6.5 × 10^{4}
50%
int8
8 bits
-128 to 127
75%
int4
4 bits
-8 to 7
87.5%

Compare float32, float16, int8, and int4 bit widths, numeric ranges, and stated memory reductions. section 8.3.3

How Transformers in Action covers it

How deep it goes
Compares quantization variants and trade-offs, but does not detail the quantization algorithm’s internal calculations.
Examples
Uses a Falcon 7B bitsandbytes configuration and a data-type comparison spanning float32 through int4.
What it assumes
Assumes access to a pretrained model and distinguishes deployment quantization from retraining-based quantization.
What you can do after
Apply it via bitsandbytes by configuring 4-bit loading and measuring GPU memory usage.
How it connects
Connects quantization with quantization-aware training, nonuniform quantization, QLoRA, and model inference.

Also explained in

Compare how 2 books explain post-training quantization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.