Skip to content

FAQ

Short answers, each pointing to the chapter that gives the full one. The first section restates TorchTPU's own FAQ, which reads the same in the 0.2.0 documentation; the rest cover questions the chapters answer most often.

About TorchTPU

What is the difference between PyTorch/XLA and TorchTPU?

PyTorch/XLA was a bridging framework that depended on JAX runtime components and its own APIs. TorchTPU is a native PyTorch backend for Cloud TPU with no JAX runtime dependency; existing code moves with changes such as .to("cuda") to .to("tpu"). TorchTPU's FAQ says PyTorch/XLA is deprecated and replaced by TorchTPU. Chapter 3.

What is the difference between TorchAX and TorchTPU?

TorchAX (also called torch_xla2) intercepts PyTorch operations at the Python level and lowers them to XLA, often through JAX; it has been used for inference benchmarking and prototyping. TorchTPU is the official PyTorch-native backend. Google's inference announcement adds that the JAX-based engines, vLLM-JAX (tpu-inference) and SGLang-JAX, will continue to be maintained.

Is TorchTPU replacing JAX?

No. It gives PyTorch code a native path to Cloud TPU, so you do not have to rewrite a model in JAX or keep separate GPU and TPU code bases.

Which TPU generations are supported?

TorchTPU 0.2.0 validates v5e, v5p, v6e (Trillium) and v7x (Ironwood); v8i and v8t are near-term work. vLLM-TorchTPU's Cloud TPU Setup guide recommends v7x (in CI), supports v6e without CI, and treats v5e, v5p and v4 as experimental; Introducing vLLM TorchTPU groups v6e with the experimental generations. See hardware and supported models.

Where are the feature list and the roadmap?

TorchTPU's feature set lists validated and experimental features and its future work; this book collects the stated plans on the roadmap page.

How do I get kernel development support?

Start with TorchTPU's built-in ops and the Tokamax kernels, then Pallas through torch.tpu.pallas.jax_op; Helion is experimental. Chapter 12.

Is there an agent to help with onboarding?

The TPU Agent Suite (experimental) is an open-source plugin with sub-agents for onboarding, diagnostics and inference performance tuning of PyTorch models on v6e and v7x. Chapter 26.

Can I use TorchTPU with a custom serving stack?

Yes, through native PyTorch execution APIs and lower-level compiler backends; vLLM and SGLang integrations are built in, and llm-d runs custom serving setups on GKE. Chapter 18, chapter 20.

How do I reach the TorchTPU developers?

Email torchtpu-feedback@google.com, contribute at https://github.com/google-pytorch/torch_tpu, or use the "TPU" tag on https://discuss.pytorch.org/. The FAQ also says monthly office hours are planned.

Getting started

My capacity request waits forever. Is the region out of TPUs?

Usually not: on a new project it is most often a quota of 0. Check GPUS_ALL_REGIONS and the generation's regional quota before the first request. Chapter 8.

Do I need import torch_tpu?

No. With the wheel installed, import torch autoloads TorchTPU and the tpu device appears; TORCH_DEVICE_BACKEND_AUTOLOAD=0 turns that off. Chapter 3.

Why does torch.tpu.device_count() raise a RuntimeError?

On PyTorch 2.11 and later the torch.tpu duplicates of torch.accelerator calls are internal and raise from user code. Use torch.accelerator.device_count(); TORCH_TPU_ALLOW_LEGACY_DEVICE_APIS=1 downgrades the error to a warning while you migrate. Chapter 3, API matrix.

The process stops at startup with "Unknown flag". Why?

The flag is in the wrong variable: generic XLA flags such as --xla_dump_to go in XLA_FLAGS, TPU compiler flags --xla_tpu_* in LIBTPU_INIT_ARGS, and each rejects the other's. Chapter 3, environment variables.

How many processes do I start per host?

One per device. A v7x chip is two devices, so a 4-chip v7x host runs 8 processes, and the world size is twice the chip count. Chapter 1, chapter 8.

Can two processes share a TPU device?

No. Only one process can access a device, so RL setups that colocate trainer and engine on one GPU split the chips instead. Chapter 15.

Execution and compilation

Which eager mode should I use?

Strict (the default) while porting, Debug (TORCH_TPU_LAUNCH_BLOCKING=1) to find an error far from its cause, and DeferAndFuse or torch.compile(backend="tpu") for speed. Chapter 4, chapter 11.

Why is the first step slow and later steps fast?

The first call compiles. That is expected; a persistent tier-3 compilation cache lets restarts skip it. Time the first call and the steady state separately. Chapter 4, chapter 24.

Why is every step slow?

Usually because shapes change and every new shape is a new compile; TorchTPU defaults torch.compile to dynamic=False. Pad to buckets or use a static KV cache, and check with TORCH_LOGS="recompiles" and fail_on_recompile. Chapter 7.

Does an op TorchTPU does not implement fall back to the CPU?

Not by default: a missing op raises NotImplementedError. The CPU fallback is an internal debugging switch that logs every use. Chapter 25.

Do CUDA streams carry over?

The API exists (torch.tpu.Stream, torch.tpu.Event), but a TensorCore runs one computation at a time and the API reference says manual multi-stream management is not needed; overlap comes from the XLA schedule. Chapter 3.

Numerics

Why do my float32 results differ from the GPU by about 1e-3?

TorchTPU's default matmul precision is one bf16 MXU pass with float32 accumulation; CUDA's default is full float32. Use torch.tpu.precision(torch.tpu.Precision.HIGHEST) where a layer needs it, at about 6 times the MXU cost. Chapter 6.

What tolerance should a parity test use?

Take it from the dtype and the operation, compare like with like (run reference parity at "highest"), and record the measured error next to the bound. Include a negative control. Chapter 23.

Training and serving

FSDP2 or SimpleFSDP?

SimpleFSDP (or manual FSDP): its collectives are nodes in the traced graph, so XLA can overlap them and there are no staging copies. TorchTPU lists FSDPv2 as experimental with low performance. Chapter 14.

vLLM-TorchTPU or SGLang-TorchTPU?

Choose on hardware, your existing stack, the speculation method you need and your model's support tier, then measure both with the same client. Chapter 19, supported models.

Do I need llm-d to serve on TPU?

No; one engine serves on its own. llm-d adds routing, KV cache awareness and flow control in front of a fleet. Its announcement suggests starting with prefix-aware routing in front of an existing vLLM deployment, then adding flow control, KV cache offload and disaggregation. Chapter 20.

Measurement

Does profiling slow the run down?

Yes, by about 5 to 10% per step. Explain with traces; measure with the profiler off. Chapter 10.

My MFU differs from a published figure. Who is wrong?

Maybe neither: MFU depends on the FLOP convention (\(6N\), \(6N\) plus attention, or counted ops) and the unit (per chip or per device). Recompute both on one convention; above 100% is a units bug. Chapter 16, chapter 24.

References