vllm-torchtpu¶
What it is. A vLLM platform plugin, not a fork: upstream vLLM's CLI, OpenAI server, scheduler and KV cache manager run unchanged, and the plugin (package vllm_torchtpu) supplies the TPU platform, one TPUWorker per device, a model runner under torch.compile(backend="tpu"), and Pallas kernels as custom ops. TPU v7x is recommended and validated in CI; v6e is supported, without CI, with reference recipes; v5e, v5p and v4 are experimental. Upstream: https://github.com/vllm-project/vllm-torchtpu. The book teaches it in chapter 18 and the serving guides.
Layout¶
| Path | What lives there |
|---|---|
src/vllm_torchtpu/platforms/ |
TpuPlatform (tpu_platform.py) and register_tpu_platform, the entry point vLLM discovers |
src/vllm_torchtpu/worker/, runner/ |
TPUWorker (one per device) and TPUModelRunner (subclasses vLLM's GPUModelRunner; pads every step to a compiled size) |
src/vllm_torchtpu/compilation/ |
The bridge from vLLM's compilation to the TorchTPU backend |
src/vllm_torchtpu/layers/ |
TPU layers: adapter/attention.py (attention backends), MoE, linear, quantization, custom ops |
src/vllm_torchtpu/kernels/ |
Pure JAX and Pallas kernels: ragged_paged_attention/, mla/, fused_moe/, megablox/, gdn/, sparse_core/, quantized_matmul/ |
src/vllm_torchtpu/distributed/, offload/ |
Parallelism, multi-host bootstrap, KV transfer (kv_transfer/tpu_connector.py), host KV offload |
src/vllm_torchtpu/models/, spec_decode/ |
TPU model implementations and model patches; speculative decoding proposers |
src/vllm_torchtpu/patch_registry.py, envs.py |
Every runtime patch of upstream vLLM, in one ordered tuple; every TPU environment variable |
examples/, scripts/ |
Offline inference and profiling scripts; benchmarking harness, tuners, multi-host scripts |
docs/ |
getting_started/, user_guide/, deployment/, developers_guide/, reference/env_vars.md |
tests/, tests_omni/ |
pytest suites by subsystem; tests for the vLLM-Omni platform |
Entry points¶
| Command, flag or variable | What it does | Source | Taught in |
|---|---|---|---|
export UV_TORCH_BACKEND=cpu; uv pip install vllm-torchtpu |
Installs vLLM, the plugin, torch-tpu and libtpu, with CPU torch (Python 3.12) |
docs/getting_started/installation.md |
Ch 18, quickstart |
python -c "from vllm.platforms import current_platform; print(current_platform.device_name)" |
Confirms vLLM loaded the TPU platform | installation guide | Ch 18 |
vllm.platform_plugins and vllm.general_plugins entry points |
register_tpu_platform returns TpuPlatform; register_layers registers TPU layers, models, tokenizers |
pyproject.toml |
Ch 25 |
vllm serve MODEL --tensor-parallel-size N --max-model-len L |
The OpenAI-compatible server on port 8000 | upstream vLLM | Ch 18 |
vllm.LLM(...), examples/offline_inference.py |
Offline batch inference with engine arguments as keywords or flags | examples | offline guide |
--max-num-batched-tokens, --max-num-seqs, --gpu-memory-utilization, --kv-cache-dtype fp8, --block-size |
The flags that fix compiled sizes, decode batch and HBM split on TPU | upstream vLLM | Ch 18, serving flags |
--attention-backend CUSTOM |
Batched ragged paged attention variant used by most recipes; RPA v3 is the default | layers/adapter/attention.py |
Ch 18 |
--data-parallel-size, --enable-expert-parallel, --pipeline-parallel-size, --prefill-context-parallel-size, --decode-context-parallel-size |
The parallelism dimensions; a group uses DP × TP × PP × PCP logical devices | upstream vLLM | parallelism guide |
--quantization, --speculative-config '{"method": ...}' |
Quantized checkpoints; six speculative methods | upstream vLLM | quantization, speculative |
VLLM_XLA_CACHE_PATH, TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT, VLLM_CACHE_ROOT |
The three cache roots to persist across restarts | docs/user_guide/compilation_cache.md |
cache guide |
TPU_PARALLEL_PRECOMPILE=1, TPU_PRECOMPILE_PEER_REPLAY=1 |
Parallel warmup; one rank per host compiles each size and the others replay it | envs.py |
Ch 18 |
VLLM_XLA_CHECK_RECOMPILATION=1 |
Logs any graph compiled after warmup; for CI, not production | envs.py |
Ch 18 |
TPU_MULTIHOST_BACKEND, --nnodes, --node-rank, --master-addr, --headless |
Multi-host serving with the default mp backend, no Ray |
docs/user_guide/multihost.md |
multi-host guide |
--kv-transfer-config '{"kv_connector": "TPURaidenConnector", ...}' |
Disaggregated prefill (kv_producer) and decode (kv_consumer). The class is TPURaidenConnector in vllm_torchtpu.distributed.kv_transfer.tpu_connector; the repository's disaggregation guide spells it TpuRaidenConnector in a raiden.raiden_connector module, which does not exist |
distributed/kv_transfer/tpu_connector.py |
disaggregation guide |
examples/tpu_profiling.py, --profiler-config.profiler torch with /start_profile and /stop_profile, USE_PHASED_PROFILER=true |
Offline, server-side and phased XProf capture | docs/developers_guide/profiling/ |
profiling guide, Ch 10 |
python -m vllm_torchtpu.tools.merge_xplane <dir> |
Merges per-rank XPlane files; keep the result out of plugins/profile/<timestamp>/ |
tools/merge_xplane.py |
Ch 10 |
vllm bench serve ..., scripts/vllm/benchmarking/run_benchmarks.sh --config NAME |
Serving benchmark client; the repository's sweep and regression harness | upstream vLLM; scripts | benchmarking guide |
VLLM_TPU_BLOCK_MAJOR_KV=1 |
Block-major KV layout: a page moves in one DMA | envs.py |
Ch 18 |
Extension points¶
| You want to | Use | Taught in |
|---|---|---|
| Change a layer for TPU | register_oot or CustomOp registration in layers/adapter/ |
Ch 25 |
| Fix upstream behaviour that subclassing cannot reach | One Patch entry in PATCHES (patch_registry.py), stages import, platform_activation, engine_core, worker_init, model_load |
Ch 25 |
| Patch one model | src/vllm_torchtpu/models/vllm/<model>_patch.py returning False when the model does not match; registered at ("platform_activation", "model_load") |
Ch 25 |
| Add a kernel | kernels/, pure JAX and Pallas: the ruff rule TID251 bans torch, torch_tpu and vllm imports there; bridge it from layers/adapter/ |
Ch 12, Ch 25 |
Tests¶
uv pip install --prerelease=allow -e . --group vllm --group test # test dependencies
JAX_PLATFORMS=cpu pytest tests/ -m "not tpu_test and not multichip and not nightly" # CPU, as CI runs it
pytest tests/ -m "tpu_test and not nightly and not multichip" # on a TPU VM
pytest -q tests/platforms/test_patch_registry.py # after a registry change
TPU tests carry @pytest.mark.tpu_test (one v7x chip in CI) or multichip; unmarked tests run on a CPU pod, so module imports must work on a CPU. The full command list is in docs/developers_guide/testing_and_ci.md.