Part I Foundations¶
Part I moves from left to right across this picture: one chip and its memory first, then the network of chips, then the software that reaches them from PyTorch.
Part I gives you the model of the machine that every later Part assumes. You will not run a training job or a server here. You will learn what a TPU chip is made of, how to tell from arithmetic alone whether an operation is limited by compute or by memory, how a PyTorch call becomes a TPU program, and the four places where TorchTPU behaves differently from the CUDA backend you know: when work runs, where tensor bytes live, what precision the matrix unit computes in, and why tensor shapes decide how often the compiler runs.
Readers who skip this Part tend to meet it later as a symptom: a model that is slower than expected, a loss curve that drifts from the GPU baseline, or a serving step that recompiles on every request. Each of those has its explanation in one of the seven chapters below.
The chapters¶
| Chapter | Summary | Reading time (min) |
|---|---|---|
| 1. TPU hardware for PyTorch engineers | What is inside a TPU chip, how chips are connected, and what the numbers on a spec sheet mean for a model. | 30 |
| 2. Rooflines and arithmetic intensity | Deciding from arithmetic alone whether an operation on a given chip is limited by compute or by memory bandwidth. | 25 |
| 3. The TorchTPU stack and the CUDA translation table | The layers between torch.matmul and the MXU, and the TPU name for each CUDA concept you already use. |
30 |
| 4. Execution model: eager modes, deferred ops, torch.compile | When work actually runs on the TPU, and how the three eager modes and torch.compile differ. |
30 |
| 5. Memory model, storage and views | Where a tensor's bytes live, and why a view that is free on GPU can cost a copy on TPU. | 35 |
| 6. Numerical precision and the MXU | The precision the matrix unit computes in, and how to tell a precision effect from a bug. | 30 |
| 7. Dynamic shapes and recompilation | Why a changing shape triggers a new compilation, and how bounded dynamism avoids it. | 35 |
Read end to end, Part I takes about three and a half hours, plus the worked problems.
What links them¶
The chapters form one argument, and each answers a question the previous one raises.
The hardware sets the costs (chapters 1 and 2). Chapter 1 describes a chip as a matrix unit (the MXU) and a vector unit (the VPU) fed from a small on-chip scratchpad (VMEM), which is fed in turn from high-bandwidth memory (HBM), with chips joined to their neighbours by ICI and to other slices by DCN. Each of those links has a bandwidth, and the MXU has a peak rate. Chapter 2 turns those numbers into a single test, the roofline, that says which resource an operation will run out of first. Every performance argument in Parts III to V is a roofline argument.
The software decides how the hardware is used (chapter 3). A TPU is programmed through the XLA compiler, not through hand-written device code launched one kernel at a time. Chapter 3 lays out the layers TorchTPU adds between PyTorch and XLA, and maps each CUDA habit to its TPU counterpart.
Four consequences of a compiler-driven device (chapters 4 to 7). Because XLA compiles programs with known shapes and the device runs asynchronously from the host:
- the moment work runs depends on the execution mode, and a call such as
.cpu()or.item()is where the host waits (chapter 4); - StableHLO has no in-place mutation, so PyTorch view semantics are rebuilt on top of it, and some views cost more than they do on GPU (chapter 5);
- the MXU multiplies in bf16 and accumulates in fp32, so numerical results can differ from a GPU run for reasons that are not bugs (chapter 6);
- a new shape means a new program, so shape changes cause recompilation unless the shape is bounded in advance (chapter 7).
Every arrow joins a chapter to the next one or to the one after that, and nothing reaches further: the vertical arrows are the chapter just before, the horizontal ones the chapter before that. Read Part I in order.
Part I is a chain: each chapter builds on the one or two chapters just before it, so read them in order. Chapter 3 uses the roofline of chapter 2 to explain why fusion matters, chapter 4 times an operation with that roofline, chapter 6 needs the tile model of chapter 5, and chapter 7 needs both the in-place cache writes of chapter 5 and the precision controls of chapter 6.
What this Part covers¶
- The parts of a TPU chip (MXU, VPU, VMEM, HBM, ICI) and the path data takes through them for a matmul.
- Whether a matmul of a given shape is compute-bound or memory-bound on a given chip generation, and the arithmetic that decides it.
- The layer of the stack where an ATen operation becomes StableHLO.
- Where a script waits for the TPU, which tensor operations may copy, why a bf16 result differs from an fp32 reference, and which input shapes trigger a recompile.
Part II then puts this model to work: getting TPU capacity, installing TorchTPU and porting a real model.

