模型与实验室 3.0 · 值得看 2026-10-23 · GitHub

TorchTPU: PyTorch backend for Google TPUs (google-pytorch/torch_tpu)

Google 开源的 PyTorch TPU 原生后端:提供 ATen kernel 实现XLA 计算的编译缓存torch.compile() 图模式执行数据并行/张量并行分布式训练支持,附 LlamaQwenResNetDLRMminGPTUNet 等模型示例和调试基准工具截至 2026-10-23 有 682 星与 DeepInfer 等同属训练/推理栈开源竞争组:PyTorch 生态有了 Google 官方维护的 TPU 后端,框架绑定硬件的格局在训练侧也开始松动README 未给性能数字,实际可用性待跑分验证

打开原文回到归档

TorchTPU: PyTorch backend for Google TPUs (google-pytorch/torch_tpu)

URL: https://github.com/google-pytorch/torch_tpu
author: google-pytorch
date: None
source: github / github
collected: 2026-10-23 (daily-intake-evening)

Summary

Google 开源的 PyTorch TPU 原生后端:提供 ATen kernel 实现、XLA 计算的编译缓存、torch.compile() 图模式执行、数据并行/张量并行分布式训练支持,附 Llama、Qwen、ResNet、DLRM、minGPT、UNet 等模型示例和调试基准工具。截至 2026-10-23 有 682 星。与 DeepInfer 等同属训练/推理栈开源竞争组:PyTorch 生态有了 Google 官方维护的 TPU 后端,「框架绑定硬件」的格局在训练侧也开始松动。README 未给性能数字,实际可用性待跑分验证。

A PyTorch backend for Google TPUs, open-sourced under google-pytorch: custom ATen kernels, a compilation cache for XLA computations, torch.compile() graph-mode execution, data- and tensor-parallel distributed training, and examples spanning Llama, Qwen, ResNet, DLRM, minGPT and UNet, plus debugging and benchmarking utilities (682 stars as of 2026-10-23). The README ships no performance numbers yet.

Source (fetched)

<img src="docs/images/torchtpu_logo.avif" alt="TorchTPU Logo" style="width: 60%;">

Description

This project provides a PyTorch backend for Google's Tensor Processing Units (TPUs), enabling users to run PyTorch models and operations on TPU devices. It includes custom ATen kernels for various PyTorch operations, a compilation cache for optimizing execution, and examples for distributed training and model inference.

Features

  • PyTorch ATen kernel implementation for TPU.
  • Compilation cache for optimized execution of XLA computations.
  • Support for distributed training (Data Parallelism, Tensor Parallelism).
  • Examples for various models (Llama, Qwen, ResNet, DLRM, minGPT, UNet).
  • Integration with torch.compile() for graph mode execution.
  • Utilities for debugging and benchmarking.

User Guide and Interactive Notebooks

A user guide is available at https://torchtpu.readthedocs.io/. This is a static version of the interactive notebooks. They are available in the docs folder.

The notebooks are Marimo (similar to Jupyter). They can be run with marimo edit file.py and then you can access them in your browser. You will need to be running this from a TPU VM, a v6e GCE instance is easiest.

Installation

The same instructions are available in the user guide linked above.

<!-- LINT.IfChange(python_version_support) -->

TorchTPU's Python version support policy matches PyTorch's Release Compatibility Matrix. Currently, Python 3.11+ is supported. See the Python Version Support Policy for more details.

<!-- LINT.ThenChange( pyproject.toml:requires_python, bazel/supported_python_versions.bzl:supported_python_versions, ../docs/developers/python_support_policy.md:python_version_support, ) -->

First create a Python virtual environment:

python -m venv .venv
source .venv/bin/activate

or, with uv

uv venv .venv
source .venv/bin/activate

Install via pip

Install the latest public release (0.2.0 on PyPI) (for uv prepend uv to all pip commands):

pip install torch_tpu==0.2.0 --extra-index-url https://download.pytorch.org/whl/cpu

Build from source

Wheels can be built via:

bazel build --config=wheel_common //ci/wheel:torch_tpu_wheel

All OSS Bazel builds default to optimized mode (-c opt) automatically via .bazelrc. Unoptimized builds (-c fastbuild, -c dbg) can degrade performance and are not used for wheel builds. If you are developing or debugging C++ code and explicitly want an unoptimized wheel, pass --//:allow_unoptimized_wheel=True:

bazel build -c dbg --config=wheel_common //ci/wheel:torch_tpu_wheel \
    --//:allow_unoptimized_wheel=True

--config=wheel_common is required, and the build fails at build time without it. The config sets --//:wheel_build=True, which routes the shared XLA/MLIR backend through the torch_version-reset transition so that pywrap factors it into a single libxla_base.so; built without the flag, every per-version common ships its own copy of the backend and the resulting wheel aborts on import torch with duplicate static registrations.

wheel_common also turns on the Remote Build Execution (RBE) remote cache and remote executor.

Obsidian evidence excerpt

from OpenClaw定时任务/内容选题编排/2026-10-23-内容选题编排.md:

203 Google 开源 TorchTPU(github.com/google-pytorch/torch_tpu,378,README 已读)——原生 PyTorch TPU 后端:ATen kernels + XLA 编译缓存 + torch.compile + 分布式训练,示例覆盖 Llama/Qwen/ResNet/DLRM/minGPT/UNet;与 DeepInfer(10-21 已投)同属「训练/推理栈开源竞争」组