PyTorch/XLA, From the Inside

You know PyTorch. This is the bridge that runs it on a TPU: every op on the xla device is recorded instead of run, the recorded graph is cut at a sync point, lowered to HLO, and handed to XLA through one C++ class. The track starts where you would, in a Colab notebook, and ends at the exact line where a buffer leaves the host.

Phase 1 — Run it first

Two notebooks on a real TPU, and the craft of writing one that survives a runtime restart.

Phase 2 — The lazy tensor

Record instead of run. Then the cut, the hash, the compile cache, and the three other ways to execute the same graph.

Phase 3 — The seam, in theory

One interface, one client per process, and the round trip of a single step across it, with the counters that make it observable.

Phase 4 — The seam, line by line

The three files that are the seam: how a device string becomes a client, the interface, and the client that calls PJRT.

Phase 5 — Above the seam

The executor that collects, hashes, lowers, caches, and runs, and the dynamo bridge that replays a cached graph without tracing.

Phase 6 — Many devices

A mesh, a sharding annotation, the virtual SPMD device, and the replicated execute that follows.

Browse the full library