Keep compiled programs across restarts in vLLM-TorchTPU¶
Use this guide when every start of vllm serve spends minutes, or the better part of an hour for large models, compiling TPU programs, or when you need to know that a server compiles nothing after warmup. vLLM-TorchTPU pads every step to one of a fixed set of token sizes and compiles a program for each during warmup. This guide persists those programs, shortens the cold start, and catches compiles that warmup missed. Chapter 18, section "What startup compiles, and how to keep it", explains the bucket ladder; chapter 7 explains bucketing.
Prerequisites¶
- A server that starts: Serve a first model with vLLM-TorchTPU.
- A directory on a disk that survives restarts (on GKE, a persistent volume or Cloud Storage mount).
Steps¶
1. Know what each cache holds¶
| Variable | Holds | Default |
|---|---|---|
TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT |
Native torch_tpu PJRT compiled executables (.bin files); the compilation cache guide calls it "the primary driver variable required to enable persistent executable binary caching on TPU" |
not set |
VLLM_CACHE_ROOT |
vLLM's Python-level artifacts: Dynamo FX graph bytecode, guards, AOT tracing artifacts (torch_compile_cache/torch_aot_compile) and TpuCompilerAdaptor metadata (artifact_compile_range_*) |
under $HOME |
VLLM_XLA_CACHE_PATH |
Persistent XLA/PJRT compilation cache artifacts; a directory or a gs:// URI |
~/.cache/vllm/xla_cache |
The two vLLM-level caches are independent of the PJRT binaries, and each variable controls only its own cache. Set all three.
2. Point all three at persistent storage¶
export VLLM_XLA_CACHE_PATH=/mnt/cache/xla
export TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT=/mnt/cache/torch_tpu
export VLLM_CACHE_ROOT=/mnt/cache/vllm
The book's builder prints these exports in front of any profile's command:
python code/ch18_vllm/launch_profiles.py --profile v7x-8-qwen3-coder-30b-guard --cache-root /mnt/cache
On GKE, keep profile_cache under VLLM_CACHE_ROOT on an in-memory emptyDir instead (Run vLLM-TorchTPU on GKE, step 3): a persisted copy makes the free-HBM probe at startup measure nothing.
Check: after the first start, TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT contains .bin files and VLLM_CACHE_ROOT contains torch_compile_cache/.
3. Time a cold start and a warm start¶
Start the server, note the time to Application startup complete, stop it, and start it again with the same flags and environment.
Check: the second start is much shorter. If it is not, the server is not reading the directories you set: check that the variables are exported in the server's own process (on Ray, forwarded to the actors), and that no flag changed between the runs.
4. Shorten the cold start on multi-rank hosts¶
export TPU_PARALLEL_PRECOMPILE=1
export TPU_PRECOMPILE_PEER_REPLAY=1
TPU_PARALLEL_PRECOMPILE=1 compiles in parallel during warmup. With TPU_PRECOMPILE_PEER_REPLAY=1, one rank of the host compiles each compile range and the others replay it from vLLM's compile cache. Peer replay needs that cache: startup fails with VLLM_DISABLE_COMPILE_CACHE=1 (for a cold start that keeps nothing, point VLLM_CACHE_ROOT at a temporary directory instead). A waiting rank compiles the range itself after TPU_PRECOMPILE_PEER_WAIT_S (default 600 s); the default leaves room over the largest Qwen3.5-397B range at DP8, about 165 s, so raise it if your largest range takes longer.
Check: the cold start falls compared with step 3's first run.
5. Compile fewer programs¶
By default the token sizes double from 16 up to --max-num-batched-tokens, one program each: 7 at 1,024, 10 at 8,192. Each costs a compile at warmup and stays resident in HBM. Three levers:
- A smaller
--max-num-batched-tokensdrops the top sizes. --compilation-config '{"compile_sizes": [...]}'replaces the ladder with your list; the Kimi-K3 recipe compiles only[1, 8, 8192]. Keep--max-num-batched-tokenswithin the largest entry.TPU_TOKEN_BUCKET_EXTRAadds sizes (comma-separated) andTPU_TOKEN_BUCKET_LINEARuses linearly spaced buckets instead of exponential ones.
The builder prints each profile's ladder:
python code/ch18_vllm/launch_profiles.py --cpu-smoke
# v7x-8-qwen3.5-397b-dp8-ep v7x-8 8 7: [16, 32, 64, ..., 512, 1024]
# v7x-8-qwen3-coder-30b-guard v7x-8 8 10: [16, 32, 64, ..., 4096, 8192]
Check: fewer sizes means a shorter warmup; a step just past a size runs the next one up with up to half its work as padding, so do not cut sizes your traffic hits often.
6. Catch compiles that warmup missed¶
export VLLM_XLA_CHECK_RECOMPILATION=1
It queries torch.tpu._get_cache_stats() (an internal call, not part of the public API) at every precompiled bucket and every forward step and logs graphs compiled after warmup: a shape, dtype or code path warmup never reached, which stalls the engine loop on a cache miss. Use 1 in CI and test pipelines and 0 (the default) in production and benchmarking, where the per-step query costs throughput. The builder's --ci flag adds it.
Check: a CI run under realistic traffic logs no newly compiled graphs after warmup.
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
| Every restart compiles from scratch | Caches unset, on an ephemeral disk, or not exported to the server process | Steps 2 and 3 |
| Restart still slow after changing a flag | The change altered a compiled shape or a setting in the compile cache key | Expect one cold start after such a change |
| Startup fails with peer replay on | VLLM_DISABLE_COMPILE_CACHE=1 set |
Remove it; use a temporary VLLM_CACHE_ROOT for a throwaway cold start |
| Some ranks compile ranges that another rank already compiled | Waiters timed out at TPU_PRECOMPILE_PEER_WAIT_S |
Raise the wait above your largest range's compile time |
| A step after warmup takes seconds | Recompilation while serving | VLLM_XLA_CHECK_RECOMPILATION=1 in CI; keep steps within the compiled sizes |
| Throughput lower with the check on | The check queries cache stats every step | VLLM_XLA_CHECK_RECOMPILATION=0 in production and benchmarks |
| KV cache sized wrongly on GKE after a restart | profile_cache persisted |
Mount it on an in-memory emptyDir |
References¶
- vLLM-TorchTPU: Compilation Cache
- vLLM-TorchTPU: Environment Variables Reference
- vLLM-TorchTPU: Quickstart
- vLLM-TorchTPU: Kubernetes & GKE Deployment
- vLLM-TorchTPU: TPU v7x (Ironwood) Serving Recipes
- Companion code: code/ch18_vllm/
- Chapter 7: Dynamic shapes and recompilation
- Chapter 18: vLLM-TorchTPU