Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorChris Fregly

Elevate your AI system performance capabilities with this definitive guide to maximizing efficiency across every layer of your AI infrastructure. In today's era of ever-growing generative models, AI Systems Performance Engineering provides engineers, researchers, and developers with a hands-on set of actionable optimization strategies. Learn to co-optimize hardware, software, and algorithms to build resilient, scalable, and cost-effective AI systems that excel in both training and inference. Authored by Chris Fregly, a performance-focused engineering and product leader, this resource transforms complex AI systems into streamlined, high-impact AI solutions. Inside, you'll discover step-by-step methodologies for fine-tuning GPU CUDA kernels, PyTorch-based algorithms, and multinode training and inference systems. You'll also master the art of scaling GPU clusters for high performance, distributed model training jobs, and inference servers. The book ends with a 175+-item checklist of proven, ready-to-use optimizations. Codesign and optimize hardware, software, and algorithms to achieve maximum throughput and cost savings Implement cutting-edge inference strategies that reduce latency and boost throughput in real-world settings Utilize industry-leading scalability tools and frameworks Profile, diagnose, and eliminate performance bottlenecks across complex AI pipelines Integrate full stack optimization techniques for robust, reliable AI system performance

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# AI Systems Performance Engineering: Optimizing Model Training and Inference Workloads with GPUs, CUDA, and PyTorch ## 【One-Line Pitch】 A comprehensive, hands-on guide for engineers and researchers who want to squeeze maximum performance from AI systems by co-optimizing GPU hardware, CUDA kernels, PyTorch code, and distributed infrastructure—from single-GPU tuning to multi-node cluster scaling. ## 【Book Arc】 - **Opening (~0%–9%)**: Introduces the book's mission—co-optimizing hardware, software, and algorithms for AI training and inference—and previews advanced inference topics like dynamic/continuous batching, prompt compression, prefix caching, and disaggregated prefill-decode architectures, plus a real-world case study of DeepSeek training a ~680B-parameter MoE model on export-restricted H800 GPUs. - **Early (~9%–25%)**: Dives into GPU hardware fundamentals, comparing NVIDIA architectures (Hopper H100 vs. Blackwell B200) in terms of transistors, memory, and die-to-die interconnects, then covers system-level concerns like liquid cooling for high-density racks (NVL72) and thermal throttling prevention. - **Early (~25%–34%)**: Moves to CPU/OS configuration for GPU environments: MIG partitioning, NUMA-aware CPU affinity, GPU driver settings (persistence mode, MPS), data prefetching, pinned memory, and network stack tuning for RDMA/InfiniBand. - **Middle (~34%–47%)**: Focuses on distributed training patterns—comparing PyTorch DataParallel (with its GPU 0 bottleneck) vs. DistributedDataParallel (one process per GPU)—and introduces NVIDIA's NIXL for high-throughput point-to-point transfers, NCCL for collectives, and GPUDirect Storage (GDS) for bypassing host memory in storage I/O. - **Middle (~47%–53%)**: Covers CUDA kernel launch configuration (blocks per grid, threads per block), emphasizing warp-size multiples, latency hiding, and occupancy tuning for modern GPUs like Blackwell. ## 【Key Takeaways】 - **Co-optimization across the full stack is essential** (Opening): Peak AI performance comes from aligning GPU kernels, network transfers, CPU threads, and storage—a weakness in any layer bottlenecks the whole system. (Middle) - **Hardware architecture drives optimization decisions** (Early): Understanding GPU internals—like Blackwell's dual-die design with 10 TB/s NV-HBI interconnect and 192 GB HBM3e—helps you reason about memory bandwidth and compute limits before writing code. - **Liquid cooling is mandatory for high-density AI racks** (Early): The NVL72's 130 kW power density requires liquid cooling with cold plates and Coolant Distribution Units (CDUs), keeping GPUs at 50–70°C to prevent thermal throttling and maintain max clocks. - **CPU/OS configuration matters as much as GPU code** (Early): NUMA-aware pinning (numactl, taskset), persistence mode, MPS, and MIG partitioning are low-overhead ways to reduce latency and improve throughput in multi-tenant environments. - **Data loading is a common hidden bottleneck** (Early): PyTorch's DataLoader with prefetch_factor, num_workers, and pin_memory=True enables async transfers that overlap with computation—neglecting this means GPUs sit idle waiting for data. - **Prefer DistributedDataParallel over DataParallel** (Middle): DataParallel serializes kernel launches and makes GPU 0 a gradient-aggregation bottleneck; DDP with one process per GPU overlaps communication with computation for better scaling. - **Use purpose-built libraries instead of reinventing** (Middle): NCCL for collectives (all-reduce), NIXL for point-to-point/streaming transfers (KV cache offloading), and GPUDirect RDMA/GDS to eliminate host memory bounce buffers—each is heavily tuned for its workload. - **CUDA launch configuration is a first-order performance lever** (Middle): Threads per block should be multiples of 32 (256–512 for Blackwell), balancing occupancy, register usage, and latency hiding to avoid underfilled warps. ## 【Reading Tips】 - **Skim the hardware deep-dives** (Early chapters) if you're already familiar with GPU architectures; focus instead on the practical CPU/OS configuration checklists and networking guidance. - **Deep-read the distributed training sections** (Middle) if you're scaling beyond a single GPU—the DataParallel vs. DDP comparison and NIXL/NCCL usage patterns are directly actionable. - **Pay attention to the profiling guidance** (Middle): Use Nsight Systems to identify communication-bound vs. compute-bound workloads, and Nsight Compute/PyTorch profiler for kernel-level memory and compute efficiency. - **The CUDA kernel launch configuration section** (Late Middle) is a quick win—even small adjustments to block sizes can yield measurable improvements. - **Excerpts don't cover the final chapters** on advanced prefill-decode tuning (FlashMLA, DeepSeek) or the 175-item optimization checklist in detail—consider those as reference material for later. ## 【Coverage Limits】 This guide synthesizes the first ~53% of the book (hardware, CPU/OS config, distributed training, and CUDA basics). The later chapters on disaggregated inference, KV cache tuning, and the final optimization checklist are only previewed in the table of contents and not covered in depth here. ##
Excerpt 1
720 Continuous Scheduling 721 Stall-Free Scheduling (Chunked Prefill) 723 Latency-Aware Scheduling and Dynamic Routing 724 Systems-Level Optimizations 725 Ov...
View in text
Excerpt 2
its directly on the component. A water-based coolant liquid flows through the tubing to carry away heat. All these cold plates are linked by hoses, manifolds...
View in text
Excerpt 3
important. Remember to pin the network interrupt handling— or polling threads—to a CPU core on the same NUMA node as the NIC and, ideally, the GPU as well. F...
View in text
Excerpt 4
put pipeline can’t keep up. Use the right tools for the job NCCL is designed for scalable collective (all-reduce, etc.) communication often used in model tra...
View in text
Excerpt 5
resident warps make forward progress with fewer stalls. Floating-point 15 GFLOPS 170 GFLOPS Small matrix size limits the absolute value. Reuse increases thro...
View in text
Excerpt 6
; then float v = y * d;, // the multiplies are independent. 332 | Chapter 8: Occupancy Tuning, Warp Efficiency, and Instruction-Level Parallelism Recomputati...
View in text
Excerpt 7
in different thread blocks previously could not efficiently share state and synchronize except using either global memory or grid.sync() for coarse-grained,...
View in text
Excerpt 8
nst size_t offset = static_cast<size_t>(tile) * TILE_ELEMS; // Leader block’s loader warp stages A and B once for the entire cluster if (cluster_rank == 0 &&...
View in text
Tags
AI categories
AIGPUPerformance Engineering
ISBN: 8341627779
Publisher: O'Reilly Media
Publish Year: 2025
Language: English
Pages: 1061
File Format: PDF
File Size: 12.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…