39 Tools for Deep Learning
Most readers first run this book’s code on a laptop or in a browser tab: open a notebook, run the cells, change the learning rate, and run them again. Sooner or later something no longer fits. A model needs more memory than the laptop has, a training run would take a week, or an open language model downloaded for a weekend project writes three words per second. Each of these looks like a question about which product to use. Underneath, the same few questions recur: does the job fit in memory, what limits its speed, and what will a finished result cost?
Products change within months, but the answers rest on a few rules that last longer. Memory decides what can run at all, so we check that a job fits before we make it faster. When a language model generates text, it reads every weight it uses from memory once for each new token, so memory bandwidth sets the speed of generation. The cheapest machine per hour does not give the cheapest experiment if it runs the job more slowly or the job fails partway, so we compare the cost of a completed result. And a result that cannot be rerun from what was recorded cannot be checked or built on, so reproducibility belongs to the workflow from the first cell. In Chapter 13 a program was limited by its arithmetic, by its memory bandwidth, or by the overhead of issuing operations. These rules apply that model to the decisions of what to run, rent, buy, and deploy.
Section 39.1 asks how to run the book’s notebooks locally so that a result does not depend on hidden state. Section 39.2 asks how to run them with nothing installed, on Colab or Kaggle. Section 39.3 asks when to rent an accelerator and how to count what a run costs. Section 39.4 asks which hardware to buy, given what limits the workload. Section 39.5 asks where to find models, datasets, and benchmarks, and how to judge and record them. Section 39.6 asks how to spread training over several accelerators when one is not enough. Section 39.7 asks how to serve a model to many users at once. Section 39.8 asks how this book is built from its sources and how to propose a change to it.
Prices, product names, quotas, and library versions change quickly. The sections that quote them give the date of each quote; check them before use.
The generated utility and d2l API documents remain searchable HTML reference pages. They are not part of the teaching sequence or the PDF edition.
Resources and Further Reading
The resources below accompany the sections of this chapter, from working on one machine to training and serving at scale. All are freely accessible online.
Systems and scaling
- How to Scale Your Model — Austin et al., Google DeepMind (2025) — an online book on predicting performance before measuring it: rooflines, TPU and GPU anatomy, parallelism, and inference arithmetic, worked out with numbers for Section 39.4, Section 39.6, and Section 39.7.
- The Ultra-Scale Playbook — Hugging Face (2025) — a guide to training on GPU clusters, based on more than 4,000 measured runs on up to 512 GPUs; it extends Section 39.6 with detailed memory budgets and parallelism trade-offs.
- Stanford CS336: Language Modeling from Scratch — lectures on YouTube and assignments on GitHub that build a language model end to end, from tokenization through distributed training and inference; a course companion to Section 39.6 and Section 39.7.
- GPU MODE lectures — videos, slides, and notebooks from CUDA fundamentals through FlashAttention and quantization, for readers who want to write the kernels whose limits Section 39.4 estimates.
Performance thinking
- Making Deep Learning Go Brrrr From First Principles — Horace He (2022) — a short essay that divides a program’s time into compute, memory bandwidth, and overhead, the division behind Section 39.4.
- Transformer Inference Arithmetic — kipply (2022) — KV-cache sizes and the bandwidth limit of decoding worked out by hand, the estimates behind Section 39.4 and Section 39.7.
- Accelerating Generative AI with PyTorch II: GPT, Fast — PyTorch team (2023) — with the gpt-fast code; an inference speedup of almost 10× built step by step in under 1,000 lines of PyTorch, using compilation, quantization, speculative decoding, and tensor parallelism.
- Which GPU for Deep Learning? — Tim Dettmers (2023) — last updated in January 2023, so its hardware examples are dated, but its method for choosing a GPU from the workload complements Section 39.4.
Surveys
- A Survey on Efficient Inference for Large Language Models — Zhou et al. (2024) — a taxonomy of data-, model-, and system-level inference optimizations, with comparative experiments on representative methods; background for Section 39.7.
- A Survey on Large Language Model Acceleration Based on KV Cache Management — Li et al. (2024) — methods for storing, compressing, and evicting the KV cache that Section 39.7 introduces, with a curated paper list.
Staying current
- r/LocalLLaMA and the llama.cpp discussions — release reports, quantization results, hardware measurements, and reproduction attempts; Section 39.5 describes how to weigh such sources.
- Pro Git — Chacon and Straub — a free book whose chapters 1–3 and 6 cover the Git and pull-request workflow that Section 39.8 assumes.