Preface
- Why build it at all
- Gates that are commands
- How the claims are checked
- Who this book is for
- About the code
- About the numbers
- What this volume covers
- Foundations
Before Any Code
- The rules of the build
- Fourteen crates, all empty
- The oracle
- Reading NumPy’s file format
- An error type before a tensor
- One command for the gate
- Every check on, before there is anything to check
- What the gate measured
- Phase 1’s gate, written in Phase 0
- What Phase 1 inherits
A Tensor Is a Shape, Some Strides, and a Pointer
- Six fields, one of which holds numbers
- Where the numbers live
- Lying about the strides
- The contiguity fast path
- Testing arithmetic nobody can enumerate
- One kernel, six types
- The two operations that decide whether an agent learns
- Owning the random numbers
- The gate
- What the tensor does not do yet
- Arithmetic and Derivatives
Kernels That Are Obviously Correct
- One thread, on purpose
- The machinery every kernel shares
- Formulas that are correct and still wrong
- An error function from 1969
- Two tensors at once
- Why
a + bdoes not compile - Writing in place
- The slowest matrix multiply I could defend
- What the baseline says
- Testing without a second implementation
- What Phase 2 leaves for autograd
Derivatives You Can Check
- The checker comes first
- The tape is an array
- The chain rule is a sum
- Broadcasting, backwards
- Derivatives that do not exist
- Where activation memory goes
- What the phase shipped
- What Chapter 5 inherits
- Learning
Layers, Optimizers, and Ninety-Eight Percent
- The gate, and why it is a number
- A parameter that never trains
- A parameter is not a tensor
- The mode is an argument
- What an optimizer does
- Cross-entropy is two functions fused
- Ninety-eight percent
- The golden run
- The cheap tests that name the cause
- What the phase leaves for the next one
- Speed
A Matrix Multiply Within Reach of OpenBLAS
- The reference that was the wrong reference
- Every stage stays in the tree
- Sixteen times from swapping two loops
- The stage that made it slower
- Packing: the copy that pays for itself
- Lane selection instead of broadcasting
- Miri and the new
unsafe - Threading is a cache decision
- The pool nobody needed
- Against the gate
- What the phase leaves for Chapter 7
Convolutions, and Ninety-Three Percent on CIFAR-10
- What a convolution does
- A convolution is a matrix multiply
- Going backwards, the copies add
- Normalization, and the conventions that cost twenty points
- ResNet-18 for a 32-pixel image
- Sixteen seconds a step
- Three elementwise functions
- Finishing the first push
- The profiler that counted threads
- Welford, threaded rather than replaced
- Packing cost more than multiplying
- A refusal is not a fallback
- Two things I costed instead of building
- Where it stopped
- Ninety-three point two six
- What the gate does not prove
- What the next phase inherits
- Plumbing
A Resume That Is Bit-Identical
- Why the gate asks for zero
- A loader whose output ignores its threads
- Samplers, and checking a bound once
- A file format that someone else can read
- What a checkpoint has to hold
- Making a passing gate mean something
- The gate failed
- The state that wasn’t a parameter
- Moving the state instead of extending the machinery
- A log that survives the crash
- What the gate does and does not prove
- What this leaves for Chapter 9
- Reinforcement Learning
The One Place With an Exact Answer
- Reinforcement learning from nothing
- Two traits, on purpose
- Two booleans
- GridWorld
- The exact answer
- Learning from experience
- The gate
- A random agent, and an identity instead of a range
- Turning a trajectory into a target
- Classic control, matched to Gymnasium
- Wrappers, and the clip that could never fire
- The parallel environments that made it slower
- The same table, balancing a pole
- What the table cannot do
DQN, and the End of Exact Answers
- From a table to a network
- The buffer
- The target network, and the clone that is not a copy
- Exploration as a value
- The skeleton every later algorithm plugs into
- The agent
- The two checks the plan asked for
- The first run passes by a tenth
- A result below random
- An exact answer after all
- The policy that does not stay learned
- The gate
- Two controls, and one of them does not fail
- An impossible number, and the next phase
Appendix A: Vocabulary
- What the thing is trying to do
- The data structure
- Making it learn
- The training loop
- Whether it worked
- The layers
- The datasets and the gates
- The performance words
- Deep reinforcement learning
Appendix B: Reproducing the Results
- Everything CI runs
- Chapters 1 to 4: the tensor, the kernels and autograd
- Chapter 5: MNIST
- Chapter 7: CIFAR-10
- Chapter 8: checkpoints
- Chapter 9: environments and tabular RL
- Chapter 10: DQN
- The book’s own check
- A note on hardware