Hardware-Aware Model Optimization › Quantization Formats for Devices

Michael BrenndoerferDecember 1, 20266 min read
Language AI HandbookAll chapters
Part 43 of 67Small and On-Device Language Models
Chapter 328Hardware-Aware Model Optimization › Quantization Formats for Devices
Reading section 3 of 11 · Quantization Formats for Devices · 6 minSection 3 of 11 · 6 min

Section 3 of 11 · 6 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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 bb bits per weight and one 32-bit scale for each full group of gg weights. To estimate the stored payload, amortize the scale over the group.

beff=b+32gb_{\text{eff}} = b + \frac{32}{g}

Here beffb_{\mathrm{eff}} counts bits per stored weight, including that scale. With b=4b=4, 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]
CollapseExpand
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]
CollapseExpand
# 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]
CollapseExpand
Horizontal bars compare weight footprint in GiB across four quantization formats.
Same parameter count, four storage choices. Effective bits translate into GiB of weights that must fit alongside the KV cache and runtime buffers. FP16 is nearly four times the INT4 g128 footprint, and group size of 32 raises INT4 cost by about 18% over group 128.

Scale overhead changes most at small group sizes. The next chart shows INT4 and INT8 over the same range. For INT8, reducing the group size from 128 to 32 raises the payload from 8.25 to 9 bits per weight, an increase of about 9%.

PythonIn [16]
CollapseExpand
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]
CollapseExpand
Two lines show effective bits per weight, including scales, falling as group size grows.
A 32-bit scale adds the same absolute overhead to INT4 and INT8 at a given group size. The overhead per stored weight falls as the group grows, dropping from 2 extra bits at group 16 to about 0.125 bits at group 256.

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.

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy