Inference & Training Efficiency
Modern GPU accelerators are asymmetric machines: their matrix compute throughput (FLOP/s) has scaled faster than their off-chip High-Bandwidth Memory (HBM) speed. An NVIDIA H100 SXM GPU delivers of FP16 tensor compute, but only of HBM3 memory bandwidth.
To saturate the GPU’s matrix units without stalling on memory transfers, a kernel must perform at least 295 floating-point operations for every byte fetched from HBM (the hardware Ridge Point):
This single ratio explains why LLM inference is divided into two physically opposite regimes:
- Prefill (Compute-Bound): Processing an input prompt of tokens in parallel performs FLOPs while reading the byte weight matrix once, yielding .
- Autoregressive Decode (Memory-Bandwidth Bound): Generating a single token () for batch size performs FLOPs while streaming all bytes of model weights from HBM, yielding —leaving 99.6% of the GPU’s compute cores idle.
| Symbol / Metric | Units / Domain | Hardware & Algorithmic Role |
|---|---|---|
| Arithmetic Intensity: Ratio of floating-point operations to HBM memory traffic. On an NVIDIA H100 SXM ( FP16, HBM3), the ridge point is . | ||
| Autoregressive Decode Intensity: Because generating 1 token per request streams all weight bytes from HBM, small-batch decode achieves only (<5% GPU compute utilization). | ||
| Affine Group Quantization (GPTQ / AWQ): Compresses 16-bit weights into -bit integers per group of 128 channels using scale and zero-point , cutting HBM weight traffic by . | ||
| Speculative Decoding Acceptance Rule: Accepts K drafted tokens from a small draft model in a single parallel target forward pass while guaranteeing the exact target distribution . | ||
| ZeRO-3 / FSDP Sharded Training State: Partitions FP16 parameters (), gradients (), and FP32 Adam states () across ranks. |
Speculative Decoding Parallel Verification (K = 4 Draft Tokens Verified in 1 Target Pass)
Weight Quantization Walkthrough (AWQ & GPTQ)
Because small-batch decoding is bottlenecked strictly by streaming weight bytes from HBM, compressing each parameter from 16 bits (FP16/BF16) to 4 bits (INT4) reduces memory traffic by nearly and directly multiplies token generation speed.
1. Group-Wise Affine Quantization
Given a weight block , 4-bit asymmetric quantization maps floating-point weights to integers :
Consider a 4-element weight slice quantized to bits ( intervals):
- Scale Factor :
- Zero-Point :
- Quantized Integers :
- Dequantized Reconstruction :
2. Activation-Aware Weight Quantization (AWQ)
In Transformer hidden states, of channels exhibit massive activation outliers ( larger than average). Quantizing the corresponding weight columns naively causes severe perplexity degradation.
AWQ (Lin et al. 2024) protects salient weight channels without mixed-precision hardware overhead by multiplying salient weight column by a per-channel scale before quantization and dividing the input activation channel by :
Speculative Decoding Math & Expected Speedup
How can we accelerate autoregressive decoding without modifying model weights? Speculative Decoding (Leviathan et al. 2023; Chen et al. 2023) uses a fast draft model to speculate tokens ahead, then uses a single parallel forward pass of the target model to verify all tokens simultaneously.
To guarantee that the output is mathematically identical to sampling from the target model , each drafted token is accepted with probability:
If token is rejected, we immediately sample a replacement token from the residual distribution without running another forward pass:
If the average acceptance rate across drafted tokens is , the expected number of tokens generated per target forward pass is:
For and , a single target verification pass emits , delivering a wall-clock speedup with zero accuracy loss.
Interactive Roofline & Quantization Simulator
Explore the H100 roofline model below for a 70B parameter model. Notice how weight quantization shifts the operating point along the memory-bandwidth slope at small batch sizes:
GPU Roofline & Quantization Throughput Simulator (LLaMA-3 70B on H100 SXM)
Adjust the concurrent batch size and weight precision (FP16 vs. INT8 vs. INT4 AWQ) to see where autoregressive decoding transitions from the HBM memory-bandwidth slope to the Tensor Core compute ceiling.
Distributed Training Memory: The 16Ψ Rule & ZeRO
Training a model with parameters in mixed precision (BF16 weights/gradients + FP32 AdamW master states) requires 16 bytes per parameter before activations:
- Parameters (
BF16): - Gradients (
BF16): - AdamW Master Weights, Momentum , and Variance (
FP32):
For a 70B model (), static states alone require —exceeding a single 80 GB GPU by . ZeRO / FSDP (Rajbhandari et al. 2020) eliminates replication across data-parallel ranks:
| Sharding Stage | Partitioned States Across | Per-GPU Memory Formula | 70B Footprint () | Communication Volume / Step |
|---|---|---|---|---|
| Baseline DDP | None (Full replication) | (OOM) | (AllReduce gradients) | |
| ZeRO-1 | Optimizer states () | (OOM) | (ReduceScatter + AllGather) | |
| ZeRO-2 | Optimizer + Gradients () | (OOM) | (ReduceScatter + AllGather) | |
| ZeRO-3 / FSDP | Optimizer + Grads + Params () | (Fits easily) | ( baseline for forward/backward AllGather) |