Hardware-Aware Model Optimization › Quantization Formats for Devices
Language AI HandbookAll chapters A quantized representation combines stored weight values with the information needed to decode them. This section compares a simple group-wise integer representation across hypothetical hardware paths. The fastest option depends on the packing and the execution kernel. TinyChat is one concrete implementation that pairs four-bit weights with device-specific packing and fused kernels. Lin et al., AWQ
The format trade-off space
Compare formats on the dimensions that affect deployment.
- Bits per weight: fewer stored bits can reduce bytes streamed per token if the runtime reads the packed format at the measured boundary. Extra metadata or transfers can offset the saving.
- Representational fidelity: how much model quality you lose, measured by perplexity or task accuracy.
- Unpacking cost: the instructions needed to turn packed weights back into something the multiplier can consume.
- Kernel coverage: whether existing optimized kernels (device-specific) implement that format.
A runtime may have efficient implementations for some bit widths and group sizes. If there is no specialized path for a chosen representation, measure the generic path and any fallback. The smaller file and the faster kernel can belong to different choices.
Integer formats and scale overhead
Take a symmetric integer format with bits per weight and one 32-bit scale for each full group of weights. To estimate the stored payload, amortize the scale over the group.
Here counts bits per stored weight, including that scale. With , group 32 uses 5 bits per weight and group 128 uses 4.25. The calculation assumes complete packed groups. A format with a stored zero point, padding, or alignment can take more space. A larger group spreads each scale over more values, and its effect on quantization error depends on the weight distribution and the fitting rule.
PythonIn [13]Expand
def effective_bits(b, group_size, scale_bits=32, zero_point=False):
overhead = scale_bits / group_size
if zero_point:
overhead += b / group_size # one packed b-bit zero point per full group
return b + overhead
effective_bit_table = {}
for g in [16, 32, 64, 128, 256]:
effective_bit_table[g] = (effective_bits(4, g), effective_bits(8, g))Multiply the parameter count by the effective bits per weight, then divide by eight for bytes. For 1.1 billion parameters, 4.25 bits gives 584,375,000 bytes, about 0.544 GiB. The ideal four-bit payload alone would use 550,000,000 bytes, about 0.512 GiB. Runtime buffers and cache storage enter the memory budget separately.
The next chart holds the weight count fixed and compares FP16, INT8 with groups of 128, and INT4 with groups of 32 or 128. FP16 uses 16 bits per weight. For INT4, reducing the group size from 128 to 32 raises the payload by about 18%. To find how many weights fit in a budget, divide the available bytes by the average stored bytes per weight. Check how the format packs or pads a partial group, and account for alignment if scales occupy a separate array.
PythonIn [14]Expand
# Effective bits including 32-bit scale overhead, for a fixed model size and group size.
footprint_params = 1.1e9 # illustrative billion-class model
footprint_rows = [
("FP16", None),
("INT8 g128", 128),
("INT4 g128", 128),
("INT4 g32", 32),
]
footprint_gib = {}
for fmt_name, fmt_group in footprint_rows:
if fmt_group is None:
bits = 16.0
elif fmt_name.startswith("INT8"):
bits = effective_bits(8, fmt_group)
else:
bits = effective_bits(4, fmt_group)
footprint_gib[fmt_name] = footprint_params * bits / 8 / (1024**3)VisualizationOut [15]Expand

PythonIn [16]Expand
plot_group_sizes = sorted(effective_bit_table)
plot_int4_bits = [effective_bit_table[g][0] for g in plot_group_sizes]
plot_int8_bits = [effective_bit_table[g][1] for g in plot_group_sizes]VisualizationOut [17]Expand

Float formats: FP8, FP16, BF16
Floating-point formats allocate bits differently between range and precision. Check the formats the target runtime can execute for the operations in your model.
- BF16 has eight exponent bits and seven stored fraction bits. It has the same normal exponent range as FP32. RISC-V Unprivileged ISA, BF16 Operand Format
- FP16 has five exponent bits and ten stored fraction bits. Its largest finite value is 65,504. W3C, WGSL §6.2.4
- FP8 can refer to different encodings, including E4M3 and E5M2. Check both the encoding and the arithmetic support of the target kernel. Micikevicius et al., FP8 Formats for Deep Learning
Choose a format the device and runtime accelerate for the required operators. Validate quality on your task with the actual executable path, including its accumulation precision and casts.
Mixed formats: W4A16, W8A8, W4A8
Weight and activation precision are separate choices. The notation uses W for weights and A for activations.
- W4A16 uses four-bit weights and 16-bit activations. A suitable kernel can read compact weights and unpack them while computing.
- W8A8 uses eight-bit weights and activations. For the same number of weights, its raw weight payload is twice that of a four-bit encoding. Scales, zero points, and packing can change the total ratio.
- W4A8 pairs four-bit weights with eight-bit activations. This requires a kernel that implements the combination and any necessary scaling.
Two questions separate the modes:
- For a memory-limited decode path, ask how much weight traffic the format removes and what it adds to the kernel.
- For prompt processing, test whether the runtime can reuse weight tiles and use the activation arithmetic mode efficiently.
Benchmark both modes on the intended model and prompt lengths.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!