Inference & Training Efficiency

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:

  1. Prefill (Compute-Bound): Processing an input prompt of tokens in parallel performs FLOPs while reading the byte weight matrix once, yielding .
  2. 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 / MetricUnits / DomainHardware & 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)

1. Fast Draft Model q (1B Params) — Serial Speculation (K = 4 Steps, ~2 ms Total)Draft 1: "return"Draft 2: "x"Draft 3: "+"Draft 4: "2" (p/q = 0.15)2. Target Model p (70B) — Single Parallel Forward Pass Verifies All 4 Tokens SimultaneouslyAccept "return"p/q = 1.05 ≥ 1Accept "x"p/q = 0.96 ≥ uAccept "+"p/q = 1.02 ≥ 1Reject "2" → Resample "1"Emits 4 Exact Tokens in 1 Pass
Figure 1: Verifying draft tokens in parallel costs the same HBM weight read as generating 1 token. Even when Draft 4 is rejected, the target model's logits at position 4 immediately yield a corrected token ("1") from , producing 4 valid tokens in a single 70B 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.

8
Precision: FP16 (16-bit)
Arithmetic Intensity I (FLOPs / Byte, log scale)TFLOP/sRidge (295 FLOPs/B)HBM Bandwidth SlopeCompute CeilingI = 8.0 FLOPs/B
Model Weight Footprint in HBM 140.0 GB
Every decode step streams the entire weight matrix across the HBM3 bus.
Arithmetic Intensity & Compute Util 8.0 FLOPs/B (2.7% Util)
Memory-Bandwidth Bound: Tensor Cores sit idle 97.3% of the time waiting on HBM weight reads.
System Decode Throughput 191 tokens/sec
Per-user speed: 23.9 tok/s ( = 41.8 ms).
Memory-Bound Decode
Batch B:

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 StagePartitioned States Across Per-GPU Memory Formula70B Footprint ()Communication Volume / Step
Baseline DDPNone (Full replication) (OOM) (AllReduce gradients)
ZeRO-1Optimizer states () (OOM) (ReduceScatter + AllGather)
ZeRO-2Optimizer + Gradients () (OOM) (ReduceScatter + AllGather)
ZeRO-3 / FSDPOptimizer + Grads + Params () (Fits easily) ( baseline for forward/backward AllGather)

Key Papers & References