Profile vLLM-TorchTPU serving¶
Use this guide when a vLLM-TorchTPU server is correct but slower than you expect and you need a TPU trace of what it does: one prefill or decode shape offline, a real serving window, one trace per inference phase, or the two halves of a disaggregated request. Each TPU worker process runs its own profiler session and traces only the chips it owns, so a whole-slice trace is assembled from one capture per worker; every mode writes XPlane (*.xplane.pb) that XProf reads. Chapter 10 explains how to read a trace (and Capture and read an XProf trace is the training-side guide); chapter 18 explains the engine you are tracing.
Prerequisites¶
- A working server or offline run: Serve a first model with vLLM-TorchTPU.
- A clone of
https://github.com/vllm-project/vllm-torchtpu.gitforexamples/andscripts/. - A viewer for the XPlane files, on the VM or your workstation (capture needs nothing extra):
pip install xprof # or: pip install tensorboard-plugin-profile
Choose a mode¶
| Mode | Also called | Best for | Writes |
|---|---|---|---|
Offline, examples/tpu_profiling.py |
non-phased, on-demand | One prefill or one decode shape, no scheduler noise | XPlane and Chrome JSON |
| Server-side capture | end-to-end | A real serving window under vllm bench serve or your client |
XPlane and Chrome JSON |
| Phased profiling | phased | One bounded trace per inference phase from one mixed run | XPlane and Chrome JSON, one set per phase per rank |
| Disaggregated serving (Raiden3) | P/D, KV transfer profiling | Correlating prefill and decode traces across pods | as the mode each pod runs |
Two words keep the server modes straight. A server is configured when it was started with a profiler kind and a trace directory, so the profile endpoints work; it is armed once /start_profile has been called, and /stop_profile disarms it. A server that is configured but never armed writes nothing, the most common reason a run produces no trace.
Profiling is not free: in benchmark runs --profile costs roughly 11% more TTFT and 4% less throughput. Never compare profile-on numbers with a baseline taken without it.
Offline: one shape¶
examples/tpu_profiling.py drives the offline LLM API with a synthetic batch, warms up, and traces --num-iters generate calls. It accepts all vLLM engine arguments plus --input-len, --output-len, --batch-size, --num-iters-warmup, --num-iters and --profile-result-dir. Warmup matters: the first iterations pay XLA compilation.
A prefill (long prompt, one output token, small batch):
python3 examples/tpu_profiling.py \
--model Qwen/Qwen3-30B-A3B-FP8 \
--tensor-parallel-size 4 \
--enable-expert-parallel \
--input-len 1024 \
--output-len 1 \
--batch-size 1 \
--profile-result-dir profiles/prefill_1k
A decode (single-token requests, large batch):
python3 examples/tpu_profiling.py \
--model Qwen/Qwen3-30B-A3B-FP8 \
--tensor-parallel-size 4 \
--enable-expert-parallel \
--input-len 1 \
--output-len 1 \
--batch-size 256 \
--profile-result-dir profiles/decode_bs256
examples/run_profiling_suite.sh sweeps a matrix of these; uncomment the experiments you want and run it.
Check: the result directory contains plugins/profile/<timestamp>/*.xplane.pb.
Server: a serving window¶
Start the server with a trace directory. --profiler-config.profiler torch is required: vLLM's ProfilerConfig validator rejects a trace directory without it.
vllm serve Qwen/Qwen3.5-35B-A3B-FP8 \
--tensor-parallel-size 4 --enable-expert-parallel \
--profiler-config.profiler torch \
--profiler-config.torch_profiler_dir /tmp/vllm_profile \
--profiler-config.ignore_frontend true
Then bracket the traffic you care about:
curl -X POST http://localhost:8000/start_profile
# ... send the traffic you want to trace ...
curl -X POST http://localhost:8000/stop_profile
vllm bench serve --profile makes those two calls around its main run. --profiler-config.ignore_frontend true skips the AsyncLLM frontend's CPU profiler, which is pure overhead here. This mode always traces the whole window between the two calls; --profiler-config.delay_iterations and --profiler-config.max_iterations apply only to the phased profiler.
Options per session. /start_profile accepts a JSON payload (or query parameters): profile_prefix names the output subdirectory, and every other key is passed on as profiler_kwargs, such as tracer levels (host_tracer_level, device_tracer_level, python_tracer_level), TPU options (tpu_trace_mode, tpu_num_sparse_cores_to_trace, tpu_num_sparse_core_tiles_to_trace) and firmware events:
curl -X POST http://localhost:8000/start_profile \
-H "Content-Type: application/json" \
-d '{
"profile_prefix": "fw_events_run",
"host_tracer_level": 3,
"tpu_trace_mode": "TRACE_COMPUTE_AND_SYNC",
"e2e_enable_fw_throttle_event": true,
"e2e_enable_fw_power_level_event": true,
"e2e_enable_fw_thermal_event": true
}'
Offline, pass the same through llm.start_profile(profile_prefix="fw_events_run", profiler_kwargs={...}).
Through the benchmark harness. CAPTURE_PROFILE=1 adds the profiler flags and, after each cell's measured run, runs the cell once more with --profile, writing traces to <results-dir>/profile. Neither the warmup nor the measured run is profiled, so the reported numbers stay comparable to a baseline. Prefer a single input and output length cell so the trace maps to one workload shape.
CAPTURE_PROFILE=1 ./scripts/vllm/benchmarking/run_benchmarks.sh \
--config qwen3.5-35b-fp8-tp4-ep
The harness also infers CAPTURE_PROFILE=1 when EXTRA_SERVE_ARGS contains --profiler-config.torch_profiler_dir; CAPTURE_PROFILE=0 opts out.
Check: <torch_profiler_dir>/plugins/profile/<timestamp>/ holds one .xplane.pb per rank, and rank_<N>/ one .pt.trace.json.gz per rank.
Phased: one trace per inference phase¶
A serving run mixes prefill and decode in one stream, so one continuous trace blends both. The phased profiler classifies each engine step by its batch composition, prefill_tokens / total_scheduled_tokens, and captures a separate, bounded trace the first time each phase appears in a session:
Every engine step lands somewhere on this line. The first step in a tinted band or at an exact end point, while no capture is running, starts that phase's capture, which then records the next max_iterations steps whatever their ratio; a step in an untinted gap is classified ambiguous and never starts one.
Ratios in the gaps (0.2 to 0.4, 0.6 to 0.9) are ambiguous and never start a capture, though such a step can fall inside another phase's capture window. A request with no computed tokens is prefill; an ongoing request scheduled for more than one token is chunked prefill; for one token, decode. Speculative draft tokens count as decode.
Through the harness (no curl needed):
rm -rf /tmp/vllm_phased_profile
USE_PHASED_PROFILER=true \
EXTRA_SERVE_ARGS='--profiler-config.profiler torch --profiler-config.torch_profiler_dir /tmp/vllm_phased_profile --profiler-config.max_iterations 5' \
./scripts/vllm/benchmarking/run_benchmarks.sh --config qwen3.5-35b-fp8-tp4-ep
Or against your own server:
rm -rf /tmp/vllm_phased_profile
USE_PHASED_PROFILER=true vllm serve Qwen/Qwen3.5-35B-A3B-FP8 \
--tensor-parallel-size 4 \
--enable-expert-parallel \
--attention-backend CUSTOM \
--profiler-config.profiler torch \
--profiler-config.torch_profiler_dir /tmp/vllm_phased_profile \
--profiler-config.max_iterations 5 \
--profiler-config.ignore_frontend true
then the same start_profile and stop_profile calls around your traffic. USE_PHASED_PROFILER must be in the server's own environment, because the TPU workers read it. Keep --attention-backend CUSTOM: without it vLLM falls back to FLASH_ATTN with block_size=16, and you profile a backend you do not serve with. Clear the trace directory between runs; phases accumulate in per-phase subdirectories.
The traffic decides the phases: one request at a time gives only prefill_only and decode_only, and the mixed phases need concurrency.
| Setting | Effect |
|---|---|
USE_PHASED_PROFILER=true |
The only on/off switch; selects the phased profiler |
--profiler-config.profiler torch |
Required with the trace directory |
--profiler-config.torch_profiler_dir <dir> |
Root for the traces |
--profiler-config.max_iterations N |
Steps captured per phase; unset falls back to 15 |
--profiler-config.delay_iterations N |
decode_heavy steps to skip before that phase's capture, to step past warmup; default 0 |
--additional-config '{"phased_profiler_decode_only_kv_len_threshold": N, "phased_profiler_prefill_only_kv_len_threshold": M}' |
Skip decode_only or prefill_only steps until the batch's minimum KV length reaches the threshold; default -1 (off); not part of the compile cache key |
Check: /tmp/vllm_phased_profile/ has one subdirectory per phase that occurred, each with plugins/profile/<timestamp>/ and rank_<N>/batch_composition_stats_<timestamp>.json files, max_iterations + 1 files per rank per phase (one for the step that starts the capture and one per profiled step after it), recording the batch's token counts, minimum KV length and assigned phase.
Read the output layout¶
A phased run at TP=4 writes, per captured phase, 4 XPlane files and 4 Chrome traces, plus max_iterations + 1 batch_composition_stats_*.json files per rank, one for the step that starts the capture and one for each profiled step after it (three phases at max_iterations=5: 12 XPlane files, 12 Chrome traces and 72 stats files):
/tmp/vllm_phased_profile/
├── prefill_only/
│ ├── plugins/profile/2026_08_03_10_15_42/
│ │ ├── rank0_t1v-n-abccf5c4-w-0.xplane.pb
│ │ └── ... one per rank
│ ├── rank_0/
│ │ ├── batch_composition_stats_<timestamp>.json
│ │ └── <host>_<pid>.pt.trace.json.gz
│ └── ...
└── decode_only/
└── ...
A standard run has the same layout without the phase level, plus <host>_<pid>.async_llm.pt.trace.json.gz unless ignore_frontend is set. XPlane files are named after the host, so each rank captures into its own sandbox and gets a rank<N>_ prefix on the way into the shared directory; the prefix uses the slice-global rank (TP × PP × DP), so DP replicas do not collide. On a multi-host slice, rank 0 publishes the run timestamp through a marker file the others poll for 5 s, so the trace directory must be on a filesystem every rank shares with rank 0.
Check: every file in plugins/profile/<timestamp>/ starts with rank<N>_ when the world size is above 1, and no did not find rank 0's canonical-ts marker warning appears in the logs.
View the traces¶
On the VM:
xprof --logdir /tmp/vllm_phased_profile
Forward the port (6006 by default) if your SSH client does not: ssh -L 6006:localhost:6006 <tpu-vm-host>. To keep traces after the VM is gone, copy them down with the directory hierarchy intact, since XProf reads the plugins/profile/<timestamp>/ layout:
rsync -avzm \
--include='*/' \
--include='*.xplane.pb' \
--include='*.pt.trace.json.gz' \
--exclude='*' \
<tpu-vm-host>:/tmp/vllm_phased_profile ~/traces/
xprof --logdir ~/traces/vllm_phased_profile
Each phase is a separate run in XProf's dropdown. The Trace Viewer shows kernel timelines; Memory Profile and Op Profile cover HBM use and MXU utilization. All ranks' XPlane files of a run sit in one directory, so XProf loads them as one session with a host picker. The Chrome JSON traces stay per rank under rank_<N>/; drag one into Perfetto or Chrome Tracing.
For a consumer that takes one file (an offline upload, a bug attachment), merge a session's per-rank captures:
python -m vllm_torchtpu.tools.merge_xplane /tmp/vllm_phased_profile
It writes one merged file per phase into the phase directory, about half the input size, because the per-rank copies of /host:metadata (which carry the HLO protos) collapse into one. --dry-run shows what would be written, -o names a single output, -d chooses the output directory. You do not need it for xprof --logdir. Never put a merged file inside plugins/profile/<timestamp>/: XProf would count it as an extra host and report twice the cores and events, with nothing to show it.
Check: XProf lists one run per phase, and its host picker shows one host per rank.
Disaggregated serving¶
Raiden3 (TPURaidenConnector) disaggregation profiling is experimental; the vLLM-TorchTPU disaggregated profiling guide documents it as of commit 7bb6a4a. Prefill and decode run in separate pods, so arm /start_profile on both services before sending traffic and disarm both afterwards. The connector emits TraceAnnotation scopes that carry the shared transfer uuid and request_id:
| Role | Annotation | Metadata |
|---|---|---|
Prefill (kv_producer) |
KV_Cache_Prefill_Register_Blocks |
uuid, request_id, num_tokens, num_blocks |
Prefill (kv_producer) |
KV_Cache_Prefill_Send_Complete |
uuid, request_id, num_tokens |
Decode (kv_consumer) |
KV_Cache_Decode_Submit_Load |
uuid, request_id, source_req_id, num_tokens, num_blocks |
Decode (kv_consumer) |
KV_Cache_Decode_Recv_Complete |
uuid, request_id, source_req_id, num_tokens, reshard_e2e_latency_ms |
One disaggregated request leaves four annotations in two traces, joined by the transfer's uuid, so search for it in each pod's run. reshard_e2e_latency_ms runs from the decode side's load submission to the transfer's completion, and the prefill side records KV_Cache_Prefill_Send_Complete only after that pull completes.
1. Deploy both pods with profiling on. Both GKE deployments enable the Raiden store-based KV cache manager and write traces to a mounted persistent volume:
env:
- name: TPU_USE_RAIDEN_KV_CACHE_MANAGER
value: "1"
- name: TPU_KV_RESHARD_TRANSPORT
value: "raiden"
- name: TPU_RAIDEN_RESHARD_IMPL
value: "store"
- name: USE_PHASED_PROFILER
value: "true" # set to "false" or omit for continuous non-phased profiling
args:
- --profiler-config='{"profiler": "torch", "torch_profiler_dir": "/usr/vllm/vllm_profile", "ignore_frontend": true}'
- --kv-transfer-config='{"kv_connector": "TPURaidenConnector", "kv_connector_module_path": "vllm_torchtpu.distributed.kv_transfer.tpu_connector", "kv_role": "kv_producer", "kv_port": 14579}'
("kv_role": "kv_consumer" on the decode deployment.) The repository's reference manifests are docs/developers_guide/examples/raiden_pd_prefill.yaml (TPU v6e 2x2, PCP=4, TP=1) and raiden_pd_decode.yaml (TPU v6e 2x2, DP=4, TP=1):
kubectl apply -f docs/developers_guide/examples/raiden_pd_prefill.yaml
kubectl apply -f docs/developers_guide/examples/raiden_pd_decode.yaml
2. Arm both, send one request through both, disarm both. Forward the services:
kubectl -n disagg-1-1 port-forward svc/vllm-service-prefill 8000:8000 &
kubectl -n disagg-1-1 port-forward svc/vllm-service-decode 8001:8000 &
The vLLM-TorchTPU profiling guide's script, in outline: POST /start_profile to both; send the prompt to the prefill service's /v1/completions with "max_tokens": 1 and "kv_transfer_params": {"do_remote_decode": true, "do_remote_prefill": false}; send the same prompt to the decode service with "max_tokens": 32 and the kv_transfer_params the prefill response returned; POST /stop_profile to both. The full Python script is on the vLLM-TorchTPU profiling page.
3. Copy both traces and open them together.
export NAMESPACE="disagg-1-1"
export PREFILL_POD=$(kubectl -n "$NAMESPACE" get pods -l app=vllm-prefill -o jsonpath="{.items[0].metadata.name}")
export DECODE_POD=$(kubectl -n "$NAMESPACE" get pods -l app=vllm-decode -o jsonpath="{.items[0].metadata.name}")
mkdir -p ./phased_traces
kubectl cp "${NAMESPACE}/${PREFILL_POD}:/usr/vllm/vllm_profile/prefill_only" ./phased_traces/prefill_only -c vllm-tpu
kubectl cp "${NAMESPACE}/${DECODE_POD}:/usr/vllm/vllm_profile/decode_only" ./phased_traces/decode_only -c vllm-decode
xprof --logdir ./phased_traces
Check: search the Trace Viewer for the request's uuid: it appears on KV_Cache_Prefill_Register_Blocks in the prefill run (and on KV_Cache_Prefill_Send_Complete once the decode side's pull has completed, if the capture is still running) and on KV_Cache_Decode_Submit_Load and KV_Cache_Decode_Recv_Complete in the decode run, and the last one carries reshard_e2e_latency_ms, the transfer's end-to-end latency.
For setting up disaggregation itself, see Disaggregate prefill and decode.
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
Startup fails: Legacy additional_config['phased_profiling_dir'] is no longer supported |
A script written for the old configuration | USE_PHASED_PROFILER=true with --profiler-config.torch_profiler_dir |
Startup fails: USE_PHASED_PROFILER is set but there is nowhere to write traces |
No trace directory | --profiler-config.profiler torch --profiler-config.torch_profiler_dir <dir> |
| The startup validator rejects the trace directory | --profiler-config.profiler torch missing |
Add it |
| The run finishes, the directory is empty | Configured, never armed | Call /start_profile; through the harness, CAPTURE_PROFILE must resolve to 1 |
| A phase is missing | The workload never produced that batch composition | Single requests give only prefill_only and decode_only; mixed phases need concurrency; read batch_composition_stats_*.json |
USE_PHASED_PROFILER has no effect |
Set only in the shell that runs curl |
Export it in the server's environment |
| Traces split across two timestamped directories | Ranks missed rank 0's timestamp marker | Trace directory on a filesystem shared with rank 0 |
| XProf shows twice the cores and events | A merged file inside plugins/profile/<timestamp>/ |
Keep merged files in the phase directory |
| Per-expert MoE timings look skewed | With EP, a device's profile shows only the experts routed to it | VLLM_MOE_ROUTING_SIMULATION_STRATEGY=uniform_random for profiling only; it produces meaningless output, never serve with it |
The trace shows FLASH_ATTN kernels |
--attention-backend CUSTOM missing |
Profile with the backend you serve with |
| Profiled numbers worse than the baseline | Profiling overhead | Compare only profile-on with profile-on |
References¶
- vLLM-TorchTPU: Profiling
- vLLM-TorchTPU: Offline profiling with examples/tpu_profiling.py
- vLLM-TorchTPU: Server-side capture (vllm serve)
- vLLM-TorchTPU: Phased profiling
- vLLM-TorchTPU: Output layout
- vLLM-TorchTPU: Viewing traces
- vLLM-TorchTPU: Troubleshooting
- vLLM-TorchTPU: Disaggregated serving (Prefill/Decode with Raiden3)
- Chapter 10: Profiling with XProf
- Chapter 18: vLLM-TorchTPU

