From Fundamentals to Production-Grade Systems
Introduction
- Who This Book Is For
- How This Book Is Organized
- A Note on Tools and Versioning
- How to Read This Book
Chapter 1: The Anatomy of a Single Request
- From HTTP Request to Generated Token: The Complete Lifecycle
- Tokenization: The Hidden Cost Before Computation Begins
- Prefill: Processing the Input Prompt in One Pass
- Decoding: Generating Tokens One at a Time
- The Key-Value Cache: Trading Memory for Recomputation
- Latency Budgets: TTFT, TPOT, and What They Mean for Users
- Summary
Chapter 2: Measuring What Matters
- Latency Metrics That Actually Inform Decisions
- Throughput vs Latency: The Fundamental Trade-off
- Utilization Metrics: GPU Compute and Memory Bandwidth
- Queueing Theory for Inference Systems
- Profiling Fundamentals: Traces, Metrics, and Flame Graphs
- Building a Baseline Benchmark Harness
- Summary
Chapter 3: GPU Architecture for Inference
- The GPU as a Parallel Compute Engine
- Memory Hierarchy: Registers, Shared Memory, Global Memory, HBM
- CUDA Concepts Relevant to Inference
- Why LLMs Are Memory-Bound (Mostly)
- The NVIDIA GPU Lineup for Inference
- Beyond NVIDIA: AMD, Intel, and Custom Silicon
- Summary
Chapter 4: The CPU-GPU Interface
- Data Movement Patterns in Inference
- PCIe Bandwidth and Latency
- Pinned Memory and Asynchronous Transfers
- Zero-Copy and Unified Memory Considerations
- Kernel Launch Overhead and CUDA Graphs
- Summary
Chapter 5: Batching and Scheduling
- Static Batching: Simple but Wasteful
- Continuous Batching (vLLM-style): The Breakthrough
- Dynamic Batching and Micro-batching
- Scheduling Policies: Fairness, Priority, and Latency
- Preemption and Speculative Execution
- Implementing a Scheduler: Design Decisions
- Summary
Chapter 6: Memory Management for LLMs
- KV Cache Size Calculations and Capacity Planning
- PagedAttention and Block Management (vLLM)
- Prefix Caching for Shared Contexts
- KV Cache Eviction Policies
- Quantization: Compressing Weights and Activations
- Memory Fragmentation and Defragmentation
- Summary
Chapter 7: Advanced Decoding Strategies
- Sampling Methods and Their Latency Impact
- Speculative Decoding: Drafting Faster Than Verifying
- Medusa and Multi-Token Prediction Heads
- Early Exit and Layer Skipping
- Repetition Handling and Stopping Criteria
- Summary
Chapter 8: Parallelism Strategies for Large Models
- Tensor Parallelism: Splitting Matrices Across GPUs
- Pipeline Parallelism: Splitting Layers Across GPUs
- Data Parallelism for Inference: When and Why
- Sequence (Context) Parallelism: Splitting Long Prompts
- Expert Parallelism for Mixture-of-Experts Models
- Hybrid Parallelism: Combining Strategies
- Summary
Chapter 9: Multi-GPU and Multi-Node Systems
- NVLink and NVSwitch: Intra-Node Communication
- InfiniBand and RoCE: Inter-Node Communication
- NCCL and Collective Communication
- Topology-Aware Placement and Scheduling
- RPC Frameworks for Distributed Serving
- Fault Tolerance in Distributed Inference
- Summary
Chapter 10: Building an Inference Server
- From Single-Model Script to Production Server
- API Design: OpenAI-Compatible Endpoints and Beyond
- Streaming Responses: Why and How
- Choosing an Inference Engine: vLLM vs SGLang vs TensorRT-LLM vs llama.cpp
- Containerization and Deployment Basics
- Warmup, Preflight, and Readiness Probes
- Summary
Chapter 11: Cluster-Scale Serving
- Load Balancing Strategies for Inference Traffic
- Request Routing: Model Selection and Workload Segmentation
- Admission Control and Backpressure
- Autoscaling: Signals, Policies, and Pitfalls
- Multi-Model Serving on Shared Infrastructure
- Kubernetes and GPU Orchestration
- Summary
Chapter 12: Disaggregated Architectures
- Why Disaggregate Prefill and Decode?
- Architecture of a Disaggregated System
- Implementations and Research
- Trade-offs and Complexity
- Distributed Caching Layers
- Summary
Chapter 13: Reliability and Observability
- Health Checking and Readiness for GPU Services
- Distributed Tracing for Inference Requests
- Metrics That Matter in Production
- Graceful Degradation Under Load
- Retry Logic, Timeouts, and Circuit Breakers
- Incident Response and Debugging GPU Failures
- Summary
Chapter 14: Capacity Planning and Cost Optimization
- Workload Characterization: Understanding Your Traffic
- Capacity Calculations: From Tokens to GPUs
- Cost Per Token and Cost Per Request Modeling
- Right-Sizing Hardware for Your Workload
- Performance Regression Testing
- Summary
Chapter 15: Extremely Low-Latency Serving
- Sub-100ms TTFT: Is It Achievable?
- Real-Time Conversational and Voice Workloads
- CUDA Graphs and Kernel Fusion at Scale
- Communication/Computation Overlap in Distributed Systems
- Edge and On-Device Inference for Ultra-Low Latency
- Summary
Chapter 16: Specialized Workloads and Emerging Techniques
- Long-Context Inference (100K+ Tokens)
- Reasoning Models with Variable Output Lengths
- Multimodal Inference: Images, Audio, and Video
- High-Concurrency Serving Patterns
- Heterogeneous GPU Fleets
- Inference-Aware Model Optimization
- Summary
Chapter 17: End-to-End Reference Architectures
- Architecture A: Single GPU Prototype (Proof of Concept)
- Architecture B: Single Multi-GPU Server (Small Team Production)
- Architecture C: Small Cluster (Startup/SMB Production)
- Architecture D: Geographically Distributed Platform (Enterprise Scale)
- Summary
Chapter 18: Designing Low-Latency LLM Systems from First Principles
- Requirements Gathering and Workload Characterization
- Latency Budget Construction
- Architecture Selection Decision Tree
- Hardware Sizing and Procurement Strategy
- Implementation Sequencing: Build in Stages
- Optimization Priorities: Where to Spend Your Time
- Production Readiness Checklist
- Summary
Chapter 19: Conclusion: Enduring Principles for a Fast-Changing Field
- The Core Mental Models
- Where LLM Infrastructure Is Heading
- A Note on Engineering Philosophy
- Closing Thoughts