Tools for Deep Learning

Dive into Deep Learning · §39

Tools for Deep Learning: From Local Notebooks to Distributed Clusters and Serving
reproducible kernels · hosted runtimes · cloud economics · hardware rooflines · open-weight artifacts · distributed training · inference engines

Four Systems Questions Behind Every Tooling Choice

Motivation

  • 1. Does it fit in memory? Training holds parameters, gradients, optimizer moments (16N), and activations in VRAM; OOM stops a run before FLOP/s matters.
  • 2. What bounds throughput? Training and prompt prefill are compute-bound, whereas batch-1 autoregressive decoding is memory-bandwidth bound.
  • 3. Cost & Reproducibility: Optimize total cost per completed result (including setup, egress, and spot recovery) and lock environments/SHAs from cell one.

Three First-Principles Equations for Systems Sizing

Quantitative Rules

M_{\text{train}} \approx 16 N + M_{\text{act}}, \qquad \text{tok/s} \lesssim \frac{\beta}{B_w + b n B_{\text{kv}}}

  • Training state & compute (§39.2, §39.4, §39.6): Mixed-precision Adam uses 16\text{ B/param} and C \approx 6ND\text{ FLOPs} across N parameters and D tokens.
  • Decode & checkpoint intervals (§39.2–39.7): Batch-1 decode streams B_w + B_{\text{kv}} at bandwidth \beta, and Young’s law checkpoints every \tau^* = \sqrt{2\delta M}.

Roadmap of Chapter 39: From Laptop to Production

Chapter Architecture

  • §39.1–39.3 Notebooks, Hosted VMs & Cloud: Kernel state discipline, uv lock files, Colab/Kaggle persistence, and cloud cost per completed result.
  • §39.4–39.5 Hardware & Ecosystem: Capacity vs. bandwidth rooflines, unified memory for MoE, Arena Elo resolution, and safetensors/SHA pinning.
  • §39.6–39.9 Scaling, Serving & D2L Internals: DDP/FSDP2, 3D parallelism, continuous batching, PagedAttention, and the D2L single-source build.

Concrete Worked Benchmarks Across the Chapter

Pedagogical Thread

  • Reproducible setups & economics (§39.1–39.3): uv pip sync, environment fingerprints, and engineer-inclusive cloud cost models across 4090 / A100 / H100.
  • Sizing & verification (§39.4–39.5): 7B training memory (86\text{ GiB} vs. 4\text{ GiB} QLoRA), decode bounds, Bradley-Terry SE (347/\sqrt{v}), and frozen manifests.
  • Distributed training, serving & the build (§39.6–39.8): 8-GPU FSDP2 (22\text{ GiB} vs. 95\text{ GiB} DDP), continuous batching simulators, and prefix output hashing.

How to Navigate This Chapter and Stay Current

Study Guide

  • Immediate setup (§39.1–39.2): Start here to run the book’s notebooks locally with uv or on Colab and Kaggle without losing work to ephemeral sessions.
  • Infrastructure decisions (§39.3–39.5): Read these sections before renting cloud GPUs, building a workstation, or adopting an open-weight checkpoint from Hugging Face.
  • Scaling and contributing (§39.6–39.9): Study §39.6–39.7 alongside Chapter 13 (Computational Performance) for multi-GPU training and LLM serving, §39.8 to contribute to D2L, and §39.9 for d2l utilities.
  • Companion references: Pair this chapter with DeepMind’s How to Scale Your Model, Hugging Face’s Ultra-Scale Playbook, and Stanford CS336.

Up next (§39.1 Notebooks): How the Jupyter kernel execution model works, why hidden state breaks reproducibility, and how to set up deterministic local environments with uv.