Skip to content

Choose a parallelism layout for vLLM-TorchTPU

Use this guide when a model needs more than one device and you must pick tensor, data, expert, pipeline or context parallelism, and their sizes, for a TPU slice. vLLM-TorchTPU supports all six of vLLM's dimensions and lets them compose, on one host or several. This guide counts devices, picks a layout by model type, and gives the documented commands for each. Chapter 18 explains what each dimension costs in collectives; chapter 13 explains the collectives themselves.

Prerequisites

  • A slice and its device count: 1 device per v6e chip; 2 per v7x chip, so 8 per v7x host.
  • The model's type: dense, or MoE with GQA or MLA attention, and its KV head count.

Steps

1. Count devices

An engine group uses \(DP \times TP \times PP \times PCP\) logical devices. On a v7x host, TP=8, DP=8, TP=1 and DP=4, TP=2 each fill the 8 devices.

Dimension Flag What it splits Collective
Tensor (TP) --tensor-parallel-size N Attention heads and dense MLP projections All-reduce or reduce-scatter per layer
Data (DP) --data-parallel-size N Requests; attention replicated per engine, sharing one EP mesh for MoE None for attention at TP=1; all-to-all across TP * DP for MoE with EP
Expert (EP) --enable-expert-parallel MoE experts across the TP * DP mesh SparseCore or GMM ragged 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

Check: the product equals the slice's devices. The book's builder refuses a mismatch with the count in the message:

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

2. Dense models: tensor parallelism

TP shards weights within a high-bandwidth ICI domain, so each device reads a fraction of the weights per decode step. The v6e and v7x recipes use TP for dense models (Llama-3.3-70B at TP=8 on v6e-8). Past the model's KV head count, more TP replicates KV heads and the KV per device stops shrinking.

Check: the startup log's KV cache size against chapter 18's kv_capacity() estimate for the per-device KV heads; if more TP no longer adds KV capacity, the extra devices are better used for DP.

3. Large MoE models: data parallelism plus expert parallelism

For large MoE models with GQA or MLA (Qwen3.5-397B-A17B, DeepSeek-V4, GLM-5.2-FP8), DP plus EP often gives much higher throughput than pure TP: attention stays local (TP=1 or TP=2), avoiding 8-way or 16-way all-reduces per layer, and each device holds num_experts / (TP * DP) experts, leaving HBM for weights and KV.

DP=8, TP=1 plus EP on one v7x host:

export USE_MOE_SPARSE_CORE=1
export ONEHOT_MOE_PERMUTE_THRESHOLD=32768

vllm serve Qwen/Qwen3.5-397B-A17B-FP8 \
  --tensor-parallel-size 1 \
  --data-parallel-size 8 \
  --enable-expert-parallel \
  --quantization fp8 \
  --kv-cache-dtype fp8 \
  --max-model-len 10240 \
  --max-num-batched-tokens 1024 \
  --max-num-seqs 64 \
  --gpu-memory-utilization 0.92 \
  --block-size 256

When HBM per device is tighter, or for higher single-stream concurrency, pair TP=2 across the two cores of one v7x chip with DP=4:

vllm serve Qwen/Qwen3.5-35B-A3B-FP8 \
  --tensor-parallel-size 2 \
  --data-parallel-size 4 \
  --enable-expert-parallel \
  --kv-cache-dtype fp8 \
  --max-model-len 16384 \
  --max-num-batched-tokens 4096 \
  --async-scheduling

MoE execution paths on multi-chip and multi-host slices are switched by environment variables:

Variable Default Effect
USE_MOE_SPARSE_CORE 1 MoE token routing and gather-reduce collectives on SparseCores
USE_MOE_FUSED_EP_KERNEL 0 The fused expert-parallel Pallas kernel (v1 or v2 via MOE_FUSED_EP_KERNEL_IMPL)
TPU_MOE_HIERARCHICAL_EP 0 Two-level (intra-chip, inter-chip) EP dispatch on dual-core v7x
TPU_MOE_SEQUENCE_PARALLEL 0 Sequence-parallel activations into MoE layers: reduce-scatter plus all-gather instead of all-reduce
TPU_LATENT_PROJ_INTRA_CHIP_TP 0 Shards MLA latent projections across the 2 cores of a v7x chip even at TP=1

Check: compare layouts at a matched global token budget (DP with a per-rank budget times \(N\) ranks against TP at the same total), as the developer guide's optimization best practices require; otherwise you are comparing budgets, not layouts.

4. Pipeline parallelism

PP splits layers into stages and composes with TP:

vllm serve meta-llama/Llama-3.1-70B-Instruct \
  --tensor-parallel-size 4 \
  --pipeline-parallel-size 2 \
  --max-model-len 8192

(Builder profile pp-llama3.1-70b.) TPU_PP_DYNAMIC_CHUNKS=1 (the default) sizes microbatch chunks dynamically to keep bubbles small without recompiling the token buckets. Stages hand activations on in lockstep by default (TPU_PP_HANDOFF=wave), so each round lasts as long as the slowest forward; TPU_PP_HANDOFF=ring sends each forward's output to the next stage as soon as it is done, which keeps stages busy when prompts of different lengths are in flight. The ring needs libtpu 0.0.50 or later with torch_tpu 0.2.0 or later (the start-up self-test fails fast otherwise). TPU_PP_RING_DEPTH (default 2) caps the forwards a stage queues; each device then holds up to that many outgoing buffers and up to 7 landing buffers of --max-num-batched-tokens × hidden size, reserved before the KV cache is sized.

A stage may also span a PCP group (MoE models then need --enable-expert-parallel). On dual-core v7x hosts, a two-core stage must not bind both cores of one physical chip: set VLLM_TPU_DEVICE_ORDER, for example 0,2,1,3,4,6,5,7 for four two-core stages on one host.

Check: with the ring handoff, the KV cache the startup log reports is smaller by the ring buffers; account for it.

5. Long contexts: prefill and decode context parallelism

For 32K to 256K-token workloads, or disaggregated serving, PCP splits each prefill chunk across ranks to cut TTFT (TPU_PCP_TOPOLOGY_AWARE_MESH=1, on by default, binds consecutive PCP ranks to adjacent chips), and DCP shards KV pages along the sequence for decode.

vllm serve Qwen/Qwen3.5-397B-A17B-FP8 \
  --tensor-parallel-size 2 \
  --prefill-context-parallel-size 4 \
  --enable-expert-parallel \
  --kv-cache-dtype fp8 \
  --max-model-len 65536

Check: \(TP \times PCP = 8\) fits one v7x host; TTFT on long prompts falls compared with the same model without PCP.

6. Beyond one host

Layouts larger than a host run on several hosts with the mp or Ray backend: Serve across several TPU hosts with vLLM-TorchTPU.

Troubleshooting

Symptom Cause Fix
Layout refused, or devices idle Product of the sizes differs from the slice, or chips counted instead of devices Recount \(DP \times TP \times PP \times PCP\); 8 devices per v7x host
MoE throughput low with TP=8 Wide attention all-reduces on every layer DP=8, TP=1 with --enable-expert-parallel
KV per device stops shrinking as TP grows TP above the KV head count replicates KV heads Use DP for the extra devices
Pipeline stages idle with mixed prompt lengths Lockstep wave handoff TPU_PP_HANDOFF=ring (libtpu 0.0.50+, torch_tpu 0.2.0+)
Smaller KV cache than expected with PP Ring buffers reserved before the KV cache Lower TPU_PP_RING_DEPTH or --max-num-batched-tokens
A two-core PP stage on v7x binds both cores of one chip Default device order Set VLLM_TPU_DEVICE_ORDER, for example 0,2,1,3,4,6,5,7
A PP stage spanning a PCP group with an MoE model That combination requires expert parallelism Add --enable-expert-parallel

References