GPU or TPU? Choosing your accelerator
The first real question for any model isn't "how do I use a TPU" but "should I?" A practical decision — the portability-vs-peak-performance trade-off, whether XLA can compile your code, resource access, and the workload — routed through a simple decision tree.
100Foundational TPU architecture & provisioningLesson 7 of 8ShowHide
Chapter 1 of 2 in TPU Training Infrastructure
- GPU or TPU? Choosing your acceleratorYou're here
Prerequisites: Why TPUs? Cloud TPUs & the TPU VM, Cloud TPU Architecture — how you consume TPUs
The one-line summary
You know what a TPU is and how you'd consume it. But the first real question for any model isn't "how do I use a TPU" — it's "should I?" And the honest answer is it depends: TPU does not always win. It comes down to what your code targets, whether XLA can compile it, whether you can get the hardware, and the workload itself.
The trade-off
Every accelerator choice sits on one axis: peak performance ↔ portability.
- Optimize for one accelerator (hand-tuned kernels) and you get the best speed — but you're locked to that hardware.
- Stay portable — write for XLA (the compiler both JAX and PyTorch-XLA target) — and you gain flexibility and availability, at the cost of some code changes and occasionally some peak performance.
First, the framework reality
A common myth: "TPUs are for TensorFlow." Not in 2026. TPUs are XLA-based and JAX-first, with PyTorch-XLA also supported; TensorFlow is legacy on TPU. So the gate isn't which framework — it's can XLA compile your code? JAX and PyTorch-XLA compile cleanly; hand-written CUDA kernels do not.
The decision tree
Walk it. Notice the branches that send you away from a TPU — they're the point:
The four questions underneath it:
- What is your code optimized for? JAX / PyTorch-XLA → TPU-ready. CUDA / GPU kernels → GPU territory.
- Can XLA compile/convert it? Yes → the TPU path opens (expect some code changes). No (hand-tuned CUDA) → GPU.
- Can you get the resource? Quota, region, capacity — the wall the next lesson is about.
- What's the workload? Large-scale, matmul-heavy training → TPU shines. Smaller, varied, broad-framework or experimental → GPU's flexibility wins.
When each wins
| Reach for a TPU when… | Reach for a GPU when… |
|---|---|
| code is JAX / PyTorch-XLA (XLA-compilable) | code leans on hand-tuned CUDA / GPU-only ops |
| the job is large-scale and matmul-heavy | the job is smaller, varied, or experimental |
| you want cost-per-FLOP at pod scale | you need the broadest framework / kernel support |
| you can get the capacity | you need it available, anywhere, now |
You don't always have to choose
There's a third answer: run both, and let the platform switch. On GKE, custom compute classes can prioritise TPU nodes and fall back to GPU on demand, and serving libraries like vLLM can run on either — so a single deployment spans both. That's a real, powerful pattern, but it's an advanced serving topic (L300); for now, knowing how to choose is the foundation.
Put it together
Route a CUDA model
In the decider, answer that your code is CUDA / GPU-specific and depends on custom kernels. Confirm the verdict — and say in one sentence why XLA is the reason.
Route a JAX model at scale
Walk the JAX / PyTorch-XLA → large-scale → capacity available path. Name the two TPU strengths that make it the right call.
Find the capacity branch
Reach the branch where you can't reliably get TPU capacity. What does it recommend, and what's the third option it hints at?
Review
The GPU-vs-TPU trade-off in one line
Check yourself
Which statement about TPU frameworks is correct today?