Loading…
Glossary term
Storing model weights at lower numeric precision to reduce memory and speed up inference.
Quantization stores a model's numbers at lower precision, for instance 8-bit or 4-bit integers instead of 16-bit floating point. That shrinks memory use and speeds up inference, usually with a small loss in quality.
It can be applied after training or taken into account during training.
8-bit quantization by hand
import numpy as np
w = np.array([0.12, -0.5, 0.33, 0.9])
scale = np.abs(w).max() / 127
q = np.round(w / scale).astype(np.int8) # stored as small integers
restored = q * scale # approximately the original
print(q, restored.round(3))It lets large models fit on cheaper hardware and even on laptops and phones.