LmCast :: Stay tuned in

Google open-sources TorchTPU, a native PyTorch back end for TPUs

Recorded: Oct. 20, 2026, 5 p.m.

Original Summarized

GitHub - google-pytorch/torch_tpu · GitHub

Skip to content

Navigation MenuSign inAppearance settingsPlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesCode QualityEnforce quality at mergeAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricingSearch/Sign inSign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

google-pytorchtorch_tpuRepository navigationCodeIssues42 (42)Pull requests214 (214)ActionsProjectsSecurity and qualityInsightsMore items

torch_tpuPublicNotificationsYou must be signed in to change notification settingsFork6 (6)Star109 (109)You must be signed in to star a repositoryAbouttorchtpu.readthedocs.ioResourcesReadmeLicenseContributingContributingSecurity policySecurity policyActivityCustom propertiesStars109 starsWatchers1 watchingForks6 forksReport repositorymainBranchesTagsGo to fileCodeOpen more actions menuLatest commit History4,462 Commits4,462 CommitsFolders and filesNameNameLast commit messageLast commit date.agents/skills/docs-review.agents/skills/docs-review  .github.github  .vscode.vscode  bazelbazel  build_filesbuild_files  cici  csrccsrc  dockerdocker  docsdocs  examplesexamples  perflabperflab  requirementsrequirements  shimsshims  src/torch_tpusrc/torch_tpu  teststests  toolstools  .bazelignore.bazelignore  .bazelrc.bazelrc  .bazelversion.bazelversion  .clang-format.clang-format  .clangd.clangd  .gitignore.gitignore  .readthedocs.yaml.readthedocs.yaml  AGENTS.mdAGENTS.md  BUILD.bazelBUILD.bazel  CLAUDE.mdCLAUDE.md  CONTRIBUTING.mdCONTRIBUTING.md  LICENSELICENSE  MODULE.bazelMODULE.bazel  README.mdREADME.md  REPO.bazelREPO.bazel  SECURITY.mdSECURITY.md  WORKSPACEWORKSPACE  WORKSPACE.bzlmodWORKSPACE.bzlmod  bazel_downloader.cfgbazel_downloader.cfg  mkdocs.ymlmkdocs.yml  mkdocs_hooks.pymkdocs_hooks.py  noxfile.pynoxfile.py  pyproject.tomlpyproject.toml  visibility.bzlvisibility.bzl  View all filesRepository files navigationREADMEContributingLicenseSecurityMore items
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.
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.
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. If you do not have RBE credentials, append --config=no_rbe to
strip those flags back out:
bazel build --config=wheel_common //ci/wheel:torch_tpu_wheel --config=no_rbe
The order matters here: --config=no_rbe has to come after
--config=wheel_common, because the later config is the one that wins for the
remote-cache and remote-executor flags they both set.
Install wheel via:
cd <path_to_repo>
python -m venv .venv; source .venv/bin/activate
# The extra-index-url provides the CPU version of torch rather than the default CUDA build.
pip install ../bazel-bin/ci/wheel/*.whl --extra-index-url https://download.pytorch.org/whl/cpu
Note that installing without --extra-index-url https://download.pytorch.org/whl/cpu will install the CUDA version of torch;
pass --extra-index-url as shown above or install the CPU build separately.
Getting Started
Some pointers to get you started:

PyTorch: Official PyTorch documentation
Tutorials and examples: easy to understand PyTorch code using TorchTPU
Public APIs: the TorchTPU APIs that you can use

Dependencies
The project uses Bazel for dependency management. Key Python dependencies are:
TBD
Bazel setup
This project uses Bazel for building and dependency management.
To install Bazel, we actually install Bazelisk, which is a transparent wrapper
that handles downloading and installing Bazel itself.
There are several ways to install Bazelisk. Here are some common ways:

If you have Go installed:
go install github.com/bazelbuild/bazelisk@latest

Download the binary directly:
wget -O ~/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.27.0/bazelisk-linux-amd64

See the
Bazelisk README
for more install instructions
However you install it, add it's location to PATH.
To verify the install, run bazel info in the repo's root directory:
bazel info

It should print information about the repo without errors.
VSCode clangd Setup
For C++ code navigation, it is recommended to use VSCode with
clangd extension.
Relying on a
compilation database
generated from Bazel action graph, clangd is able to
enrich the editor with various smart features, including code completions, go-to
definitions, etc.

Install VSCode extensions via UI or the following command:
code --install-extension llvm-vs-code-extensions.vscode-clangd
# Uninstall Microsoft C++ extensions to avoid interference.
code --uninstall-extension ms-vscode.cpptools

Generate the initial compile_commands.json:
tools/setup_clangd.py

It may take a while (> 30 minutes) for the first run to make a full build, but
reruns will be incremental and cheap. If you have run bazel build recently,
generated files already exist so you can pass --no-build to skip waiting for
heavy builds (note that on a fresh workspace, skipping the build may prevent
clangd from resolving generated files). See more options in the
script file-level comments.
Alternatively, you can invoke the script via nox (arguments after -- are
forwarded):
nox -s refresh_compile_commands -- --no-build
nox -s refresh_compile_commands -- //src/torch_tpu/ops/...
Contributing
We welcome contributions to the PyTorch on TPU project! Please see our
CONTRIBUTING.md for guidelines on how to contribute,
including signing our Contributor License Agreement (CLA) and code review
processes.
Star History

License
This project is licensed under the Apache 2.0 License. See the
LICENSE file for details.
Abouttorchtpu.readthedocs.ioResourcesReadmeLicenseContributingContributingSecurity policySecurity policyActivityCustom propertiesStars109 starsWatchers1 watchingForks6 forksReport repositoryReleasesPackagesUsed byContributorsLanguages

Footer

© 2026 GitHub, Inc.

Footer navigation

Terms

Privacy

Security

Status

Community

Docs

Contact

Manage cookies

Do not share my personal information

You can’t perform that action at this time.

The torch_tpu repository, maintained by Google's PyTorch team within the google-pytorch organization on GitHub, provides a comprehensive and optimized PyTorch backend tailored for Google's Tensor Processing Units (TPUs). This project bridges the gap between PyTorch's high-level model and operation abstractions and the low-level, highly optimized execution on TPU hardware, enabling users to run PyTorch models and perform a wide array of operations directly on TPU devices. The project's feature set is robust, encompassing a full implementation of PyTorch's ATen kernel library specifically adapted for TPU architectures, a sophisticated compilation cache that accelerates the execution of XLA computations through caching and optimization, and extensive support for distributed training methodologies, including both Data Parallelism and Tensor Parallelism, which allow efficient scaling of models across multiple TPU devices. Furthermore, the repository includes a diverse set of practical examples demonstrating the deployment of well-known models such as Llama, Qwen, ResNet, DLRM, minGPT, and UNet, facilitating hands-on learning and validation. Integration with torch.compile() for graph mode execution is also a key capability, enabling the compilation of PyTorch models into optimized graphs for enhanced performance, while utilities for debugging and benchmarking are provided to aid in performance analysis and development.

From a technical and architectural perspective, the project deeply leverages the underlying XLA (Accelerated Linear Algebra) and MLIR (Multi-Level Intermediate Representation) compilation pipelines. The wheel build process is meticulously configured using Bazel, with the --config=wheel_common flag being essential to route the shared XLA/MLIR backend through a version-reset transition that consolidates it into a single libxla_base.so file, preventing the common issue of duplicate static registrations that occur when per-version backends are not properly aggregated. An optional --config=no_rbe flag can be applied to strip out Remote Build Execution (RBE) remote cache and executor settings, which is necessary for environments lacking RBE credentials, and the order of configuration flags is critical to ensure correct precedence. Installation instructions are aligned with PyTorch's Release Compatibility Matrix, currently supporting Python 3.11 and above, and present two primary installation pathways: a straightforward pip installation of the latest public release (version 0.2.0) using the CPU-specific wheel index URL (https://download.pytorch.org/whl/cpu) to avoid unnecessary CUDA dependencies, and a source-based build using Bazel, which requires the --config=wheel_common flag and can be adjusted with additional flags like --config=no_rbe as needed. The wheel installation via pip from bazel-bin is also detailed, with reminders that using the CPU index URL is mandatory to install the correct CPU torch build.

The development workflow is heavily reliant on Bazel for dependency management and build orchestration, necessitating the installation of Bazelisk, a transparent wrapper that handles Bazel's distribution and installation. Bazelisk can be installed via Go's install command or by direct binary download, and its location must be added to the system PATH for subsequent use. Verification of the Bazel installation is performed by running bazel info in the repository root, which should display repository details without errors. To support C++ development and code navigation, the project recommends using Visual Studio Code with the clangd extension, which benefits significantly from a compilation database generated from the Bazel action graph. The initial generation of the compile_commands.json file is accomplished via the tools/setup_clangd.py script, which may require a substantial initial build exceeding thirty minutes but becomes efficient with subsequent incremental reruns. This script can alternatively be invoked through the nox testing framework, using the refresh_compile_commands test session with additional arguments forwarded to the script.

A comprehensive user guide and interactive notebooks are accessible at the torchtpu.readthedocs.io domain, with static copies of the notebooks maintained within the docs folder. These notebooks are constructed using Marimo, a framework analogous to Jupyter notebooks, and can be launched locally using the command 'marimo edit file.py', though they must be executed within a TPU virtual machine, with a v6e GCE instance being the recommended configuration. This highlights the project's reliance on specialized TPU hardware to fully exploit its capabilities and features.

The project actively encourages contributions, with detailed guidelines provided in CONTRIBUTING.md that outline the process, including the necessity to sign a Contributor License Agreement (CLA) and adhere to established code review processes. The repository is licensed under the Apache 2.0 License, ensuring broad compatibility and open use. As of the documentation, the repository has accumulated 109 stars, 6 forks, 42 issues, 214 pull requests, and 4,462 commits, reflecting its active development, community engagement, and growing adoption within the PyTorch ecosystem.