> ## Documentation Index
> Fetch the complete documentation index at: https://miles.radixark.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google TPUs

> Run Miles on Google Cloud TPU v7x through torch_tpu, with the torchtitan trainer and sglang-torchtpu sharing one host.

Miles runs on Google Cloud TPU v7x through [torch\_tpu](https://github.com/google-pytorch/torch_tpu).
The torchtitan backend trains and [sglang-torchtpu](https://github.com/sgl-project/sglang-torchtpu)
serves rollouts as an external engine. Megatron-LM is not supported on TPU.

## Layout

One v7x 2x2x1 host has 4 chips with 2 TensorCores each, so 8 devices. The trainer runs as 4 ranks
on devices 0-3 and the engine serves on devices 4-7. Both jobs share the host's slice, so weights
move from trainer to engine over ICI (`--update-weight-transfer-mode ici`) without touching disk.

## Image

The engine and the trainer share one Python environment, built by `docker/Dockerfile.tpu` on
sglang-torchtpu's release image. CI rebuilds it next to the CUDA image and publishes it as
`radixark/miles:dev-tpu` (and `latest-tpu`). To build it yourself:

```bash theme={null}
python docker/build.py --variant tpu --image-tag dev    # radixark/miles:dev-tpu
```

To set the environment up by hand instead, see
[`scripts/tpu/README.md`](https://github.com/radixark/miles/blob/main/scripts/tpu/README.md#environment).

## Launch training

The TPU launchers live under `scripts/tpu/`, one per model family: Qwen3-4B, Qwen3-30B-A3B, a 4-layer
GLM-4.7-Flash, and `run_qwen3_5_torchtitan.py` for Qwen3.5 / Qwen3.6 / Qwen3.8, which picks its row with
`--model-name` (`Qwen3.5-4B`, `Qwen3.5-27B`, `Qwen3.6-35B-A3B` or `Qwen3.8-27B`). Each launcher has a `prepare`, a `sglang` and a `train` command. `prepare` fetches the model and
datasets. Start the engine in its own shell, then start training a minute or two later without waiting for the
engine's `/health`: the engine compiles only after the trainer has joined the slice.

```bash theme={null}
python3 scripts/tpu/run_qwen3_4b_torchtitan.py prepare
python3 scripts/tpu/run_qwen3_4b_torchtitan.py sglang               # devices 4-7
python3 scripts/tpu/run_qwen3_4b_torchtitan.py train --recipe full  # devices 0-3
```

The first step of a cold run compiles the trainer's programs, and sglang has to be restarted with
every training run. The
[README](https://github.com/radixark/miles/blob/main/scripts/tpu/README.md) covers both, along with
the recipes, the compile cache, and per-model trainer settings.

## Next steps

* [`scripts/tpu/README.md`](https://github.com/radixark/miles/blob/main/scripts/tpu/README.md) — the full recipe and operating notes.
* [Docker build](https://miles.radixark.com/docs/developer/ci/02-docker-build) — the TPU Dockerfile, variants, and tags.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.