Tiered prefix cache on TPU¶
Use this guide when the prefix hit rate is limited by HBM: multi-turn or agentic conversations come back after their blocks were evicted, and the server recomputes a prefill it already did. Each model server offloads evicted KV blocks to host DRAM and, on TPU7x single host, to a shared filesystem, and loads them back on reuse. The router adds a second prefix scorer that tracks each pod's host tier. Chapter 20 explains the tiers.
Prerequisites¶
- The optimized baseline prerequisites (TPU node pools, boot disk, repository, CRDs, namespace, Secret).
-
One of the TPU configurations (all
CONNECTOR=native):ACCELERATOR_TYPEModel Layout VARIANTHost tier tpu/v6Qwen/Qwen3-32B3 replicas x 8 chips ( 2x4, TP=8), 32k contextcpu100 GiB per engine tpu/v7, single hostQwen/Qwen3.5-397B-A17B-FP83 replicas x 4 chips ( 2x2x1, DP=8 x TP=1, EP, fp8 KV, 262k)cpuorfs32 GiB per DP engine, 256 GiB per pod tpu/v7,HOST_TYPE=multi-hostQwen/Qwen3.5-397B-A17B-FP8LeaderWorkerSet 2x2x2, TP=16, EPcpuonly256 GiB per group, on the leader tpu/v5pQwen/Qwen3-32B3 replicas x 4 chips ( 2x2x1, TP=4)cpuTPU_OFFLOAD_NUM_CPU_CHUNKS(validated nightly)The v6e and TPU7x rows are community-maintained. The llm-d project's guide records a manual v6e validation on 2026-10-12; its nightly runs use
tpu/v5pwhile v6e capacity is unavailable. - Host memory: each engine also pins a 16 GiB staging buffer (TPU_PREMAPPED_BUFFER_SIZE), sotpu/v6pods request 900Gi (ct6e-standard-8thas 1440 GB) andtpu/v7pods 850Gi (tpu7x-standard-4thas about 919 GiB allocatable). - ForVARIANT=fs: a ReadWriteMany storage class (Managed Lustre is the validated backend,STORAGE_CLASS=lustre-class). ForHOST_TYPE=multi-host: the LeaderWorkerSet controller.
Steps¶
1. Set the environment¶
export REPO_ROOT=$(realpath $(git rev-parse --show-toplevel))
export GUIDE_NAME=tiered-prefix-cache
export NAMESPACE=llm-d-tiered-prefix-cache
export MONITORING=false
export MONITORING_VALUES=
export ACCELERATOR_TYPE=tpu/v7 # tpu/v5p, tpu/v6 or tpu/v7
export MODEL_SERVER=vllm
export CONNECTOR=native
export VARIANT=cpu # cpu = host DRAM, fs = host DRAM + shared filesystem (single host only)
export INFRA_PROVIDER=gke
export HOST_TYPE=single-host # multi-host: tpu/v7 and VARIANT=cpu only
export STORAGE_CLASS= # VARIANT=fs only, for example lustre-class
export MODEL=Qwen/Qwen3.5-397B-A17B-FP8 # Qwen/Qwen3-32B on tpu/v5p and tpu/v6
source ${REPO_ROOT}/guides/env.sh
export ROUTER_BASE_VALUES="${REPO_ROOT}/guides/recipes/router/base.values.yaml"
export ROUTER_VALUES="${REPO_ROOT}/guides/${GUIDE_NAME}/router/${HOST_TYPE}/${GUIDE_NAME}-cpu.values.yaml"
Check: ls ${ROUTER_VALUES} finds the file; a wrong HOST_TYPE gives a missing path.
2. Size the router's host-tier index, then deploy the router¶
vLLM does not report its host tier size, so the CPU producer's capacity is set by hand in router blocks of 64 tokens:
lruCapacityPerServer = host tier bytes per pod / (64 x KV bytes per token)
The shipped single-host value, 19200, is for the default NVIDIA overlay. For Qwen3-32B (256 KiB per token, so 16 MiB per block), a 100 GiB tier gives 6400 by this formula; set it for tpu/v6. On TPU7x single host, layer the TPU7x values instead, which set 4352-token blocks, a 262k match window and the 8 x 32 GiB tier, the same values as the Qwen3.5-397B model guide:
# TPU7x single host: add -f ${REPO_ROOT}/guides/${GUIDE_NAME}/router/single-host/tpu-v7.values.yaml after ROUTER_VALUES
helm install ${GUIDE_NAME} \
${ROUTER_STANDALONE_CHART} \
-f ${ROUTER_BASE_VALUES} \
${MONITORING_VALUES} \
-f ${ROUTER_VALUES} \
-n ${NAMESPACE} --version ${ROUTER_CHART_VERSION}
The release name must be ${GUIDE_NAME}. With HOST_TYPE=multi-host the router values route only to the LeaderWorkerSet leaders.
Check: the EPP pod is Running.
3. Provision the filesystem tier (VARIANT=fs only)¶
# ReadWriteMany PVC for the filesystem tier, mounted at /mnt/files-storage
envsubst < ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/pvc.yaml | kubectl apply -n ${NAMESPACE} -f -
kubectl get pvc llm-d-kv-cache-storage -n ${NAMESPACE}
On TPU7x the storage tier is part of TorchTPU's TPURaidenOffloadingConnector: every offloaded block is written to the host tier and, write-through, to raiden_storage_path (/mnt/files-storage/kv in the overlay). On a miss in HBM and host DRAM, a block found in storage is recalled through host staging blocks into HBM. Every pod sets PYTHONHASHSEED=0, because storage keys are prefix-block hashes; the engine refuses to start the tier without it. The overlay also sets raiden_storage_properties.direct_io: true, a metadata cache of 1048576 entries and an 86400 s metadata TTL. The tier refuses to start under pipeline parallelism, files are keyed by TP and PCP rank (a new DP or TP means a new directory), and the connectors never evict: capacity is the storage system's job.
Check: the PVC is Bound.
4. Deploy the model servers¶
# HOST_TYPE=single-host
kubectl apply -n ${NAMESPACE} \
-k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/${ACCELERATOR_TYPE}/${MODEL_SERVER}/${CONNECTOR}/${VARIANT}/${INFRA_PROVIDER}/
# HOST_TYPE=multi-host: TPU v7 LeaderWorkerSet, Qwen/Qwen3.5-397B-A17B-FP8
kubectl apply -n ${NAMESPACE} \
-k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/tpu/v7/vllm/native/cpu/multi-host/
On tpu/v6 and tpu/v7 the host tier is TorchTPU's TPU Sync store: TPURaidenOffloadingConnector (vllm_torchtpu.offload.raiden_connector, kv_role: kv_both) with TPU_USE_RAIDEN_KV_CACHE_MANAGER=1 and TPU_VLLM_ENABLE_UNIFIED_BLOCK_POOL=1. HBM (--gpu-memory-utilization=0.90) is checked first, then host DRAM, then the filesystem; with write-through, the filesystem holds every block offloaded to host DRAM.
On TPU7x single host, an evicted block goes to host DRAM and, write-through, to the shared filesystem at the same time; a later hit loads it back, and a block found only in storage comes up via host staging blocks. A lookup tries the fastest tier first, and nothing evicts from the filesystem: its capacity is the storage system's job.
Check: confirm the served model matches MODEL (on multi-host only leaders, worker index 0, serve port 8000):
POD=$(kubectl get pods -n ${NAMESPACE} -l llm-d.ai/guide=${GUIDE_NAME} \
-o go-template='{{range .items}}{{$i := index .metadata.labels "leaderworkerset.sigs.k8s.io/worker-index"}}{{if or (not $i) (eq $i "0")}}{{.metadata.name}} {{end}}{{end}}' | awk '{print $1}')
SERVED=$(kubectl get --raw "/api/v1/namespaces/${NAMESPACE}/pods/${POD}:8000/proxy/v1/models" \
| grep -o '"id": *"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/')
echo "model servers serve: ${SERVED}"
It prints ${MODEL}.
5. Verify that blocks reach the offload tier¶
Get IP as in Optimized baseline, step 4, and send its 10-request shared-prefix burst (step 5 there). Then read the offload counters:
for pod in $(kubectl get pods -n ${NAMESPACE} -l llm-d.ai/guide=${GUIDE_NAME} \
-o go-template='{{range .items}}{{$i := index .metadata.labels "leaderworkerset.sigs.k8s.io/worker-index"}}{{if or (not $i) (eq $i "0")}}{{.metadata.name}} {{end}}{{end}}'); do
echo "== ${pod}"
kubectl get --raw "/api/v1/namespaces/${NAMESPACE}/pods/${pod}:8000/proxy/metrics" \
| grep -E '^vllm:(kv_offload_(store|load)_bytes_total|external_prefix_cache_(hits|queries)_total)' || true
done
Check: on the TPU connectors, vllm:external_prefix_cache_queries_total counts prompt tokens looked up in the offload tier on the pod that served the burst. For VARIANT=fs on TPU7x, the guide's validation primed a 22k-token prompt on one pod and restored it from the filesystem on a fresh pod: vllm:external_prefix_cache_hits_total grew on the second pod and the output was identical.
6. Watch the path under load¶
| Signal | What it tells you |
|---|---|
vllm:external_prefix_cache_hits_total / vllm:external_prefix_cache_queries_total beside vllm:prefix_cache_hits_total |
Under pressure the HBM rate drops and the offload rate should take up the difference |
vllm:kv_offload_store_bytes_total, vllm:kv_offload_load_bytes_total |
Steady stores with no loads: the tier costs memory and saves no prefill |
vllm:kv_offload_load_bytes_total / vllm:kv_offload_load_time_total |
A load must beat the prefill it replaces (host to device copy only) |
vllm:kv_offload_allocation_failure_total |
Stores that found no free host blocks; the server logs cannot store chunks |
llm_d_epp_prefix_indexer_size, llm_d_epp_prefix_indexer_hit_ratio by plugin_name |
What the router believes each tier holds |
vllm:time_to_first_token_seconds |
Compare against an HBM-only run at the same load |
The bundled alerting rules do not cover offloading yet.
Check: the offload hit rate is non-zero under sustained load and TTFT is no worse than the HBM-only baseline.
7. Clean up¶
kubectl delete -n ${NAMESPACE} -k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/${ACCELERATOR_TYPE}/${MODEL_SERVER}/${CONNECTOR}/${VARIANT}/${INFRA_PROVIDER}
# multi-host: kubectl delete -n ${NAMESPACE} -k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/tpu/v7/vllm/native/cpu/multi-host
kubectl delete -n ${NAMESPACE} -f ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/pvc.yaml --ignore-not-found=true
helm uninstall ${GUIDE_NAME} -n ${NAMESPACE}
kubectl delete namespace ${NAMESPACE}
Check: the namespace is gone. Files written to the shared filesystem stay until the storage system removes them.
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
| Store counters stay at zero | Connector not active | Check the pod's --kv-transfer-config |
| Offload hit rate near zero while HBM hit rate falls | Blocks not stored, or evicted before reuse | Flat stores: connector; steady stores and no loads: grow cpu_bytes_to_use within the pod memory limit |
| Router CPU-index hit ratio well above the servers' | lruCapacityPerServer larger than the tier really holds |
Lower it to the formula's value |
| TTFT worse than HBM only | Loads slower than recompute | Load speed; on fs, the storage read throughput |
| Steady allocation failures | Host blocks held by in-flight transfers | Increase cpu_bytes_to_use |
| Filesystem tier refuses to start | PYTHONHASHSEED unset, or pipeline parallelism |
Keep the overlay's PYTHONHASHSEED=0; no PP with the storage tier |
fs hits missing on multi-host |
The storage tier is single host only | Use VARIANT=cpu with HOST_TYPE=multi-host |
