Skip to main content

Quantization: Not a Free Lunch

INT4 gives up to 4.0× speedup for memory-bound decode. For compute-bound weight-only quantization, it gives 1.0×.

algorithm
intermediate
Discover that quantization helps only when a workload is memory-bound (or when native low-precision Tensor Cores boost compute). Compare the effect of INT4 on LLM decode vs. large-batch training.

The Question

INT4 quantization reduces model weight size by 4× (from 16.06 GB in FP16 to 4.02 GB in INT4 for Llama-3.1-8B). Intuitively, 4× fewer bytes should mean 4× faster execution. Does INT4 always give a 4× speedup?

Tutorial 1 already supplies the tools to predict the answer: performance is governed by whichever ceiling binds first. When quantization reduces bytes transferred from HBM without increasing arithmetic throughput, it accelerates memory-bound workloads and leaves compute-bound workloads unchanged.

This tutorial makes the prediction, runs the experiment, and shows that the outcome depends entirely on the operating regime.

NotePrerequisites

Complete Tutorial 1: The Memory Wall and Tutorial 2: Two Phases, One Request. This tutorial assumes familiarity with memory-bound vs. compute-bound regimes and why LLM decode is memory-bound.

NoteLearning Objectives
  • Predict whether quantization will help a given workload based on its regime
  • Measure the speedup from INT8 and INT4 for both memory-bound and compute-bound workloads
  • Explain why weight-only INT4 yields 4.0× in one regime and 1.0× in another
  • Evaluate the accuracy-compression trade-off using CompressionModel
TipBackground: What Quantization Actually Does

Quantization reduces the number of bytes per parameter:

Precision Bytes/Param Relative to FP16 Llama-3.1-8B Weights
FP16 2 1.0× (baseline) 16.06 GB
INT8 1 0.5× 8.03 GB
INT4 0.5 0.25× 4.02 GB

For memory-bound workloads, performance scales with bytes loaded from HBM per step. Halving bytes nearly halves latency. For compute-bound workloads, performance scales with FLOP/s. Fewer weight bytes do not change the number of FLOPs, so latency stays the same unless the hardware also provides higher-throughput low-precision Tensor Cores.

The key criterion is always which ceiling the workload is hitting.


1. Setup

import mlsysim
from mlsysim.solvers import ServingModel, SingleNodeModel
from mlsysim.solvers import CompressionModel

2. Memory-Bound Case: LLM Decode at Batch 1

LLM decoding at batch 1 is the textbook memory-bound workload. Each token generation must reload the entire model from HBM. Fewer bytes per parameter means fewer bytes to load, and therefore lower inter-token latency:

from mlsysim.solvers import ServingModel
from mlsysim.show import table, info

model = mlsysim.Models.Language.Llama3_8B
hardware = mlsysim.Hardware.Cloud.H100
solver = ServingModel()

rows = []
baseline_itl = None
for prec in ["fp16", "int8", "int4"]:
    r = solver.solve(
        model=model, hardware=hardware,
        seq_len=2048, batch_size=1, precision=prec
    )
    itl_ms = r.itl.to("ms").magnitude
    if baseline_itl is None:
        baseline_itl = itl_ms
    speedup = baseline_itl / itl_ms
    rows.append([prec, r.itl.to('ms'), r.model_weights_size, f"{speedup:.1f}x"])

table(["Precision", "ITL", "Weights", "Speedup vs FP16"], rows)
Precision      ITL   Weights  Speedup vs FP16
─────────────────────────────────────────────
fp16       4.87 ms  16.06 GB             1.0x
int8       2.44 ms   8.03 GB             2.0x
int4       1.22 ms   4.02 GB             4.0x

INT8 cuts weights from 16.06 GB to 8.03 GB and lowers ITL from 4.87 ms to 2.44 ms, a 2.0× speedup. INT4 cuts weights to 4.02 GB and lowers ITL to 1.22 ms, a 4.0× speedup. On the pure Roofline ceiling (zero kernel-launch tax and matching weight/KV precision), decode latency scales directly with bytes transferred from HBM; in production W4A16 serving—where the KV cache stays in FP16, group scales add overhead, and dequantization kernels add launch latency—realized speedups typically land around 3.0–3.8×.


3. Compute-Bound Case: Large-Batch Execution

The same optimization behaves differently on a compute-bound workload, ResNet-50 at batch 256 on the NVIDIA A100:

from mlsysim.solvers import SingleNodeModel

train_model = mlsysim.Models.Vision.ResNet50
train_hw = mlsysim.Hardware.Cloud.A100
train_solver = SingleNodeModel()

rows = []
baseline_lat = None
for prec in ["fp16", "int8", "int4"]:
    p = train_solver.solve(
        model=train_model, hardware=train_hw,
        batch_size=256, precision=prec
    )
    lat_ms = p.latency.to("ms").magnitude
    if baseline_lat is None:
        baseline_lat = lat_ms
    speedup = baseline_lat / lat_ms if lat_ms > 0 else 0
    rows.append([prec, p.latency.to('ms'), f"{p.throughput.magnitude:.0f} img/s", f"{speedup:.1f}x"])

table(["Precision", "Latency", "Throughput", "Speedup"], rows)
Precision   Latency   Throughput  Speedup
─────────────────────────────────────────
fp16       13.47 ms  19003 img/s     1.0x
int8        6.74 ms  37964 img/s     2.0x
int4       13.47 ms  19003 img/s     1.0x

At batch 256, ResNet-50 on the NVIDIA A100 is compute-bound: weight-only INT4 (13.47 ms, 19,003 img/s) delivers 1.0× speedup relative to FP16 (13.47 ms, 19,003 img/s). Because the A100 lacks native INT4 Tensor Cores in the Zoo, weight-only INT4 dequantizes weights to FP16 in registers and executes at the 312 TFLOP/s FP16 compute ceiling; shrinking weight traffic by 4× does nothing when arithmetic is the bottleneck. By contrast, INT8 reaches 6.74 ms (2.0× speedup) only because the A100 provides dedicated INT8 Tensor Cores at 624 TFLOP/s (2× the FP16 compute peak).

WarningNuance: INT8 Tensor Cores vs. Weight-Only INT4

GPUs with dedicated INT8 Tensor Cores (such as the A100 at 624 TFLOP/s INT8 vs. 312 TFLOP/s FP16, a 2× compute boost) raise both the memory ceiling (fewer bytes) and the compute ceiling (more INT ops/sec) when activations and weights are quantized together (W8A8). Weight-only INT4 (W4A16), by contrast, reduces HBM weight traffic by 4× while keeping arithmetic on FP16 Tensor Cores, so it accelerates memory-bound decode (4.0×) while leaving compute-bound steps unchanged (1.0×).


4. The Reveal: Same Optimization, Two Regimes

Placing the results side by side makes the contrast stark:

rows = []

# Memory-bound: LLM decode
decode_row = ["Llama-3 8B decode"]
for prec in ["fp16", "int8", "int4"]:
    r = solver.solve(model=model, hardware=hardware, seq_len=2048, batch_size=1, precision=prec)
    decode_row.append(r.itl.to('ms'))
decode_row.append("Memory-bound")
rows.append(decode_row)

# Compute-bound: large-batch CNN execution
train_row = ["ResNet-50 bs=256"]
for prec in ["fp16", "int8", "int4"]:
    p = train_solver.solve(model=train_model, hardware=train_hw, batch_size=256, precision=prec)
    train_row.append(p.latency.to('ms'))
train_row.append("Compute-bound")
rows.append(train_row)

table(["Workload", "FP16", "INT8", "INT4", "Regime"], rows)
Workload               FP16     INT8      INT4         Regime
─────────────────────────────────────────────────────────────
Llama-3 8B decode   4.87 ms  2.44 ms   1.22 ms   Memory-bound
ResNet-50 bs=256   13.47 ms  6.74 ms  13.47 ms  Compute-bound
ImportantKey Insight

Weight-only quantization reduces bytes loaded from memory. For a memory-bound workload, fewer bytes mean proportional speedup. For a compute-bound workload, fewer bytes alone mean no speedup, because compute, not memory, is the ceiling. The regime determines whether byte reduction works: INT4 lowers Llama-3.1-8B decode latency from 4.87 ms to 1.22 ms (4.0× speedup, memory-bound) yet leaves ResNet-50 at batch 256 at 13.47 ms (1.0×, compute-bound). Always check the regime before choosing an optimization.


5. Scale Overhead and the Accuracy Tax: CompressionModel

Quantization is not free: group-wise scale factors slightly increase effective bitwidth (\(b_{\text{eff}} = b_{\text{target}} + b_{\text{scale}} / g\)), and lower bitwidths trade task accuracy for memory savings. Because accuracy degradation depends on architecture, calibration method (e.g., GPTQ or AWQ), and downstream metric, CompressionModel takes accuracy_delta as an explicit empirical input rather than guessing from a fixed curve:

from mlsysim.solvers import CompressionModel

comp_solver = CompressionModel()

configs = [
    ("FP16 (baseline)", 16, None, 0.0),
    ("INT8 per-channel", 8, None, -0.002),
    ("INT4 (g=128)",     4, 128,  -0.015),
]

rows = []
for label, bits, group_size, acc_delta in configs:
    c = comp_solver.solve(
        model=model, hardware=hardware,
        method="quantization", baseline_precision="fp16",
        target_bitwidth=bits, group_size=group_size,
        accuracy_delta=acc_delta,
    )
    rows.append([
        label,
        c.compressed_size_gb,
        f"{c.compression_ratio:.2f}x",
        f"{c.estimated_accuracy_delta:+.1%}",
        f"{c.memory_savings_pct:.1f}%"
    ])

table(["Format", "Compressed", "Compression", "Accuracy", "Savings"], rows)
Format            Compressed  Compression  Accuracy  Savings
────────────────────────────────────────────────────────────
FP16 (baseline)     16.06 GB        1.00x     +0.0%     0.0%
INT8 per-channel     8.03 GB        2.00x     -0.2%    50.0%
INT4 (g=128)         4.14 GB        3.88x     -1.5%    74.2%

Relative to FP16, 8-bit quantization shrinks Llama-3.1-8B to 8.03 GB (2.00× compression, 50.0% memory savings) at a typical -0.2% accuracy delta. Going to 4-bit with group_size=128 (16-bit scale per 128 weights, \(b_{\text{eff}} = 4.125\) bits/weight) shrinks weights to 4.14 GB (3.88× compression rather than an idealized 4.00×, 74.2% savings) at an illustrative -1.5% delta. The engineering rule is not “always quantize” but “quantize when the workload is memory-bound AND measured accuracy loss stays within the application’s error budget.”

WarningWhen NOT to Quantize
  • Training: Training is compute-bound at large batch sizes. Weight-only quantization does not help and low-precision gradients can harm convergence.
  • High-accuracy applications: Medical, financial, and safety-critical systems may not tolerate even a 0.2% to 1.5% accuracy loss without task-specific validation.
  • Already compute-bound inference: An inference workload that runs at large batch sizes (e.g., offline batch processing) is already compute-bound unless hardware supports faster low-precision arithmetic.

Using a Measured Accuracy Curve

Passing a scalar accuracy_delta works for a single operating point, while sweeping bitwidths or pruning ratios benefits from a multi-point AccuracyCurve. A curve records the accuracy one experiment measured across several compression levels alongside the uncompressed baseline in the same evaluation harness, together with explicit Provenance.

The package ships four published curves as examples of the format. Below, two curves for Qwen-7B-Chat from Table 2 of Jin et al. (2024) compare GPTQ against SpQR across bitwidths (note that the curves belong to Qwen-7B-Chat rather than Llama-3.1-8B, so treat the table as a demonstration of how quantizer choice reshapes the cliff):

from mlsysim.engine.accuracy_curve import shipped_curve

gptq_curve = shipped_curve("qwen-7b-chat-gptq")
spqr_curve = shipped_curve("qwen-7b-chat-spqr")

rows = []
for bits in [8, 4, 3, 2]:
    gptq_res = comp_solver.solve(model=model, hardware=hardware, baseline_precision="fp16", target_bitwidth=bits, accuracy_curve=gptq_curve)
    spqr_res = comp_solver.solve(model=model, hardware=hardware, baseline_precision="fp16", target_bitwidth=bits, accuracy_curve=spqr_curve)
    rows.append([
        bits,
        f"{gptq_res.estimated_accuracy_delta:+.1%}",
        f"{spqr_res.estimated_accuracy_delta:+.1%}",
    ])

table(["Bits", "Qwen-7B-Chat (GPTQ)", "Qwen-7B-Chat (SpQR)"], rows)
Bits  Qwen-7B-Chat (GPTQ)  Qwen-7B-Chat (SpQR)
──────────────────────────────────────────────
8                   +0.1%                -0.6%
4                   -2.2%                -0.7%
3                   -5.7%                -1.6%
2                  -40.6%                -3.9%

Only the accuracy column changes between the two curves; size, compression ratio, and Roofline speedup are computed from physical bitwidth and group-scale parameters as before. A curve returns exact values at measured points, interpolates linearly between adjacent measured points, and refuses to extrapolate outside its measured range because the accuracy cliff varies sharply across models and quantizers.

To use your own results, build a curve from your measured points:

from mlsysim.core.provenance import Provenance
from mlsysim.engine.accuracy_curve import AccuracyCurve

my_curve = AccuracyCurve(
    name="my-model-rtn",
    axis="bitwidth",                      # or "sparsity" for a pruning curve
    measured_model="my model and checkpoint",
    method="round-to-nearest, per-channel, weights only",
    metric="top-1 accuracy",
    dataset="my validation set (10,000 examples)",
    retrained=False,
    baseline_accuracy=0.761,              # the uncompressed model, same harness
    points=[(16, 0.761), (8, 0.759), (6, 0.752), (4, 0.705)],
    provenance=Provenance(
        kind="derived",
        ref="my quantization sweep",
        verified="2026-11-16",
        notes="Measured with my evaluation script on my validation set.",
    ),
)

c = comp_solver.solve(model=model, hardware=hardware, target_bitwidth=6, accuracy_curve=my_curve)
info("From my curve", accuracy_change_at_6_bits=f"{c.estimated_accuracy_delta:+.1%}")
── From my curve ───────────────────────────
accuracy change at 6 bits:  -0.9%

A curve describes the model, method and data it was measured on. The solver cannot check that it matches the workload you pass, so keep one curve per model and method.


Where This Clicks in the Textbook

Vol I · Ch 10Core Theory

Covers PTQ, QAT, group-quantization scale overhead, structured sparsity, and accuracy-fidelity trade-offs.

Vol I · Ch 11Silicon Support

Distinguishes weight-only dequantization (W4A16 bandwidth relief) from native INT8/FP8 Tensor Core throughput.

Vol II · Ch 11Edge Envelopes

Applies aggressive quantization and pruning to fit strict on-device SRAM, DRAM, and milliwatt budgets.


Next Steps

  • KV-Cache: The Hidden Tax: Quantization also shrinks the KV-cache, allowing more concurrent users
  • The Memory Wall: Revisit the memory wall to see how quantization shifts the bandwidth bottleneck
  • Starving the GPU: Another case where the bottleneck is not where it is expected
  • Where to Invest: Quantify how much quantization buys compared to hardware upgrades
Back to top