Skip to content

Part VII Extending the stack

Cover art: a software stack of four slabs, with one new module dropping into an open slot and another already attached to the bottom slab.

The blue slab at the bottom is torch_tpu and the layers above it are the engines and routers built on it. One new piece is about to drop into a slot an upper layer left open for it, and another already extends the bottom layer and has passed its check. The ruler on the left is the Part's rule: every new piece is measured before it stays.

Parts I to VI used the stack as it ships: you ran models on TorchTPU, profiled them, fixed what the profile showed, scaled them out, served them, and learned to prove that the numbers were right and the speed was real. Part VII is for the day the stack does not do what your model needs. An ATen op has no TPU lowering and the run stops with NotImplementedError. A serving engine's upstream code assumes CUDA in one function. A new architecture has to train in TorchTitan's TPU lane. A router should prefer the replica whose compiled shapes fit the request. Each of these is fixed by adding code to one of the five repositories, at the place that repository has set aside for it, with the tests and CI gates that repository expects.

This Part is about building. The chapters cover the extension points, the contracts behind them and a method for using them, and they end with design exercises: a lowering, a patch, a hook, a model port, a scorer, or an agent-driven optimization loop. The gates of Part VI are what make that safe. Nothing you build here is finished until a parity test with a negative control says it computes the right thing and, where you claim speed, a benchmark you can defend says it is faster.

The chapters

Chapter Summary Reading time (min)
25. Extending the stack: ATen lowerings, patch registry, plugins Where a change to the TorchTPU stack belongs; adding an op lowering, a vLLM-TorchTPU patch, an SGLang-TorchTPU hook, a TorchTitan model or an llm-d scorer; and proving it works and keeps working. 45
26. Agent-driven workflows with the TPU Agent Suite What the TPU Agent Suite is, how its onboard, parity, profile, roofline and kernel ladder reuses this book's methods, which gates keep an agent honest, and how to decide which of its results to trust. 45
Appendix: conclusions and further reading What the whole book adds up to, and where to read next. short
Appendix: production readiness checklist Engineering capabilities by area, each with the evidence that shows it and the chapter that covers it. short

Chapters 25 and 26 take about 90 minutes to read, plus the time for their design exercises; the appendix pages are short and meant to be returned to.

Both chapters extend the stack through the doors it already has. Chapter 25 is the manual version. It maps the extension points of all five repositories (torch_tpu, vLLM-TorchTPU, SGLang-TorchTPU, TorchTitan's TPU lane and the llm-d EPP), shows how an ATen op reaches the TPU and what happens when none is registered, and walks through each repository's registration mechanism and contribution workflow with the exact commands from its contributing guide. Chapter 26 hands the same kind of work, onboarding a model, checking parity, profiling, reading the roofline and tuning a kernel, to the TPU Agent Suite's specialist agents behind its one router skill, runs the CPU-checkable half of that ladder from this repository, and accepts what the agents return only on the evidence of their artifacts, not their summaries. It ends with a design exercise: an agent workflow for your own model, gates first.

Correctness first, then speed, in both. Chapter 25's method is parity test first, then the smallest change at the layer that owns the defect, then proof that the change is exercised, and only then a performance claim. Chapter 26's agents follow the same ladder, and its gates (schema-valid requests, a module-level parity rule, a bounded kernel loop that never measures a candidate that failed parity, a noise floor that refuses to record a win inside the measured noise) are Part VI's gates run by a machine; its companion script shows a deliberately broken parity step blocking the whole pipeline. You will recognize chapter 23's negative controls and chapter 24's steady-state measurements in both.

What each chapter reuses. Chapter 25 reuses the Pallas bridge of chapter 12, the deferred execution model of chapter 4, the vLLM-TorchTPU and SGLang-TorchTPU runtimes of chapters 18 and 19, the EPP of chapter 20 and the TorchTitan lane of chapter 14. Chapter 26 reuses the porting checklist of chapter 9, the profiles of chapter 10, the rooflines of chapter 2, the kernels of chapter 12, and the parity and performance gates of chapters 23 and 24.

A map of Part VII. A note at the top left reads From earlier Parts. Top row, right of the reuse column: dashed stub boxes 12 Pallas kernels and 23 Correctness. Below 12 sits 25 Extending the stack; a solid arrow runs straight down from 12 into it, and a solid arrow from 23 turns left into its top. To the right of 25, below 23, sits the dashed stub 24 Performance evidence; a dashed arrow runs left from 24 into the right side of 25, and a solid arrow runs down from 24 into 26 Agent workflows, which sits under 24. A solid arrow from the right side of 23 runs down the right margin into the right side of 26. On the left, a column of four dashed stubs: 14 FSDP and TorchTitan, 18 vLLM-TorchTPU, 19 SGLang-TorchTPU, 20 llm-d architecture. A dashed line from each joins one dashed vertical line, marked with a small muted dot at each branch, and one dashed arrow from that line enters the left side of 25. There is no arrow between 25 and 26. A legend at the bottom right reads: Chapter B lists chapter A as a prerequisite, with an A box, a solid arrow and a B box; Chapter B reuses chapter A, not a prerequisite, with an A box, a dashed arrow and a B box; and Chapter in an earlier Part, with a dashed A box.

Chapters 25 and 26 do not depend on each other: 25 needs 12 and 23, 26 needs 23 and 24. The dashed arrows mark what 25 reuses: the performance method of chapter 24 and the systems it extends, each of which you can skip if you do not work on its repository.

A solid arrow from A to B means chapter B lists chapter A as a prerequisite. Chapter 25 needs the Pallas bridge of chapter 12 and the parity gates of chapter 23; chapter 26 needs the gates of chapters 23 and 24, and does not depend on chapter 25, so you can read the two in either order. A dashed arrow marks a chapter that chapter 25 reuses without needing it: from chapter 24, the performance method its extensions are measured with; from chapters 14, 18, 19 and 20, a system it extends, which you can skip if you do not work on that repository. Chapter 25's reuse of chapter 4 and chapter 26's reuse of chapters 2, 9, 10 and 12 are not drawn, to keep the map readable. The appendix pages are not on the map: the production readiness checklist covers every Part, so it has no single prerequisite.

What this Part covers

  • Which repository and extension point own the fix for a gap (a missing op, an upstream function that misbehaves on TPU, a model that does not train yet, a routing policy you want), and why a fix one layer higher would be a workaround.
  • Adding an ATen lowering to torch_tpu: its registration, its op tests against the CPU, its removal from the list of known unregistered ops, and a check that CI runs those tests on a TPU.
  • vLLM-TorchTPU patches with the right lifecycle stages and retry contract, SGLang-TorchTPU hooks and seams, TorchTitan TPU-lane ports with a reference-parity test, and llm-d scorers wired into a scheduling profile.
  • Driving the TPU Agent Suite's ladder on a model, and accepting or rejecting each result on its evidence rather than the agent's summary.
  • The production readiness checklist, with the chapter to reread for each gap.