TorchTPU: Google's Open Source PyTorch Back End for TPUs
The torch_tpu README is short on benchmarks but long on build and install pitfalls: a CUDA torch default, a wheel that dies on import, and a flag-ordering rule. Here is what to know before you point a TPU VM at it.

If you have a PyTorch model and a TPU, the first questions are practical ones. Which Python version does the package need? Which torch build does it pull in? What happens when you build it yourself? Google's google-pytorch/torch_tpu repository is an open source PyTorch back end for TPUs, and its README answers those questions in unusual detail, including a few build failures it warns you about.
The README gives no numbers for benchmarks, op coverage or comparisons with other TPU paths. What it does give is the install path, the build flags, the feature list and the constraints. Those are worth reading closely before you commit a TPU VM to an evaluation.
What the repository says it provides
The description is a PyTorch back end that lets you run PyTorch models and operations on TPU devices. The feature list is short and specific:
- A PyTorch ATen kernel implementation for TPU, with custom kernels for various operations.
- A compilation cache for optimized execution of XLA computations.
- Distributed training support: Data Parallelism and Tensor Parallelism.
- Integration with
torch.compile()for graph mode execution. - Examples for Llama, Qwen, ResNet, DLRM, minGPT and UNet.
- Utilities for debugging and benchmarking.
Implementing at the ATen level means the work happens where PyTorch dispatches individual operations, not in a wrapper around your model code. The compilation cache matters for the same reason. XLA compilation is not free, and a cache keyed on computations is what stops you paying that cost on every run. The README does not say how the cache is keyed or where it is stored, so check the user guide before relying on it in CI.
Installing the released package
The latest public release named in the README is 0.2.0 on PyPI. The Python support policy follows PyTorch's Release Compatibility Matrix, and the README currently lists Python 3.11+. Create a virtual environment first, with either venv or uv:
python -m venv .venv
source .venv/bin/activate
pip install torch_tpu==0.2.0 --extra-index-url https://download.pytorch.org/whl/cpuThe --extra-index-url is not optional. Without it, pip resolves the default CUDA build of torch, and the README says so explicitly. On a TPU VM that means a large, useless CUDA wheel and a dependency set you did not intend. If you use uv, prepend uv to every pip command. The flag stays the same.
Building from source with Bazel
The project builds with Bazel, and the README recommends installing Bazelisk, a wrapper that fetches the right Bazel version. Two routes are given: go install github.com/bazelbuild/bazelisk@latest, or downloading a binary (the example uses Bazelisk v1.27.0 for Linux amd64). Put it on your PATH and run bazel info in the repo root. It should print repository information without errors.
The wheel build target is:
bazel build --config=wheel_common //ci/wheel:torch_tpu_wheelAll OSS Bazel builds default to optimized mode (-c opt) through .bazelrc. The README warns that -c fastbuild and -c dbg can degrade performance, so they are not used for wheel builds. If you really want an unoptimized wheel for C++ debugging, you must also pass --//:allow_unoptimized_wheel=True. The guard exists so nobody ships a slow wheel by accident.
Why --config=wheel_common is mandatory
This is the most useful failure mode in the README. The build fails without --config=wheel_common. The config sets --//:wheel_build=True, which routes the shared XLA/MLIR back end through the torch_version-reset transition, so that pywrap factors it into a single libxla_base.so.
Without the flag, every per-version common target ships its own copy of the back end. The resulting wheel then aborts on import torch with duplicate static registrations. The wheel builds, but it is broken at import. That is a worse failure than a build error, because you only find out after installing. If you script the build, make the config a hard-coded part of the command.
The RBE flags and the ordering rule
wheel_common also turns on the Remote Build Execution (RBE) remote cache and remote executor. If you have no RBE credentials, you need to strip those flags out. The README's answer is --config=no_rbe:
bazel build --config=wheel_common //ci/wheel:torch_tpu_wheel --config=no_rbeOrder matters. --config=no_rbe has to come after --config=wheel_common, because the later config wins for the remote-cache and remote-executor flags both of them set. Reverse the two and you will probably get a build that tries to talk to remote infrastructure you cannot authenticate against. The README does not describe the exact error you would see, so treat the ordering as a rule and do not wait to confirm it.
To install the result, build in a fresh venv and point pip at the wheel under bazel-bin/ci/wheel/, again with the CPU --extra-index-url. The CUDA-torch warning applies here too.
Notebooks, the user guide and the hardware requirement
The user guide lives at torchtpu.readthedocs.io and is a static rendering of interactive notebooks in the repo's docs folder. The notebooks are Marimo, which the README describes as similar to Jupyter. Run one with marimo edit file.py and open it in your browser.
You need to run this from a TPU VM, and the README says a v6e GCE instance is the easiest option. So you cannot evaluate the back end meaningfully on a laptop. You can read the code and build the wheel there, but running the examples needs TPU hardware. Budget for a v6e instance before planning an evaluation. The examples (Llama, Qwen, ResNet, DLRM, minGPT, UNet) cover a useful spread of architectures: transformers, a CNN, a recommendation model and a segmentation network. Each is a reasonable first test for your own workload.
Distributed training and torch.compile
The README lists Data Parallelism and Tensor Parallelism and provides examples for distributed training and model inference. It lists no other parallelism strategies, so do not assume pipeline or sequence parallelism from the feature list. It also gives no scaling numbers.
The torch.compile() integration provides graph mode execution. If your code already uses torch.compile on GPU, the sensible first test is to run the same model unchanged and see which ops fall off the supported path. The README does not document coverage, so the examples and the public API reference in the user guide are your best guide to what is supported today.
The contributor setup cost
If you plan to read or modify the C++ side, the README recommends VSCode with the clangd extension, backed by a compilation database generated from the Bazel action graph. The setup commands are code --install-extension llvm-vs-code-extensions.vscode-clangd and, to avoid interference, code --uninstall-extension ms-vscode.cpptools. Then run tools/setup_clangd.py to generate compile_commands.json.
The first run does a full build and can take more than 30 minutes. Reruns are incremental and cheap. If you have built recently, pass --no-build to skip the wait. On a fresh workspace that may leave clangd unable to resolve generated files. The same can be done through nox: nox -s refresh_compile_commands -- --no-build. Contributions are welcome, with guidelines in CONTRIBUTING.md.
Where this does not fit, and what to watch for
- No TPU, no evaluation. The notebooks assume a TPU VM, with a v6e GCE instance suggested.
- Python 3.11 or newer. Older environments need upgrading first.
- Early version. The public release is 0.2.0, and the README's Dependencies section still says 'TBD'. Pin the version and expect the API surface to move.
- Unknown op coverage. The README lists kernels for 'various' operations without enumerating them. Test your own model before assuming it runs.
- Bazel is the build system. Teams that only want to consume the package can avoid it by using the PyPI wheel. Teams that need to patch the back end take on Bazel, RBE configuration and long first builds.
- Packaging traps. A missing CPU
--extra-index-urlinstalls CUDA torch, and a missingwheel_commonproduces a wheel that fails on import.
The README has no performance data, so the case for adopting this rests on whether your models run correctly on it. Start with the closest example to your architecture, on a v6e VM, with the released 0.2.0 wheel.
- #Open Source
- #PyTorch TPU
- #PyTorch back end
- #TPU v6e
- #TorchTPU
- #torch_tpu



Comments