Key points
This post is a comprehensive engineering reference on GPU cluster training and inference acceleration for large language models, organized in two major parts.
Part 1: GPU Cluster Training Optimization
1. VRAM footprint and memory management
- With AdamW + FP16/BF16 mixed precision, model states cost
16Φbytes per Φ billion parameters (2Φ weights + 2Φ gradients + 12Φ optimizer states). A 70B model therefore needs ~1.12 TB just for parameters and optimizer states, before activations and KV-cache. - Three core memory-saving pillars:
- Activation checkpointing (rematerialization): drop forward activations and recompute them during backward — trades ~20–30% extra compute for 70%+ activation memory savings.
- FlashAttention-2/3: tiled softmax computed in on-chip SRAM, avoiding writing the N×N attention matrix to HBM; memory complexity drops to O(N).
- CPU/NVMe offloading: sink inactive optimizer states to host memory.
- FP32 (1/8/23 bits) vs FP16 (1/5/10, overflow-prone) vs BF16 (1/8/7, same dynamic range as FP32) vs FP8 (E4M3 for forward/weights, E5M2 for backward gradients).
- FP16 requires dynamic loss scaling (e.g., multiply loss by 2^16 before backward). BF16 is now the standard on Ampere/Hopper (A100/H100/H800/H20) with no loss scaling needed. Includes a native PyTorch
torch.cuda.amp.autocast(dtype=torch.bfloat16)example. - ZeRO-1: partition optimizer states — 4× memory savings, unchanged communication.
- ZeRO-2: additionally partition gradients via Reduce-Scatter — 8× savings.
- ZeRO-3: partition parameters too, fetching via All-Gather per layer — per-GPU memory falls to
16Φ / N_GPUs. - Includes a production
ds_config.jsonwithstage: 3,overlap_comm, and CPU optimizer offloading. - Splits layers across GPUs; batches are split into m micro-batches to keep the pipeline full.
- Bubble ratio:
F_bubble = (p − 1) / (m + p − 1) ≈ (p − 1) / m. - 1F1B scheduling keeps activation lifetimes short (fixing GPipe's activation blowup); Interleaved 1F1B with v virtual stages compresses bubbles to
(p−1)/(v·m), pushing bubble overhead below 10%. - AWQ: protects the top 1% salient channels via per-channel scaling based on activation distributions; near-lossless 4-bit quality — the top choice for LLM deployment.
- GPTQ: second-order (inverse Hessian) error compensation per row; good for large offline batch quantization but sensitive to activation outliers.
- FP8 (W8A8): native 8-bit Tensor Core matmul on Ada/Hopper — maximum throughput with no dequantization overhead.
- Classic KL-divergence soft-label distillation has evolved into long chain-of-thought trajectory distillation: a 671B reasoning model (e.g., DeepSeek-R1 style) generates detailed
<think>...</think>traces on millions of math/code problems, and small models (1.5B–32B) are SFT-trained on these traces — inheriting deep reasoning without expensive RL. - A draft model generates K candidate tokens; the target model verifies all K in one parallel forward pass, accepting ~2–3 tokens per step.
- Acceptance rule:
P(accept) = min(1, P_Target(x) / P_Draft(x))— the modified rejection sampling guarantee makes output distribution mathematically identical to pure target-model generation. - Medusa / EAGLE: self-speculative multi-head variants requiring no separate draft model.
- Orca-proposed, vLLM-popularized iteration-level scheduling: finished requests are evicted and new requests inserted at each token step, eliminating padding waste and head-of-line blocking of static batching; 3–5× serving throughput.
- Chunked prefill interleaves long-prompt chunks with decode steps to flatten TTFT spikes.
2. Mixed precision training
3. ZeRO (Zero Redundancy Optimizer, DeepSpeed)
4. Pipeline parallelism
Part 2: Industrial-Grade Inference Acceleration
5. Quantization
6. Knowledge distillation
7. Speculative decoding
8. Continuous batching
Practical tuning decision matrix
| Bottleneck | Recommended stack | Expected gain | | :--- | :--- | :--- | | OOM training 70B+ models | ZeRO-3 + activation checkpointing + BF16 | Break memory wall, near-linear cluster scaling | | High TTFT | Chunked prefill + FlashAttention-3 | Smooth long-input spikes | | Low throughput / high cost | vLLM (continuous batching + PagedAttention) + AWQ 4-bit | 4–8× concurrency, ~65% VRAM reduction | | Slow token-by-token latency | Speculative decoding (EAGLE-2 / Medusa) + FP8 | 2–3.5× speedup, lossless quality |
References
1. ZeRO: *Memory Optimizations Toward Training Trillion Parameter Models* (SC'20) — arXiv:1910.02054 2. FlashAttention-2: *Faster Attention with Better Parallelism and Work Partitioning* (ICLR 2024) — arXiv:2307.08691 3. AWQ: *Activation-aware Weight Quantization for On-Device LLM Compression and Acceleration* (MLSys 2024) — arXiv:2306.00978 4. Speculative decoding: *Fast Inference from Transformers via Speculative Decoding* (ICML 2023) — arXiv:2211.17192 5. Orca: *A Distributed Serving System for Transformer-Based Generative Models* (OSDI 2022)
Original post image: