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.
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.
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:
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:
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:
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:
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):
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 Provenancefrom mlsysim.engine.accuracy_curve import AccuracyCurvemy_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.