Skip to content

vLLM-TorchTPU

40 min read

Prerequisites: Dynamic shapes and recompilation, Inference math: prefill, decode, KV cache

Chapter 17 gave you the arithmetic of serving: decode is bound by HBM bandwidth, prefill by the MXU, and the KV cache decides how many users fit. This chapter puts a real engine on top of that arithmetic. vLLM-TorchTPU is vLLM with a TPU platform plugin underneath: the same vllm serve command, the same OpenAI-compatible server, scheduler and KV cache manager you use on GPUs, with the model compiled by torch.compile(backend="tpu") and attention, MoE and quantized matmuls running as Pallas kernels. You will install it, start a first server and an offline batch, then learn the handful of flags that behave differently on TPU because every step runs a precompiled program of fixed shape. From there the chapter covers parallelism, quantization and speculative decoding as the documentation's recipes use them, the differences between v6e and v7x, and how to benchmark with vllm bench serve. It ends with the three checks that tell you a deployment is right: a smoke request, a TPOT you can explain against chapter 17's floor, and a parity gate against outputs you trust.

What this chapter covers

  • How vLLM-TorchTPU plugs into upstream vLLM, and a first OpenAI-compatible server and offline batch on a Cloud TPU VM.
  • The serving flags that behave differently on TPU (--max-model-len, --max-num-batched-tokens, --max-num-seqs, --gpu-memory-utilization, --kv-cache-dtype, --block-size), the compilation caches, and the token buckets and KV capacity a configuration implies.
  • TP, DP plus EP, PP and context-parallel layouts, quantization methods and speculative decoding as the v6e and v7x recipes use them.
  • TTFT and TPOT measured with vllm bench serve and the chapter's client, and read against chapter 17's decode floor.
  • Failure modes (long warmup compiles, KV cache exhaustion, recompilation while serving, unsupported models) and a parity gate for every rollout.

How vLLM-TorchTPU plugs into vLLM

vLLM-TorchTPU is an out-of-tree vLLM platform plugin, not a fork. The coding guidance states the design rule plainly: "This repo exists to add TPU behavior to vLLM, not to re-implement vLLM." When the package is installed, vLLM finds it through the vllm.platform_plugins entry point, which returns the class TpuPlatform; a second entry point under vllm.general_plugins registers the TPU layers, models and tokenizers. Nothing in your launch command names the plugin. vllm serve on a TPU VM simply finds a platform that claims the hardware.

Layered diagram in three dashed bands stacked top to bottom. The top amber band, Upstream vLLM, holds OpenAI API server on the left, Scheduler in the middle and KV cache manager on the right; an arrow labelled requests runs from OpenAI API server to Scheduler, and an arrow labelled allocate blocks runs from Scheduler to KV cache manager. The middle blue band, vllm_torchtpu plugin, holds TpuPlatform on the left, TPUWorker in the middle directly below Scheduler, and TPUModelRunner on the right; an arrow labelled SchedulerOutput runs down from Scheduler to TPUWorker, and an arrow labelled execute_model runs from TPUWorker to TPUModelRunner. The bottom teal band, TorchTPU on TPU, holds Paged KV cache on the left, Pallas kernels in the middle and XLA program on the right, directly below TPUModelRunner; an arrow labelled pad to bucket runs down from TPUModelRunner to XLA program, an arrow labelled custom ops runs from XLA program to Pallas kernels, and an arrow labelled read and write runs from Pallas kernels to Paged KV cache.

Read the path from top left: everything in the amber band is upstream vLLM code, unchanged. The plugin starts where the scheduler hands a batch to a worker, and the TPU-specific cost appears at "pad to bucket".

The three bands map onto what you will configure and debug:

  • Upstream vLLM (unchanged). The OpenAI-compatible API server, the scheduler (continuous batching, chunked prefill, prefix caching) and the KV cache manager that hands out blocks are the same code that runs on GPUs. The launch post lists the CLI, the server, the scheduler and the KV cache manager as deliberately the same, and that is why every flag in this chapter is a vLLM flag.
  • The plugin. TpuPlatform tells vLLM how to run on TPU. Each TPU device gets its own worker process, TPUWorker, "the same way vLLM runs on GPUs", and devices communicate through torch.distributed. TPUModelRunner subclasses vLLM's GPUModelRunner and runs the model under torch.compile(backend="tpu", fullgraph=True). Before each step it pads the batch to a precompiled size, which is where TPU serving differs most from GPU serving.
  • TorchTPU on the TPU. The compiled graph lowers to one XLA program. Kernels that benefit from hand tuning are JAX/Pallas kernels registered as custom ops (the bridge is torch_tpu._internal.pallas.jax_op, the same one chapter 12 used) and called from inside that program: Ragged Paged Attention v3 for MHA and GQA models, MLA kernels for DeepSeek, Kimi and GLM, Gated DeltaNet and Kimi Delta Attention for hybrid models, fused MoE, and fp8, int8, MXFP4 and NVFP4 matmuls.

How the plugin changes upstream behaviour. Some TPU behaviour cannot be added by subclassing, so the plugin patches it, and every patch is registered in one ordered tuple, PATCHES in src/vllm_torchtpu/patch_registry.py. Each entry names a callable and the lifecycle stages it runs at: import, platform_activation (inside TpuPlatform.check_and_update_config), engine_core, worker_init (in TPUWorker.__init__) and model_load. The stages are entry points in different processes, not one sequence, and completion is tracked per process. A spawned worker starts with an empty registry, which is why shared patches are registered for both platform_activation and worker_init. You need this model only when you read a startup log: the registry logs Completed TPU patch callbacks at <stage>: ..., and the developer guide warns that the line includes permanent no-ops, so it does not prove a feature was exercised. Chapter 25 shows how to add a patch.

Which hardware. The setup guide calls TPU v7x (Ironwood) recommended and validated in CI on every pull request, TPU v6e (Trillium) supported but not covered by CI, and v5e, v5p and v4 experimental. The launch post groups v6e with the experimental generations. This chapter follows the setup guide, which is the more specific statement, and treats v6e recipes as reference configurations, which is how the v6e recipe page describes itself.

Install and serve a first model

You need a TPU VM with Python 3.12 (chapter 8 covers capacity; the vLLM-TorchTPU setup guide provisions v7x through queued resources and v6e through Compute Engine). Check the devices are visible with ls /dev/vfio/ before installing.

The recommended install uses uv and routes torch to the PyTorch CPU wheel index, because default PyPI serves CUDA builds of torch on Linux x86_64 that pull gigabytes of nvidia-* packages onto a TPU host:

uv venv --python 3.12 ~/uv_venv
source ~/uv_venv/bin/activate

# Route torch and torchvision to the PyTorch CPU index
export UV_TORCH_BACKEND=cpu

uv pip install vllm-torchtpu

With pip, pass --extra-index-url https://download.pytorch.org/whl/cpu instead. The vllm-torchtpu package installs upstream vllm (built with VLLM_TARGET_DEVICE="empty", which skips the CUDA extensions) and pulls vllm-torchtpu-core, the plugin itself, together with torch-tpu, libtpu and tpu-sync-torch. The guide currently pins vllm==0.32.0 for source installs. Confirm that vLLM sees the plugin:

python -c "from vllm.platforms import current_platform; print(current_platform.device_name)"

The package also installs tpu-info, which shows chip utilization and HBM in use at any time. A prebuilt image is the other route: vllm/vllm-torchtpu:latest for serving, :nightly when you also need the test and benchmark tools, run with --privileged, --net=host and --shm-size 150gb so the container reaches the /dev/vfio devices.

Start the quickstart's single-device server:

vllm serve meta-llama/Llama-3.2-1B-Instruct \
  --tensor-parallel-size 1 \
  --max-model-len 4096 \
  --port 8000

The first start is slow. The launch post says the first startup "compiles TPU graphs for the configured shapes, which can take a few minutes"; the next section explains what is being compiled and how to keep it. Wait for the log line Application startup complete, then send the quickstart's request from another terminal:

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.2-1B-Instruct",
    "messages": [
      {"role": "user", "content": "Explain how Tensor Processing Units accelerate matrix multiplication."}
    ],
    "max_tokens": 128,
    "temperature": 0.0
  }'

Offline batch inference uses the same engine through vllm.LLM, with engine arguments as keyword arguments (tensor_parallel_size= for --tensor-parallel-size, and so on):

from vllm import LLM, SamplingParams

prompts = [
    "Hello, my name is",
    "The capital of France is",
    "The future of AI hardware is",
]

sampling_params = SamplingParams(temperature=0.0, max_tokens=64)
llm = LLM(
    model="meta-llama/Llama-3.2-1B-Instruct",
    tensor_parallel_size=1,
    max_model_len=1024,
)

outputs = llm.generate(prompts, sampling_params)
for output in outputs:
    print(f"Prompt: {output.prompt!r}")
    print(f"Generated: {output.outputs[0].text!r}\n")

The repository wraps this in examples/offline_inference.py, which accepts every engine flag on the command line (python examples/offline_inference.py --model meta-llama/Llama-3.2-1B-Instruct --tensor-parallel-size 1 --max-model-len 1024), applies the chat template when the tokenizer has one, and starts and stops the profiler when a torch profiler directory is configured. Use offline mode to produce reference outputs and to profile (chapter 10); use the server for anything with latency.

What startup compiles, and how to keep it

There is no CUDA graph capture on TPU. Instead, the runner pads each step to one of a fixed set of token counts, compiles a program for each size during warmup, and dispatches every later step to the program for its size. In the plugin source, dynamic compile ranges are disabled, upstream @torch.compile(dynamic=True) decorators are unwrapped, and every step is padded to an exact entry in compilation_config.compile_sizes. This is chapter 7's bucketing, run by the engine for you.

Which sizes. When you do not set compile_sizes, the sizes double from 16 and the last one is exactly --max-num-batched-tokens; _get_token_paddings in the plugin's platform code builds the list. A budget of 1,024 compiles 16, 32, 64, 128, 256, 512 and 1,024: seven programs. A budget of 8,192 compiles ten. --compilation-config '{"compile_sizes": [...]}' replaces the ladder with your own list; the Kimi-K3 recipe on v7x-32 compiles only [1, 8, 8192]. Two environment variables extend the default ladder: TPU_TOKEN_BUCKET_EXTRA adds specific sizes and TPU_TOKEN_BUCKET_LINEAR uses linearly spaced buckets instead of exponential ones.

Two charts titled Token buckets: what the per-step token budget compiles, and what a step wastes. Left, for a token budget of 8192 with 10 sizes from 16 to 8,192: the share of the compiled step that is padding, in percent, against tokens scheduled in the step on a log2 axis from 1 to 8,192. The curve falls from 94% at 1 token to 0 at 16, then forms a sawtooth that jumps back to about 50% just past each power of two and falls to 0 at the next one. Orange points mark 17 tokens running the 32 program, 257 tokens running the 512 program, and 4,097 tokens running the 8,192 program. Right, v7x CI benchmark configs, horizontal bars of token sizes compiled at warmup: Qwen3.5-397B-A17B-FP8 with TP=1 DP=8, DeepSeek-V4-Flash with TP=1 DP=8 and GLM-5.2-FP8 with TP=1 DP=16 each 7 sizes with budget 1,024; Qwen3-Coder-30B-FP8 TP=8 (the PR guard) and Qwen3-Coder-480B-FP8 TP=8 each 10 sizes with budget 8,192; Kimi-K3 TP=32 with compile_sizes set, in green, 3 sizes, budget 8,192 (1, 8, 8,192).

This chart is arithmetic, not a measurement: the left panel applies the bucket rule to a token budget, and the right panel applies it to the v7x CI benchmark configs. Every tooth on the left is a compiled program; a step pays up to half its MXU work in padding just past each boundary. On the right, the budget a recipe picks sets how many programs warmup builds, unless the recipe lists them itself, as Kimi-K3 does.

Three things follow from the ladder. A larger --max-num-batched-tokens adds programs, so warmup gets longer, and each compiled program stays resident in HBM. A step just past a size runs the next one up: 257 tokens run the 512 program with 50% padding. And a step that would exceed the largest compiled size cannot run, so keep --max-num-batched-tokens within the largest compile_sizes entry. The chapter's launch_profiles.py refuses a configuration that breaks it.

How long. Long enough to plan for. The environment variable reference sizes the default wait for a peer compile against "the biggest Qwen3.5-397B range at DP8 (about 165 s with every rank of the host compiling)", and the repository's GKE JobSet for multi-host benchmarks raises its deadline to eight hours "because these models compile for the better part of an hour before the sweep starts".

Keeping it across restarts. Three cache roots matter, and the documents describe them at different levels:

Variable What it holds Where documented
VLLM_XLA_CACHE_PATH persistent XLA/PJRT compilation cache, default ~/.cache/vllm/xla_cache, also a gs:// URI env vars reference; the quickstart and launch post name it for reuse across restarts
TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT native torch_tpu PJRT executables (.bin files) compilation cache guide, which calls it "the primary driver variable required to enable persistent executable binary caching on TPU"
VLLM_CACHE_ROOT vLLM's Python-level artifacts: Dynamo FX graphs, guards, AOT tracing artifacts compilation cache guide; independent of the PJRT binaries

The quickstart names only VLLM_XLA_CACHE_PATH, while the compilation cache guide names the other two and calls the Tier-3 root the primary one. They are not alternatives: each holds different artifacts, and the repository's own GKE manifest sets VLLM_XLA_CACHE_PATH and VLLM_CACHE_ROOT on persistent storage. Set all three on a persistent disk; launch_profiles.py --cache-root DIR does that. On GKE, the deployment guide adds one exception: keep profile_cache (under VLLM_CACHE_ROOT) on an in-memory emptyDir, because a persisted copy makes the free-HBM probe at startup measure nothing.

Shortening a cold start. TPU_PARALLEL_PRECOMPILE=1 compiles in parallel during warmup. Add TPU_PRECOMPILE_PEER_REPLAY=1 and each compile range is compiled by one rank of the host and replayed by the others from vLLM's compile cache; startup fails if the compile cache is disabled with VLLM_DISABLE_COMPILE_CACHE=1, and a waiting rank gives up after TPU_PRECOMPILE_PEER_WAIT_S (default 600 s) and compiles the range itself.

Catching compiles you did not warm. VLLM_XLA_CHECK_RECOMPILATION=1 queries torch.tpu._get_cache_stats() (an internal, underscore-prefixed TorchTPU function that is not on its public API list, so rely on it only through this variable, not from your own code) at every precompiled bucket and every forward step and logs any graph compiled after warmup, such as a shape, dtype or code path warmup never reached. The guide's advice is 1 in CI and test pipelines and 0 in production and benchmarking, where the per-step query costs throughput.

The serving flags that matter on TPU

These flags are ordinary vLLM engine arguments. On TPU each one also fixes a shape, a compile count or a slice of HBM, so they deserve more thought than on a GPU.

Flag What it sets What it means on TPU Values in the recipes
--max-model-len longest sequence, prompt plus output sizes the KV a full-length sequence needs; with --max-num-seqs it bounds KV demand 4,096 (quickstart), 8,192 to 16,384 (most v6e and v7x recipes; 9,216 and 10,240 in several), 65,536 with PCP
--max-num-batched-tokens tokens one step may schedule; caps prefill chunks the largest compiled size and the top of the bucket ladder; chunked prefill splits longer prompts 1,024 (DP=8 MoE recipes) to 8,192 (TP=8 recipes)
--max-num-seqs sequences decoding at once the decode batch: chapter 17's \(B\) 8 (Kimi-K3), 64 (Qwen3.5-397B, GLM-5.2), 256 (DeepSeek-V4), 512 (Qwen3-Coder)
--gpu-memory-utilization fraction of each device's HBM the engine may use the name is upstream's; on TPU it is HBM per device 0.82 (Kimi-K3) to 0.95 (Qwen3-Coder)
--kv-cache-dtype fp8 KV cache element type halves KV bytes; the v6e recipes say always pass it on 32 GB chips fp8, or fp8_e4m3 in the DeepSeek-V4 recipes
--block-size tokens per KV page page size of the paged cache 256 in the parallelism guide, the Qwen3.5-397B and Kimi-K3 recipes, and disaggregation
--attention-backend CUSTOM attention implementation the recipes pass it; RPA v3 is the default for MHA and GQA either way (supported models page) most v6e and v7x recipes
--async-scheduling upstream vLLM's asynchronous scheduling listed with chunked prefill as a feature validated in every CI recipe most recipes
--enable-prefix-caching / --no-enable-prefix-caching automatic prefix caching the feature for agent and multi-turn traffic, validated with Qwen3.5 and Kimi-K3; the CI benchmark recipes turn it off benchmark recipes use --no-

The plugin source shows what is behind --attention-backend CUSTOM: the default backend uses the RPA v3 kernel, and CUSTOM selects a batched variant of ragged paged attention that also supports a sequence-along-lane KV layout. The supported models page treats both as RPA. Pass CUSTOM when you follow a recipe, and leave it out when you do not have a reason.

Do the KV arithmetic before you start the server. The parallelism guide says buffers the engine needs are "reserved before the KV cache is sized": the engine reserves --gpu-memory-utilization of each device's HBM, loads the weights, sets aside working memory and gives the rest to the KV cache. With chapter 17's formula per device, \(K\) is the KV heads each device holds after tensor parallelism:

\[ \text{sequences at full length} = \left\lfloor \frac{\text{HBM} \times \text{utilization} - \text{weights per device} - \text{working memory}}{2 \times L \times K_\text{device} \times H \times \text{bytes} \times \texttt{max-model-len}} \right\rfloor \]

kv_capacity() in launch_profiles.py computes it. If the answer is below --max-num-seqs, the engine cannot keep that many full-length sequences and will preempt some under load; if it is 0, one full-length sequence does not fit at all. Both are worked in problem 3. The estimate leaves out page rounding and the compiled programs resident in HBM, so treat a small margin as no margin, and use tpu-info and the server's startup log as the authority.

Ragged paged attention

The KV cache manager in the top band hands out blocks; the kernel in the bottom band has to read them. Chapter 17 introduced a paged KV cache as the answer to static caches that preallocate max_len positions for every sequence and read padding. vLLM-TorchTPU's default attention for MHA and GQA models is a Pallas kernel, Ragged Paged Attention v3, and its name says what it does.

An animation in eight frames of a KV page pool of 12 pages, 4 token slots each, with page tables on the right and the tokens of the current step packed into a row of 16 slots at the bottom. Frame 1: the pool is empty. Frame 2, step 1: prefill A, 10 tokens, and B, 3 tokens; A takes pages 0 to 2, the last half full, B takes page 3; 13 tokens plus 3 padding. Frame 3, step 2: prefill C, 7 tokens, and decode A and B; C takes pages 4 and 5; 9 tokens plus 7 padding. Frame 4, step 3: decode A, B and C; B's page is full so it gets page 6; 3 tokens plus 13 padding. Frame 5: the attention kernel reads only each sequence's own pages, outlined in orange: A pages 0 to 2, B pages 3 and 6, C pages 4 and 5. Frame 6: B finishes and pages 3 and 6 are marked free. Frame 7, step 4: prefill D, 6 tokens, which takes pages 3 and 6, while A opens page 7 and C opens page 8. Frame 8 summarizes: ragged means sequences of any length, prefill and decode mixed in one padded step; paged means KV lives in pool pages a table points to.

Watch two things: the colored slots grow only as far as each sequence's real length, and the row at the bottom always has 16 slots. Memory follows the data; the compiled shape does not move.

Paged. The KV cache is one pool of fixed-size pages allocated at startup; --block-size sets the tokens per page (the animation uses 4 so the slots are visible, the recipes use 256). Each sequence has a page table listing the pages it holds, in any order. A sequence takes a new page only when its last one is full, and when it finishes its pages return to the pool without any copy. Memory in use is proportional to tokens actually held, not to --max-model-len times the batch.

Ragged. One step carries tokens from many sequences of different lengths: a chunk of one prompt's prefill next to one decode token from each running sequence, which is how chunked prefill and continuous batching share a step. They are packed into one row, padded to the step's bucket, and one kernel call processes the whole row, with each query reading the KV pages of its own sequence through its page table. No query reads another sequence's pages, free pages, or positions past its length.

Still static. XLA needs fixed shapes, and it gets them: the pool, the page tables and the step's token count are fixed sizes. Only their contents change. This is the same trick as chapter 7's static KV cache, moved from one sequence to the whole batch.

Two knobs from the supported models page belong here. VLLM_TPU_BLOCK_MAJOR_KV=1 selects a block-major layout in which all layers of a page are contiguous, so a page moves in one DMA, which matters for disaggregated transfer and host offload; USE_RPA_PIPELINED_DMA_STAGING=1 enables pipelined DMA staging in the kernel. Neither is needed for a first deployment.

Parallelism: TP, DP, EP and the rest

vLLM-TorchTPU supports all six of vLLM's parallelism dimensions, on single-host and multi-host slices, and they compose:

Dimension Flag What it splits Collective it adds
Tensor (TP) --tensor-parallel-size N attention heads and dense MLP weights all-reduce or reduce-scatter per layer
Data (DP) --data-parallel-size N requests; attention replicated per engine none for attention at TP=1
Expert (EP) --enable-expert-parallel MoE experts over the TP * DP mesh all-to-all dispatch and combine
Pipeline (PP) --pipeline-parallel-size N layers into stages point-to-point activations
Prefill context (PCP) --prefill-context-parallel-size N each prefill chunk's tokens ring attention between adjacent chips
Decode context (DCP) --decode-context-parallel-size N KV pages along the sequence log-sum-exp merge of partial attention

Count devices first. An engine group consumes \(DP \times TP \times PP \times PCP\) logical devices. A v7x chip exposes two TensorCore devices of 96 GB each, so a four-chip tpu7x-8 host has 8 devices and 768 GB; a v6e chip is one device of 32 GB. TP=8, DP=8, TP=1 and DP=4, TP=2 all fill one v7x host.

Dense models: TP. Chapter 17 showed why decode wants tensor parallelism: each device reads \(1/n\) of the weights, so the bandwidth floor falls by \(n\), at the cost of two activation all-reduces per layer. Its rule of thumb carries over: TP beyond the model's KV head count replicates KV heads, so the KV per device stops shrinking.

Large MoE models: DP plus EP. For MoE models with GQA or MLA, the parallelism guide and the launch post both report the best throughput from data-parallel attention plus expert parallelism, for example DP=8, TP=1 with EP on one v7x host. Attention stays local to each device, so there is no attention all-reduce, and the experts spread over the whole slice: each device holds num_experts / (TP * DP) of them, leaving its HBM for weights and KV. This is the reference throughput recipe for Qwen3.5-397B-A17B-FP8 and the layout of the DeepSeek-V4 and GLM-5.2 recipes. For lower per-request latency at small concurrency, the v7x recipes offer --tensor-parallel-size 2 --data-parallel-size 4, which the parallelism guide places across the two cores of one physical chip.

PP, PCP and DCP. Pipeline parallelism splits layers into stages (--tensor-parallel-size 4 --pipeline-parallel-size 2 in the guide's Llama-3.1-70B example). Prefill context parallelism splits long prompts across ranks to cut TTFT, and decode context parallelism shards KV pages along the sequence for long-context decode; the guide aims both at 32K to 256K-token workloads and at disaggregated serving.

Quantization

Quantized weights are reshaped and packed once at load time, so the Pallas matmul, attention and fused MoE kernels run on the MXU's low-precision paths directly. When a checkpoint's config.json already carries a quantization_config, vLLM detects the format and you pass nothing; --quantization is for overriding or for quantizing at load.

--quantization Weights Use it for
fp8 (or automatic) float8_e4m3fn, per tensor, per channel or 2D blocks the *-FP8 checkpoints in most recipes
compressed-tensors fp8 (W8A8), int4 (W4A8, W4A16), mxfp4 checkpoints whose quant_method is compressed-tensors; selected automatically
mxfp4 fp4 with e8m0 block scales, block 32 openai/gpt-oss-120b and gpt-oss-20b
nvfp4 fp4 with fp8 block scales NVFP4 checkpoints such as nvidia/Qwen3-30B-A3B-NVFP4
awq, gptq int4 (and int8 for GPTQ), weight only AWQ and GPTQ checkpoints
deepseek_v4_fp8 fp8 with optional fp4 MoE requantization DeepSeek-V4
online_fp8 a bf16 checkpoint quantized to fp8 while loading serving a bf16 checkpoint with fp8 weights

The quantization guide's headline combination is fp8 weights with --kv-cache-dtype fp8, which "halves both weight and KV cache HBM footprints while doubling MXU matrix throughput on TPU v6e and TPU v7x". In chapter 17's terms, fp8 weights halve the bandwidth floor of decode and fp8 KV halves the attention term and doubles the sequences that fit. One opt-in knob changes the arithmetic for small batches: with TPU_FP8_LINEAR_W8A16_MAX_ROWS, fp8 linear steps whose padded bucket has at most that many rows keep bf16 activations against the fp8 weights, which the guide says speeds up small decode steps on v7x. Its default is 0 (off). Load-time requantization of weights and MoE experts (REQUANTIZE_*, MOE_REQUANTIZE_*, used by the DeepSeek-V4 recipes for W4A8 MoE) exists for checkpoints whose block layout does not suit the MXU.

A quantization change changes the model you serve. Gate it on parity and on an accuracy evaluation, as the end of this chapter and chapter 23 do; the developer guide's own rule for a new quantization path is before-and-after evaluation plus a serving benchmark on the same machine.

Speculative decoding

Chapter 17 explained why speculative decoding works: decode is memory-bound, so a target forward pass that scores several tokens per sequence costs about what one that scores a single token does. A drafter proposes \(k\) tokens, the target scores all of them in one pass, keeps the longest prefix it agrees with and adds one token of its own.

An animation in eleven frames of speculative decoding with 3 draft tokens after the prompt The cat sat on. Each cycle has three frames: the drafter proposes 3 tokens, the target verifies them in one pass marking each accepted or rejected and showing its own token, and the kept tokens are appended to the output, with counters for target passes and tokens generated. Cycle 1: drafts the, mat, and; the first two are accepted, and is rejected, and the target's own token is a period; 3 tokens added. Cycle 2: drafts It, was, warm are all accepted and the target adds and; 4 tokens added. Cycle 3: drafts the, dog, slept are all rejected and the target's token quiet is added; 1 token. The last frame reads 8 tokens in 3 target passes: plain decode needs 8 target passes for the same 8 tokens, and 5 of 9 drafts were accepted.

Count target passes, not drafts: each cycle costs one pass and yields between 1 and \(k + 1\) tokens, and every kept token is the one the target would have chosen.

vLLM-TorchTPU supports six methods through --speculative-config, a JSON object with "method", "num_speculative_tokens" and, for methods with a separate drafter, "model":

Method "method" Draft checkpoint Best for, per the guide
EAGLE-3 "eagle3" yes (yuhuili/EAGLE3-*) high acceptance across chat, coding and reasoning
Multi-token prediction "mtp" (or "qwen3_next_mtp") built into the checkpoint (Qwen3.5, DeepSeek-V3/R1, GLM-5) models trained with MTP heads; nothing extra to manage
DFlash "dflash" yes (z-lab/*-DFlash-*) block-diffusion drafts of up to 16 tokens in one forward pass
DSpark "dspark" yes (deepseek-ai/dspark_*, Inferact/Kimi-K3-DSpark) parallel block drafting with a sequential Markov head
N-gram "ngram" no repetitive prompts, code edits, citations, RAG extraction
Suffix decoding "suffix" no a suffix tree over the prompt and earlier responses

Two examples from the guide, one with a draft model and one without:

vllm serve Qwen/Qwen3-32B \
  --tensor-parallel-size 8 \
  --max-model-len 8192 \
  --speculative-config '{
    "method": "eagle3",
    "model": "RedHatAI/Qwen3-32B-speculator.eagle3",
    "num_speculative_tokens": 3
  }'

vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --tensor-parallel-size 2 \
  --speculative-config '{
    "method": "ngram",
    "num_speculative_tokens": 5,
    "prompt_lookup_max": 4
  }'

Choose \(k\) by measurement. The benchmarking harness has a mode for exactly that: run_benchmarks.sh --mode spec_bench restarts the server for each batch size and \(k\) (with \(k = 0\) as the baseline without speculation), runs vllm bench serve --dataset-name spec_bench, and reports speedup against \(k = 0\) and the acceptance rate. Chapter 17's problem 6 explains the pattern you should expect: speculation helps most at small batches, where the extra positions are free, and less as the batch pushes the step toward the ridge.

v6e and v7x recipes

The two generations differ in the numbers that drive every choice above: a v6e chip is one device with 32 GB of HBM, a v7x chip two devices with 96 GB each. The v7x recipes are extracted from the CI benchmark configurations; the v6e recipes are reference configurations sized for 32 GB chips and not run in CI.

Model Slice Layout
Llama-3.2-1B/3B-Instruct, Qwen3-8B v6e-1 (32 GB) TP=1
Qwen3-32B, Qwen3-Coder-30B-A3B-FP8, Qwen3.5-35B-A3B-FP8 v6e-4 (128 GB) TP=4, plus EP for MoE
Llama-3.3-70B-Instruct, gpt-oss-120b v6e-8 (256 GB) TP=8, plus EP for MoE
Qwen3.5-397B-A17B-FP8 v6e-16 (2 hosts, 512 GB) TP=16, or DP=2, TP=8 plus EP
vllm serve Qwen/Qwen3-8B \
  --tensor-parallel-size 1 \
  --kv-cache-dtype fp8 \
  --max-model-len 8192 \
  --max-num-batched-tokens 2048 \
  --gpu-memory-utilization 0.90 \
  --async-scheduling \
  --port 8000

Every v6e recipe passes --kv-cache-dtype fp8, and the page says to always do so on 32 GB chips "to double available KV cache blocks and prevent preemption under long-context or high-concurrency workloads". Models that do not fit one host's 256 GB go to v6e-16.

Model Slice Layout
Qwen3.5-397B-A17B-FP8 v7x-8 (8 devices, 768 GB) TP=1, DP=8 plus EP
Qwen3-Coder-480B-A35B-Instruct-FP8, Qwen3-Coder-30B-A3B-Instruct-FP8, Qwen3.5-35B-A3B-FP8 v7x-8 TP=8 plus EP
gemma-4-31B-it-FP8-Dynamic v7x-8 TP=2, DP=4
DeepSeek-V4-Flash v7x-8 TP=1, DP=8 plus EP
GLM-5.2-FP8, DeepSeek-V4-Pro-0813 v7x-16 (2 hosts) TP=1, DP=16 plus EP
Kimi-K3 v7x-32 (4 hosts) TP=32 plus EP
vllm serve Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8 \
  --tensor-parallel-size 8 \
  --enable-expert-parallel \
  --quantization fp8 \
  --kv-cache-dtype fp8 \
  --attention-backend CUSTOM \
  --max-model-len 16384 \
  --max-num-batched-tokens 8192 \
  --max-num-seqs 512 \
  --gpu-memory-utilization 0.95 \
  --async-scheduling \
  --no-enable-prefix-caching \
  --port 8000

This is the PR-time performance guard configuration. The v7x pages count logical devices, so --tensor-parallel-size 8 fills one four-chip host. MoE recipes add environment variables of their own (USE_MOE_SPARSE_CORE=1 and ONEHOT_MOE_PERMUTE_THRESHOLD=32768 for Qwen3.5-397B), and multi-host recipes stream weights from Cloud Storage with --load-format runai_streamer and --enable-ep-weight-filter.

The pattern across both pages: pick the smallest slice whose HBM holds the weights with room for KV, use TP within a host for dense models and DP plus EP for large MoE models, and put fp8 on the KV cache wherever the recipe does.

Multi-host and disaggregated serving

Both are covered in depth in chapter 20; here is what to recognize in a vLLM-TorchTPU command.

Multi-host. When a layout spans several TPU VMs (v7x-16, v7x-32, v6e-16), the default mp backend runs vllm serve on every host and exchanges slice addresses through a torch.distributed TCPStore rendezvous, with no Ray cluster. For TP, PP or PCP across hosts, every host passes --nnodes, --node-rank, --master-addr and --master-port, and hosts other than 0 add --headless. For multi-host DP, each host serves its local DP ranks with --data-parallel-size-local and --data-parallel-start-rank. TPU_MULTIHOST_BACKEND=ray switches to a Ray cluster driven from the head node.

Disaggregated prefill and decode. The disaggregation guide separates "compute-bound Prefill (kv_producer) and memory-bandwidth-bound Decode (kv_consumer)" onto separate engine pools, which "prevents long-prompt prefills from stalling ongoing decode steps": chapter 17's failure mode of decode stalled behind prefill, solved by giving each phase its own engines and parallelism. KV moves over TPU Sync through vLLM's KV connector interface (--kv-transfer-config), with a controller, a prefill pool, a decode pool and a proxy, and it can be resharded in flight between layouts, for example prefill on PCP=4, TP=2 into decode on DP=8, TP=1. On one 8-device host, examples/disagg/run_disagg_single_host.sh launches the whole pipeline and runs vllm bench serve against it. One naming discrepancy to know before you copy a command: the disaggregation guide writes the connector as TpuRaidenConnector in module ...kv_transfer.raiden.raiden_connector, and neither exists in the code. Use TPURaidenConnector with module path vllm_torchtpu.distributed.kv_transfer.tpu_connector, as the scripts in examples/disagg/ do; chapter 20 sets out the evidence, and its manifest checker rejects the guide's spelling.

The companion code

code/ch18_vllm/ (source) turns this chapter into two tools, both standard library only.

launch_profiles.py holds eleven named profiles that reproduce the flags of the quickstart, the v6e and v7x recipes, the parallelism guide and the speculative decoding guide, and builds vllm serve command lines from them. It accepts only flags and environment variables the documents use, and refuses combinations they rule out: more devices than the slice has, a KV dtype or quantization method outside the documented lists, an EAGLE-3, DFlash or DSpark config without a draft checkpoint, a token budget beyond the largest compile_sizes entry, peer replay without parallel precompile. It prints each profile's bucket ladder and builds the vllm bench serve command from the benchmarking guide.

python code/ch18_vllm/launch_profiles.py --cpu-smoke
python code/ch18_vllm/launch_profiles.py --profile v7x-8-qwen3-coder-30b-guard --cache-root /mnt/cache --ci
# 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
# export VLLM_XLA_CHECK_RECOMPILATION=1
# vllm serve Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8 \
#   --tensor-parallel-size 8 \
#   ...
python code/ch18_vllm/launch_profiles.py --profile v6e-8-llama3.3-70b --slice v6e-4
# error: v6e-8-llama3.3-70b: DP x TP x PP x PCP = 8 devices, v6e-4 has 4

Validation is not a substitute for the engine: it knows what the documents state, not whether a model fits or a checkpoint is supported. On a TPU VM, --launch NAME replaces the process with the vllm serve command.

client.py measures what a user sees. It streams completions and times every token: TTFT from sending the request to the first token, TPOT as \((t_\text{last} - t_\text{first}) / (\text{tokens} - 1)\), chapter 17's definitions. bench runs a closed loop at fixed concurrency and reports median and p99; smoke sends the quickstart's request; record and parity save greedy outputs from a build you trust and compare a new build exactly. Its CPU smoke run starts a local fake endpoint whose prefill and decode delays are known, and checks that the client measures them:

$ python code/ch18_vllm/client.py --cpu-smoke
fake endpoint http://127.0.0.1:55767: prefill 5.0 ms + 0.2 ms/word, decode 10.0 ms/token
smoke: 128 words back from /v1/chat/completions
  requests 16 at concurrency 4, wall 0.74 s
  TTFT ms  median    30.56   p99    36.95
  TPOT ms  median    13.37   p99    14.46
  output tokens/s 259.7
  expected TTFT about 25 ms, TPOT about 10 ms
  measured 13.37 ms, floor 8.00 ms: the floor is 60% of the measurement (1.67x)
parity against itself: PASS (4/4)
parity against a corrupted build: FAIL (0/4); first at char 49: 't19ec t8c87 t5bd9 te337 ' vs 'x19ec x8c87 x5bd9 xe337 '
cpu-smoke: OK

The fake endpoint is a test fixture, not a TPU: it has no batching, so its TPOT does not grow with concurrency. The measured TPOT sits above the configured 10 ms by the sleep and thread overhead of a laptop, which is why any measurement lands above its floor.

Benchmarking with vllm bench serve

vllm bench serve is upstream vLLM's serving benchmark, and the benchmarking guide gives the exact client the nightly 480B configuration uses. Start the server in one terminal, then run the client in another:

vllm bench serve \
  --backend vllm \
  --model Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8 \
  --host localhost \
  --port 8000 \
  --dataset-name random \
  --random-input-len 1024 \
  --random-output-len 1024 \
  --random-range-ratio 0.8 \
  --num-prompts 320 \
  --max-concurrency 64 \
  --request-rate inf \
  --ignore-eos \
  --save-result \
  --result-filename isl1024_osl1024_c64.json \
  --seed 42

Read the flags as experimental controls. --dataset-name random with --random-input-len and --random-output-len fixes the input and output lengths (ISL and OSL), and --random-range-ratio 0.8 spreads them around those values. --ignore-eos makes every request produce its full output so TPOT is averaged over the same number of tokens. --max-concurrency 64 with --request-rate inf is a closed loop: 64 requests in flight, a new one as each finishes, so 64 is chapter 17's batch. --seed 42 makes the random prompts repeatable, and --save-result writes the JSON you compare between runs. The guide's other two runs change only the lengths (1,024 in and 8,192 out, then 8,192 in and 1,024 out), which separates a decode-heavy workload from a prefill-heavy one. launch_profiles.py --bench NAME prints this command for any profile.

The repository's harness, scripts/vllm/benchmarking/run_benchmarks.sh --config NAME, starts the server with a config's flags, can run discarded warmup passes (BENCHMARK_WARMUP_RUNS), sweeps lengths and concurrency, and saves per-combination JSON. Its regression gate is a good template for your own: median TPOT, total and output token throughput, completed requests, and median TTFT only where the baseline has it, all within 5% of a baseline. It omits TTFT under closed-loop load beyond the prefill admission capacity, \(DP \times\) max-num-batched-tokens / prompt length, because there "median TTFT is queue-position noise". Two more rules from the optimization guide save wasted runs: compare parallelism layouts at a matched global token budget (DP with a per-rank budget times \(N\) ranks against TP at the same total), and treat an end-to-end number without a trace and a mechanism as unexplained.

Failure modes

Symptom Mechanism What to check or change
Startup takes many minutes, every time Warmup compiles one program per token size per rank, from scratch, because nothing persisted Persist VLLM_XLA_CACHE_PATH, TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT and VLLM_CACHE_ROOT; TPU_PARALLEL_PRECOMPILE=1 and TPU_PRECOMPILE_PEER_REPLAY=1 on multi-rank hosts; a smaller --max-num-batched-tokens or an explicit compile_sizes list compiles fewer programs. Budget for it on GKE: the repository's multi-host JobSet allows eight hours
A step after warmup takes seconds; latency spikes at odd times Recompilation while serving: a shape or code path warmup never compiled VLLM_XLA_CHECK_RECOMPILATION=1 in CI logs the new graphs; keep steps within the compiled sizes
Requests preempted or aborted under load; throughput collapses at high concurrency KV budget too small: weights plus --max-num-seqs full-length sequences exceed the HBM reservation Compute kv_capacity(); lower --max-model-len or --max-num-seqs; --kv-cache-dtype fp8 (always on v6e); fp8 weights; more devices. In disaggregated decode pools, capacity preemption aborts the request with stop_reason "kv_cache_preempted" and counts in vllm:num_preemptions
Out of HBM after a change that did not touch KV flags Weights or resident buffers grew, and resident HBM growth directly shrinks the KV cache (the developer guide's words); compiled programs also stay resident Compare the server's HBM logs and tpu-info before and after; check new pipeline buffers, which are reserved before the KV cache is sized
The model will not load, or a feature raises an error Unsupported model or option. The plugin's rule is to raise NotImplementedError with an actionable message rather than silently fall back Check the supported models page (a model missing from a row there "has not been run in CI, not that it is unsupported"); try the smallest config offline first; for models with dynamic shapes in their code, see chapter 9
Layout refused at startup, or half the slice idle Device count: \(DP \times TP \times PP \times PCP\) does not match the slice, or a v7x layout counted chips instead of devices Recount in logical devices: 8 per v7x host, 1 per v6e chip
TPOT spikes whenever long prompts arrive Decode stalled behind prefill (chapter 17) A smaller --max-num-batched-tokens chunks prefill; PCP for long prompts; disaggregate prefill and decode
Throughput well below a recipe's A different experiment: prefix caching set differently from the recipe, a different concurrency, a non-matched token budget between layouts, or recompilation checks left on Match the recipe's flags exactly, including --no-enable-prefix-caching, and VLLM_XLA_CHECK_RECOMPILATION=0

Verifying the result

A deployment is trustworthy when it answers, when its decode speed is one you predicted from bytes and bandwidth, and when it computes the same outputs as a build you trust. Run the checks in that order; each one is cheaper than the next.

  1. Smoke request. Once the server logs Application startup complete, send one request and read the answer:

    python code/ch18_vllm/client.py smoke --model meta-llama/Llama-3.2-1B-Instruct
    

    A coherent answer proves the plugin loaded, the weights are right and one prefill and decode ran. Repeat it after the first restart with persistent caches: startup should now take much less time, and if it does not, the caches are not where the server looks.

  2. Benchmark TTFT and TPOT, and compare TPOT with chapter 17's floor. Before running, write down the floor. For a dense model it is (weight bytes per device + batch × KV bytes per sequence per device) / HBM bandwidth per device, with the batch set to the concurrency and the context to input plus half the output; chapter 17's kv_cache.py computes it for its models, and its TP table gives 16.73 ms at batch 64 and 4,096 tokens of context for Muse Glimmer 30B on one v7x device, 8.86 ms at TP=2. Then measure at that concurrency:

    python code/ch18_vllm/client.py bench --model YOUR_MODEL --requests 256 --concurrency 64 \
        --prompt-words 1024 --max-tokens 1024 --floor-tpot-ms YOUR_FLOOR
    

    or with vllm bench serve as above, reading its median TPOT. The measurement must be above the floor. Chapter 17's reference point is the Muse Glimmer case study, where a simple decode loop ran at 61% of peak bandwidth; an engine with paged attention, fused kernels and a batch should come closer as concurrency grows. A measurement below the floor means an input to the floor is wrong, usually per chip mixed with per device or bf16 assumed where weights or KV are fp8. A gap that grows with concurrency faster than the KV term predicts points at prefill steps interleaved with decode or at a bucket boundary. MoE models are harder to predict: FLOPs follow the active parameters, while the bytes a step reads depend on how many experts the batch touches (a conservative whiteboard model counts every weight byte on the device), so start with a dense model.

  3. Parity gate against reference outputs. Record greedy outputs from a build you trust, offline or from a known-good server, and compare every new image, flag set or quantization against them before it takes traffic:

    python code/ch18_vllm/client.py record --model YOUR_MODEL --out ref.json      # on the trusted build
    python code/ch18_vllm/client.py parity --model YOUR_MODEL --reference ref.json  # on the candidate
    # parity PASS: 4/4 prompts identical
    

    Exact greedy agreement catches a wrong checkpoint, a broken kernel or a quantization that changed the model. Two correct builds with different numerics can legitimately diverge at a near tie, so when you compare bf16 serving against an fp32 reference, use a logprob gate with a tie rule and the accuracy evaluations of the benchmarking harness; chapter 23 builds both.

Worked problems

Problem 1. Which of these layouts fit, and how many logical devices does each use? (a) --tensor-parallel-size 2 --data-parallel-size 4 on v7x-8; (b) --tensor-parallel-size 2 --prefill-context-parallel-size 4 on v7x-8; (c) --tensor-parallel-size 4 --pipeline-parallel-size 2 --data-parallel-size 2 on v7x-8; (d) --tensor-parallel-size 16 on v6e-8.

Answer

Devices are \(DP \times TP \times PP \times PCP\). (a) \(4 \times 2 = 8\): fits one v7x host exactly, and the parallelism guide puts each TP pair on the two cores of one chip. (b) \(2 \times 4 = 8\): fits; it is the prefill layout of the launch post's disaggregation example. (c) \(2 \times 4 \times 2 = 16\): does not fit one 8-device host; it needs v7x-16. (d) 16 devices on an 8-device slice: does not fit; the v6e recipes put TP=16 on v6e-16, two hosts. launch_profiles.py rejects (c) and (d) with the device count in the message.

Problem 2. A server runs with --max-num-batched-tokens 4096 and no compile_sizes. How many token sizes does warmup compile? A step schedules 1,100 tokens: which program runs and what fraction of it is padding? What changes with TPU_TOKEN_BUCKET_EXTRA=1536?

Answer

The ladder is 16, 32, 64, 128, 256, 512, 1,024, 2,048, 4,096: nine sizes. 1,100 tokens is past 1,024, so the step runs the 2,048 program, and \((2048 - 1100) / 2048 = 46\%\) of it is padding. With an extra size of 1,536 the ladder has ten sizes and the step runs the 1,536 program, \((1536 - 1100) / 1536 = 28\%\) padding, at the price of one more compile at warmup and one more program resident in HBM. token_buckets(4096, extra=[1536]) and padding_fraction in launch_profiles.py check both.

Problem 3. You serve a model with LLaMA 2-13B's shapes (chapter 17: 40 layers, 40 KV heads of 128, about 26 GB of bf16 weights) on v6e-8 with --tensor-parallel-size 8, --gpu-memory-utilization 0.92 and --max-model-len 16384. Ignoring working memory, how many full-length sequences fit with a bf16 KV cache, and with --kv-cache-dtype fp8? Would --max-num-seqs 32 be safe?

Answer

Per device: \(40 / 8 = 5\) KV heads and \(26 / 8 = 3.25\) GB of weights. KV per token per device in bf16 is \(2 \times 40 \times 5 \times 128 \times 2 = 102{,}400\) bytes, so one 16,384-token sequence needs 1.68 GB on every device. Free space per device is \(32 \times 0.92 - 3.25 = 26.19\) GB, which holds \(\lfloor 26.19 / 1.68 \rfloor = 15\) full-length sequences; the TP group as a whole serves 15, since each device holds a slice of every sequence. With fp8 KV the per-sequence cost halves and 31 fit. --max-num-seqs 32 is not safe even with fp8: if all 32 sequences grow to full length, the cache runs out and the engine preempts. It is safe if typical sequences are much shorter than 16,384, because the paged cache holds only real tokens, or with a smaller --max-model-len. This is the arithmetic behind the v6e page's advice to always use fp8 KV. Check with kv_capacity(32, 0.92, 3.25, 102400, 16384).

Problem 4. Write the vllm bench serve command that measures a prefill-heavy workload (8,192 input tokens, 1,024 output tokens) at 32 concurrent requests against a server on port 8000 serving Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8, following the benchmarking guide. Which of the server's flags must you check first?

Answer

vllm bench serve --backend vllm --model Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8 \
  --host localhost --port 8000 --dataset-name random \
  --random-input-len 8192 --random-output-len 1024 --random-range-ratio 0.8 \
  --num-prompts 320 --max-concurrency 32 --request-rate inf --ignore-eos \
  --save-result --result-filename isl8192_osl1024_c32.json --seed 42
Check --max-model-len: with a range ratio of 0.8 the longest requests approach \(1.8 \times 8192 + 1.8 \times 1024\) tokens, beyond the guard recipe's 16,384, so either lower the ratio or raise the limit. Check --max-num-seqs is at least 32 so the server does not queue the concurrency you asked for, and --max-num-batched-tokens: at 8,192 each prompt is one prefill chunk, at 1,024 it is eight, which changes TTFT. Keep prefix caching off, as the recipe does, so the run matches the CI configuration it will be compared with.

Problem 5. A latency-sensitive coding assistant serves meta-llama/Llama-3.1-8B-Instruct on two devices, mostly editing code the user pasted into the prompt. Choose a speculative decoding method and write the --speculative-config. If the target accepts on average 2 of 5 drafts and decode is far below the ridge, roughly what happens to TPOT?

Answer

N-gram lookup fits: the guide recommends it for code edits and prompts with repetitive structure, and it needs no draft checkpoint. The guide's example is --speculative-config '{"method": "ngram", "num_speculative_tokens": 5, "prompt_lookup_max": 4}'. Each target pass then yields \(2 + 1 = 3\) tokens on average. At a small batch the pass costs about one plain decode step (chapter 17), so TPOT falls to roughly a third of the plain value, less the cost of the lookup and of verifying 6 positions instead of 1. Measure it with run_benchmarks.sh --mode spec_bench against \(k = 0\) before believing it; acceptance depends on the traffic.

Problem 6. After a new image is rolled out, client.py parity fails on one prompt at character 31, while the other three match, and the median TPOT is 2% better. The release notes mention a new attention kernel. What do you do?

Answer

Do not ship on the TPOT gain. One prompt diverging partway through can be a legitimate near tie between two correct numerical paths, or the first symptom of a kernel bug. Run the logprob parity gate (chapter 23, verify_cpu_vs_tpu_serving_parity) against a reference with the tie rule: if the reference's top-1 and top-2 logprobs at the divergence are within the measured noise, it is a tie and the gate passes; if not, it is a real mismatch. Run the harness's accuracy evaluation too. Only then compare performance, against a baseline taken on the same machine with the same flags.

Quick questions

  1. Name the three layers of the architecture diagram and say which one each of these belongs to: the scheduler, TPUModelRunner, Ragged Paged Attention v3, --max-num-seqs.
  2. Why does vLLM-TorchTPU need no change to your launch command to activate it?
  3. Which flag sets the largest compiled token size, and how does the default bucket ladder follow from it?
  4. What do VLLM_XLA_CACHE_PATH, TORCH_TPU_TIER3_COMPILATION_CACHE_ROOT and VLLM_CACHE_ROOT each hold, and why set all three?
  5. What does VLLM_XLA_CHECK_RECOMPILATION=1 detect, and why is it off in production?
  6. In ragged paged attention, what is ragged, what is paged, and what stays a fixed shape?
  7. When do the documented recipes choose DP=8, TP=1 plus EP over TP=8?
  8. What does fp8 weights plus fp8 KV change in chapter 17's decode floor and in the number of sequences that fit?
  9. Which speculative decoding methods need a draft checkpoint?
  10. Which metrics does the benchmarking harness's regression gate compare against a baseline, and why does it sometimes omit TTFT?

Key takeaways

  • vLLM-TorchTPU is a platform plugin under unmodified vLLM: the CLI, OpenAI server, scheduler and KV cache manager are upstream; one TPUWorker per device runs TPUModelRunner under torch.compile(backend="tpu"), with Pallas kernels as custom ops. pip install vllm-torchtpu (Python 3.12, PyTorch CPU index) and vllm serve are all it takes to start.
  • Every step runs a precompiled program. By default the token sizes double from 16 to --max-num-batched-tokens; each is a compile at warmup and a program in HBM, and a step just past a size pays up to half its work in padding. Persist the three cache roots, use parallel precompile with peer replay on multi-rank hosts, and run VLLM_XLA_CHECK_RECOMPILATION=1 in CI.
  • The flags that shape TPU serving are --max-model-len, --max-num-batched-tokens, --max-num-seqs, --gpu-memory-utilization, --kv-cache-dtype and --block-size. Compute the KV capacity they imply with chapter 17's formula before starting a server; use fp8 KV always on v6e.
  • Ragged Paged Attention packs sequences of any length into one padded step and reads each sequence's KV from pages listed in its page table, so memory follows real length while every shape stays static.
  • Use TP for dense models, DP plus EP for large MoE models (DP=8, TP=1 on a v7x host for throughput), and count devices as \(DP \times TP \times PP \times PCP\) logical devices, two per v7x chip. fp8 weights and KV halve both footprints; speculative decoding (six methods) turns spare decode compute into tokens.
  • Benchmark with vllm bench serve at fixed lengths, closed-loop concurrency, --ignore-eos and a seed; compare median TPOT with chapter 17's floor, and expect it above the floor. Gate every rollout on a smoke request, a TPOT you can explain and parity with outputs from a trusted build.

References