TPU Runner
tpu-runner is a job orchestrator designed to maximize utilization of your Google Cloud TPU allocation.
It races capacity requests across compatible TPU types and regions, assigns jobs efficiently, retries jobs interrupted by Spot preemptions, and automatically scales capacity with demand. It also minimizes inter-region transfer costs, prepares a clean workspace for new jobs, and lets related jobs reuse local caches (e.g. for previously compiled XLA artifacts or software environments).
We use Firestore for queue and orchestration state, GCS for source bundles and job artifacts, and a Cloud Run controller to manage TPU capacity and execution.
Install
Install tpu-runner as a standalone CLI:
uv tool install tpu-runner
For local development, run this from the repository root:
uv tool install --editable .
Configure gcloud:
gcloud auth login
gcloud auth application-default login
gcloud config set project YOUR_PROJECT_ID
Set up the runner
Create an example deployment:
tpu-runner init
Edit deployment.yaml with your project ID, existing Secret Manager secret names, and the TPU types, zones, maximum counts, runtime versions, and chip limits you are willing to use. Counts are provisioning ceilings and TPU Runner scales capacity up and down with demand, keeping idle capacity only when keep_warm is enabled.
The default ssh_transport: direct creates public-IP TPUs; set it to iap to create private-IP TPUs and reach them through IAP tunnels instead.
Validate and deploy:
tpu-runner validate-fleet deployment.yaml
tpu-runner deploy deployment.yaml
deploy enables the required APIs and creates or updates the runner bucket, Firestore database, service accounts and IAM, SSH identity, worker startup script, controller image, and Cloud Run controller job.
Submit work
In the root of the code you want to run, create job.yaml:
jobs:
- tpu: [v4-32, v6e-64]
buckets:
- gs://my-training-us-central2
- gs://my-training-us-east1
bundle: .
priority: high
caches:
- key: pip
path: .cache/pip
env:
PIP_CACHE_DIR: .cache/pip
WANDB_PROJECT: my-project
command: python3 -m pip install -r requirements.txt && touch "$PIP_CACHE_DIR/.ready" && python3 train.py --data "$JOB_BUCKET/data" --checkpoints "$CHECKPOINT_GCS_DIR"
tpumay contain one or several compatible TPU types to race.- Omit
zoneandtpu_nameto race all compatible fleet capacity. Setzoneto use one zone, ortpu_nameto use one exact declared TPU. - Create one listed bucket in each candidate region and mirror required data at
the same object paths. For a single-region job, list one bucket. The winning
region's bucket becomes
JOB_BUCKET, and retries remain pinned to that region. bundleis a local directory relative tojob.yaml. TPU Runner archives and uploads it; use.tpu-runnerignoreto exclude files.prioritymay below,normal, orhigh.- Before a new job starts, TPU Runner clears the previous runner workspace,
then extracts the new bundle into a fresh directory. A directory
declared under
cachesis preserved when it is marked.readyand the next job on that worker declares the samekey. Configure the relevant tool, such as pip, to write to the cache path. Incomplete caches are discarded, and all caches disappear when the TPU is deleted. commandruns independently on every TPU worker. Other runner-provided variables includeJOB_ID,ATTEMPT_ID,TPU_WORKER_HOST,TPU_WORKER_COUNT,JOB_DIR, andATTEMPT_GCS_DIR.
Submit and watch the job:
tpu-runner validate-jobs job.yaml
tpu-runner submit job.yaml
tpu-runner watch JOB_ID
tpu-runner logs JOB_ID
tpu-runner cancel JOB_ID
Spot preemption and infrastructure failures return a job to
pending with the same region and checkpoint directory. Application and setup
failures are terminal. TPU Runner schedules higher-priority jobs first. Within
each priority it considers the most constrained jobs first and moves flexible
jobs to alternative idle TPUs when that allows more jobs to run.
TPU Runner stores job bundles, logs, diagnostics, status, and checkpoints in the job’s GCS bucket,
while your application data remains in the GCS buckets you provide.
Use tpu-runner --help for a list of all commands, or use a specific command such as tpu-runner submit --help for its options.
PRs and feature requests are welcome. Thank you to the Google TPU Research Cloud (TRC) program for inspiring this work.
Metadata
Release files for tpu-runner 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tpu_runner-0.1.2.tar.gz | 66.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tpu_runner-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 136.8 kB
Release files / tpu_runner-0.1.2.tar.gz
| Download URL | tpu_runner-0.1.2.tar.gz |
|---|---|
| Size | 66.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9853db66143cb402503f4749f2fc11e3701d9e16f456292a2f048a4a020ceac8
|
|
BLAKE2b-256 checksum How to use checksums |
9d556b7db52034bbdf419d16ce4563ac32d419945773455271a9c3ee3666259c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / tpu_runner-0.1.2-py3-none-any.whl
| Download URL | tpu_runner-0.1.2-py3-none-any.whl |
|---|---|
| Size | 70.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
851221d46b48615e39ec15da799079c847150129744e40c9ffc99516458c7c1d
|
|
BLAKE2b-256 checksum How to use checksums |
85445baeb484ab502d45efb16757df15ebe2c31cfac37a9d581f580d64d99797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|