The End of CUDA Lock-In? Inside TorchTPU

summarized

TLDR

Google's TorchTPU largely delivers on its one-line promise to let PyTorch code run on TPUs by changing 'cuda' to 'tpu', with 98% of popular Hugging Face models working without modification. However, performance varies significantly depending on model size and structure, and the paper's numbers are more conservative than the launch post's headline figures. The real barrier to switching remains access to TPU hardware, CUDA-specific operational knowledge, and handling models with dynamic shapes or diverging code paths across distributed ranks.

Key points

TorchTPU was open-sourced by Google on October 20th and codeveloped with Meta's PyTorch team.

It works by plugging into PyTorch's dispatcher and deferring operations into stable HLO programs for XLA compilation.

98% of nearly 5,000 popular Hugging Face models run without code changes, and 97% of architecture families match GPU numerics.

The old PyTorch XLA is deprecated and will be archived on November 15th, with Google recommending migration to TorchTPU.

Performance claims vary: 52% of peak on an 8B Qwen-3 model, but only 27% on a large mixture-of-experts model.

Techniques

  • deferred ops
  • stable HLO
  • XLA compilation
  • liveness analysis
  • three-tier compilation cache
  • repeated ops heuristic
  • eager modes
  • torch.compile with Dynamo
  • skinny collectives
Transcript (captions)

0:00 I expected Google's torch TPU paper to walk back its own one-line promise. Its test table says the opposite. The line held for 98% of the popular hugging face models it tried. If your PyTorch code

0:11 says CUDA all over it, that table is about whether your model can leave Nvidia without a rewrite. Until now, leaving mostly meant one, and that rewrite is Nvidia's moat. Reuters

0:21 reported last December that Google's own enterprise customers said adopting TPUs meant switching from PyTorch to JAX. Then on October 20th, Google open-sourced torch TPU with a one-line

0:33 pitch. Where your code says model.to cuda, write model.to TPU. That line bugged me. A TPU runs whole programs built by Google's XLA compiler, while PyTorch fires off one small operation at

0:46 a time. So, I read the launch post, the paper, the docs, and the Hacker News thread for what sits in between and what it costs. Headlines call it the end of Nvidia's CUDA lock-in. And on the

0:57 one-line part, the paper backs them. The crack is in Google's own numbers. Its launch post headlines 52% of the chip's peak math put to real use on a small model, the 8 billion Qwen-3. The paper's

1:09 largest-scale run, a far bigger model, sits near 27%. Different models, so neither cancels the other. But if you train something big, which do you plan with? By the end, you'll know that. How

1:21 one string reaches a chip that wants whole programs, and which part of Nvidia's moat it cracks. Start with the road Google is closing. In 2021, Hugging Face's blog described PyTorch XLA

1:32 tensors as lazy. They record operations into a graph until a result is needed, and you cut that graph with a call named mark_step. Google's current docs describe the old approach the same way.

1:43 You had to mark which regions could be compiled. Hugging Face's post named the price, too. If the graph keeps changing shape, the cache misses and XLA compiles again. So, a batch whose length kept

1:54 changing could mean compiling over and over. In the Hacker News launch thread, Ismael Mej summed up those years. You had to fight XLA to make PyTorch run on TPUs.

2:04 Hugging Face even built its own bridge, Optimum TPU, to cut that friction for its libraries. Its docs page now opens on a banner. Optimum TPU is now archived. No date and no reason, which

2:16 is about as short as a eulogy gets. Over on GitHub, the PyTorch XLA repo spells it out. Deprecated, replaced by torch TPU, archived on November 15th. If you've got PyTorch XLA jobs running

2:29 today, put that date on your calendar. Google's docs recommend migrating them to torch TPU and starting anything new there. More surprising is who built the

2:38 replacement. Meta's PyTorch team codeveloped torch TPU. So, the company that makes PyTorch spent engineering time getting PyTorch to run well on chips Nvidia doesn't make. Jana

2:50 van Gruenen, Meta's director of PyTorch engineering, says it lets Meta deploy its PyTorch workloads to Google TPUs. Her quote sits next to a report from The Information this February, a

3:00 multi-billion-dollar deal for Meta to rent TPUs. Neither company confirmed it, so it stays a report. What's on the record is the rest of her line. The work builds, in her words, the ecosystem

3:11 flexibility everyone needs. So, how does one string reach a chip that runs compiled programs? Reuters spelled out why that's possible at all. Very few developers write every line of

3:21 code that chips from Nvidia, AMD, or Google will actually execute. Your model calls PyTorch, and PyTorch decides what runs. Whoever owns that middle layer owns the port. I expected a converter

3:33 that translates your whole model before it runs. What the paper describes is more patient. Torch TPU plugs in exactly where PyTorch already decides where each operation goes, and then, mostly, it

3:44 waits. PyTorch calls that spot the dispatcher. Every PyTorch operation, a matrix multiply, an add, a softmax, goes through it on the way to the back end for its tensors device. Torch TPU

3:56 registers there in a spare back end slot, then fills it with about 450 core PyTorch operations. Ops that already break down into simpler ones get skipped. So, Torch TPU doesn't have to

4:06 cover everything by hand. What you get? A TPU tensor is an ordinary PyTorch tensor. Code above it sees the same type it always has, which is how the paper's goal, swapping CUDA for TPU, can hold.

4:19 Now, the obvious way to run those ops, send each one to the chip the moment PyTorch calls it. Torch TPU can do that. Google's developer blog lists three eager modes. Debug syncs after every op,

4:31 which is what you want when you're hunting a bug and you've made peace with the wait. Strict sends ops one at a time without waiting on each. Fused is where the speed is. Google's blog puts it at

4:41 50 to over 100% faster than strict with no setup on your side. That's Google measuring itself with no outside benchmark behind it. Fused works like this. Each operation becomes what the

4:53 paper calls a deferred op. Instead of running, it adds itself to a program written in stable HLO, the input format XLA's compiler reads. Your Python keeps going line after line while the program

5:05 grows behind it. Picture a waiter who doesn't run each dish to the kitchen as you order it. They write down the whole order and the kitchen gets one ticket for the table. For Torch TPU, the ticket

5:15 is a stable HLO program and the kitchen is XLA. A ticket goes in the moment you ask for something. In PyTorch terms, that's when your code needs an actual value. {dot}item on the

5:26 loss or {dot}to CPU. Right then, the dispatcher calls back into Torch TPU, which first runs liveness analysis, working out which in-between results anything still needs.

5:37 Next, it computes a cache key for the program and checks a three-tier compilation cache. Seen this exact program before? Cache hit and the compiled one gets reused. If not, XLA

5:48 compiles it. Either way, the program runs on the TPU and your loss comes back. One step stays dark. No source in this research explains how libtpu and XLA turn stable HLO into

6:00 actual TPU instructions. None of them puts a figure on how long a first compile takes, either. Waiting has a limit, though. A big transformer is the same block stacked

6:10 over and over, and without a cut, the program would keep growing until you asked for a value. So, the paper adds a repeated ops heuristic. When it spots a pattern like a transformer block

6:20 repeating, it cuts the batch early and runs it. Transformers repeat themselves by design, and torch_xla takes the hint. Our waiter picture breaks right here. A real kitchen already knows its dishes.

6:32 XLA doesn't. The first time a program shows up, it has to compile it, and only the cache makes the next visit cheap. Now, hold that against the old road, because the idea of waiting isn't new.

6:43 Pytorch XLA also recorded a graph and compiled it, and a value request ran the graph there, too. What moved is who decides. Before, you marked which regions could compile and called

6:53 mark_step yourself. Now, torch_xla makes those calls and adds its own cut whenever a block repeats, while its tensors stay normal Pytorch tensors. Step three is for when eager speed isn't

7:04 enough. Call torch.compile, and Dynamo, Pytorch's graph capturer, turns your Python into graphs. Instead of going to Inductor, Pytorch's usual compiler, those graphs go to XLA,

7:17 lowered to stable HLO, the same format that eager path builds. Google's reason, XLA is, in its words, "rigorously battle-tested for TPU topologies." So, as one chain, your code calls an op.

7:30 Pytorch's dispatcher hands it to torch_xla. Fuse mode defers it into a stable HLO program. A value request or a repeated block cuts the program. Either the cache or XLA supplies a compiled

7:42 version and the TPU runs it. All of that sits behind one line. At your desk, that chain has a consequence. A program the cache hasn't seen means a compile. Changing shapes were exactly the old

7:54 PyTorch XLA pain. So, the obvious worry is whether models with moving sizes still work. Torch TPU's paper tested that directly. Its coverage table put nearly 5,000 popular hugging face models

8:05 through one simple question. Does it run at all? Yes came back for 98% of them. A second test grouped them into architecture families and compared outputs against a GPU. 97% of those

8:17 families matched GPU numerics. I'd care about that figure most because a model that runs but drifts is worse than one that crashes. You find the crash in a minute. Drift shows up later in your

8:27 eval scores. And the worry about moving sizes? For causal language models with bounded dynamism, meaning sizes that change within known limits, the paper reports a 99% pass rate. It doesn't list

8:39 which of the popular models fail. A TechCrunch report puts those misses down to dynamic shapes. Around it, Google's post lists a launch day ecosystem. Transformers V5, it says,

8:50 now takes device map equals TPU. vLLM has its own Torch TPU plugin, promising the same command line, the same open AI compatible server, and no model code changes. Its readme recommends the

9:03 newest TPUs and still marks the older V5 chips experimental. Zen Teak, which uses TPUs to generate synthetic data, supplies the flashiest customer number in the launch post. On TPU V6E chips, it

9:15 says, its daily token capacity rose more than fourfold. Read the setup, though. GKE inference gateway with LLM D routing request, which may not involve Torch TPU's eager path at all. One customer

9:29 quote, no second source, of everything in that Hacker News thread, the comment that surprised me most isn't about Google's chips at all. User PC Moritz wrote that as a side project they've

9:40 been building an open source version of libtpu, the runtime layer torch tpu sits on for tenstorrent accelerators. They claim it can already run most of torch tpu. The project libtt plugs in where

9:53 libtpu does as what's called a pjrt plugin. On tenstorrent black hole cards, its readme reports about 6,000 torch tpu tests passing and call it half that many failing.

10:05 A readme that prints its failures right beside its passes is more forthcoming than plenty of launch posts. So the story flips a little. Software sold as a crack in Nvidia's moat can itself be

10:16 pointed at another company's chip at least partly by one person outside Google. To me it reads as pytorch's device string starting to mean what it says. Back to the question from the

10:26 start. If you train something big, do you plan with Google's headline figure or the papers? Start with what each one measured. Google's headline figure comes from the 8 billion quint 3, small by

10:36 these standards with Google saying it scaled across thousands of iron wood tpus. Over in the paper, the largest scale row is a far bigger mixture of experts model and it lands near 27%

10:47 short answer then. Google's figure is the best it reported on a smaller model. Divide one by the other and the giant mixture of experts run keeps its chips busy with useful

10:57 math about half as well. If your job looks like that one, plan with the paper's number. The paper's sharper warning is about ranks. In a distributed job, each process is a rank.

11:07 When ranks run different code, the safe default is something the paper calls skinny collectives. It compiles each collective, the step where ranks swap data, on its own. Cost in the paper's

11:18 example, 30 to 40% end to end compared with the faster option it describes. It's an easy trap because the one line you changed says nothing about how your ranks behave. So check before you move.

11:30 If any rank takes a different branch from the others, budget for that cost until you've measured your own job. Reinforcement learning has its own note. Per the paper, colocation, meaning

11:39 training and generation sharing the same chips, isn't supported out of the box. If that's how your RL setup runs, expect to build that part yourself for now. Then there's a part no compiler touches.

11:50 Under its own one-line headline, Tech Times says Torch TPU doesn't address the operational knowledge gap. The debugging guides, kernel optimization playbooks, and institutional memory built around

12:01 CUDA. When your run stalls, the answers you search up still say CUDA. Your string changed. The search results didn't, and a string doesn't hand you a TPU. These chips live in Google Cloud,

12:13 and whether you can get the ones you need at a price that beats your GPUs is outside what these sources measure. That decision still happens in a price quote. On Hacker News, Jacques M gave the

12:23 measured version. CUDA still has an edge, but every release like this chips away at that. One YouTube title says this could end a $4 trillion empire. That's a lot to hang on a device string.

12:34 Everything I read sides with Jacques M. One gap keeps it from being settled. No source here runs the same PyTorch training job on TPUs and Nvidia GPUs side-by-side. So what did Google crack?

12:46 The rewrite. For most common models, the cost of trying a TPU went from a port to a string. You change code you already have. And Reuters reported that rewrite as the very cost Google's own customers

12:58 named, what it left standing. Access to the chips, the CUDA know-how, and the tax on code where ranks diverge. Add the popular models that still don't pass. From the paper's table, that works out

13:09 to about 2%. If I had to give one rule, it's this. Before you move a job, ask whether your model is a common Hugging Face architecture, and whether every rank runs the same code. Yes to both,

13:21 and the switch is close to one line. A no on either, and plan with the paper's numbers, not the launch post. My verdict, by who you are. If you serve models with VLLM, this is the easiest

13:32 door in. Same server, same command line. If you're on PyTorch XLA, start moving before that November 15th archive. If you train giant mixture of experts models or run co-located RL, I'd wait

13:45 for numbers that look like your workload. I started out expecting the paper to walk its one-line promise back. Mostly it kept it and it listed its own limits, too, which is more than the

13:55 headlines did. Rewriting your code was one wall of the moat and that wall's cracked. Everything else still stands. So, if you've got a PyTorch job that says CUDA today, what's actually

14:05 stopping you from trying TPU? The hardware, the know-how, or ranks that run different code? Tell me which one in the comments.

Frontier News · by Hyperjump Technology