27 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.
The chapter moves from a single interactive notebook to multi-machine training and production serving. We begin with where code runs day to day: managing Jupyter kernel state and local uv environments so results do not depend on hidden execution history (Section 27.1), running notebooks with zero local setup on Colab and Kaggle (Section 27.2), and pricing rented cloud accelerators by the total cost of a completed result (Section 27.3). Next, we turn to hardware and external artifacts: choosing what to buy from memory capacity, bandwidth, and compute bounds (Section 27.4), and discovering, evaluating, pinning, and licensing pretrained models and datasets from public hubs (Section 27.5). Finally, we scale across machines and contributors, partitioning training across multiple accelerators (Section 27.6), serving concurrent users under latency targets (Section 27.7), and seeing how this book itself is built and maintained from single-source Markdown files (Section 27.8).
Prices, product names, quotas, and library versions change quickly. The sections that quote them give the date of each quote; check them before use.
- 27.1 Notebooks
- 27.2 Colab and Kaggle
- 27.3 Cloud Computing
- 27.4 Hardware
- 27.5 Ecosystem
- 27.6 Distributed Model Training
- 27.7 Model Serving
- 27.8 Contributor Guide
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, covering rooflines, TPU and GPU anatomy, parallelism, and inference arithmetic worked out with numbers for Section 27.4, Section 27.6, and Section 27.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 27.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 27.6 and Section 27.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 27.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 27.4.
- Transformer Inference Arithmetic — kipply (2022): KV-cache sizes and the bandwidth limit of decoding worked out by hand, the estimates behind Section 27.4 and Section 27.7.
- Accelerating Generative AI with PyTorch II: GPT, Fast — PyTorch team (2023): accompanied by 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 27.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 27.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 27.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 27.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 27.8 assumes.