Back to paths

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.

beginner~9 min#ml-systems#hardware#accelerators
100Foundational TPU architecture & provisioningLesson 7 of 8Show

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:

Simulation: gpu-or-tpu-decider

The four questions underneath it:

  1. What is your code optimized for? JAX / PyTorch-XLA → TPU-ready. CUDA / GPU kernels → GPU territory.
  2. Can XLA compile/convert it? Yes → the TPU path opens (expect some code changes). No (hand-tuned CUDA) → GPU.
  3. Can you get the resource? Quota, region, capacity — the wall the next lesson is about.
  4. 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-heavythe job is smaller, varied, or experimental
you want cost-per-FLOP at pod scaleyou need the broadest framework / kernel support
you can get the capacityyou 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

Steps
  1. 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.

  2. 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.

  3. 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

Flashcards1 / 4

The GPU-vs-TPU trade-off in one line

Check yourself

Quick exam1 / 3 · 0 correct

Which statement about TPU frameworks is correct today?

Your notes on this lesson