---
title: 'Cold Compile Optimization, Part 2: Cross-DP Compile Reuse for Data-Parallel Deployments on TPU'
author: Forrest Xi
date: '2026-10-09'
url: https://blog.maxwell-x.dev/en/hy4-cold-compile-dp/
lang: en
tags:
- TPU
- vLLM
- XLA
- Compilation
- Data Parallelism
---

# Cold Compile Optimization, Part 2: Cross-DP Compile Reuse for Data-Parallel Deployments on TPU

> The cross-rank replay described in the previous post only looks for reusable compiled artifacts within the same DP index. In a pure data-parallel deployment each inference engine has a DP index of its own, so replay never happens. We widened replay to search across DP indices, and for layouts that mix tensor and data parallelism we normalized the process group names in the graph fingerprint. On our self-maintained branch with the same image, the time from weights loaded to service ready dropped from 741 s to 270 s for Qwen3.5 DP8, and from 703 s to 251 s for TP2×DP4.

::: tldr
**TL;DR**

- **Problem**: the cross-rank replay proposed upstream in vllm-torchtpu (not yet merged into main) only looks for reusable compiled artifacts within the same DP index. Under pure data parallelism each engine owns one DP index, so the replay count is 0, and for every bucket all 8 engines go through tracing, conversion, loading and saving on their own.
- **Solution**: with tensor parallel size 1, widen the replay search to all DP indices. With tensor parallel size greater than 1, the graphs of different DP groups differ only in the process group names of collective calls, so we first normalize the group names in the graph fingerprint and then replay across DP.
- **Gain**: on our self-maintained branch with the same image, the time from weights loaded to service ready dropped from 741 s to 270 s for Qwen3.5 DP8, from 703 s to 251 s for TP2×DP4, and from 606 s to 241 s for TP4×DP2. All of them passed the accuracy evaluation.
:::

## Background

[The previous post](https://blog.maxwell-x.dev/en/hy4-cold-compile/) covered cold compile optimization for Hy4 on TPU v7. One of the key changes was replaying compiled artifacts between ranks: vllm-torchtpu assigns token buckets to different ranks for compilation, and once one rank has finished a complete artifact and it passes the graph fingerprint check, the other ranks load it directly instead of tracing and compiling again. Hy4's production deployment is TP16 with a single DP group, so all 16 ranks can replay from each other, and the change brought a significant gain.

Data-parallel (DP) deployments are different. For a model like Qwen3.5-397B we deploy DP8 on a single TPU v7 host: each of the 8 inference engines holds a full copy of the attention weights and serves its own requests, while expert parallelism shards the MoE experts across the 8 engines. Yet replay barely shortened cold compile for this layout. This post explains why, and how we made replay work under data parallelism.

Unless noted otherwise, cold compile time in this post means the time from the last `Loading weights took` log line to service ready, starting from an empty cache. It excludes pod startup and weight loading. The previous post measured from pod creation, so the two sets of numbers are not directly comparable.

## Problem: why replay fails under data parallelism

### Replay only searches within the same DP index

In the code, when cross-rank replay looks for artifacts to replay, it only matches other ranks under the same DP index, and the lock file name used to claim a compile task also contains the DP index. With tensor parallel size 1, each DP index has only one rank, so there is no peer to find. In a controlled experiment with the same image and parallel precompile enabled, Qwen3.5 DP8 recorded 0 replays; the same setup with the cross-DP replay patch recorded 70 (10 buckets × 7 engines).

### What gets repeated is the vLLM-layer compile pipeline

This does not mean the 8 engines compile the same XLA program 8 times. Judging by the cache directory, in each of three cold compiles every bucket has only 1 copy of the XLA cache, the graphs exported by the 8 engines have identical md5, and the vLLM-layer artifacts of all engines have the same byte size, differing only in timing metadata. What is not shared is the vLLM-layer pipeline: AOTAutograd, conversion from FX graph to MLIR, and loading and serializing the compiled artifact. Every engine runs these steps itself, all 8 engines work on the same bucket at the same time, and buckets advance one after another.

### Where the time goes

Take the original Qwen3.5 DP8 recipe as an example (an older image, without parallel precompile). Three cold compiles averaged 1008.1 s. Cross-checking the log timeline against the modification times of the cache files gives the following breakdown:

| Item | s | Share |
|---|---:|---:|
| The 9 main-model buckets other than the slowest of the 10: 8 engines compile the same bucket in lockstep, buckets run serially | 646.3 | 64.1% |
| Necessary compile (the slowest bucket, 1024) | 93.2 | 9.2% |
| Disk writes and serialization | 87.6 | 8.7% |
| Sampler and other small graphs | 62.3 | 6.2% |
| Dynamo tracing | 54.8 | 5.4% |
| Compilation during the profile run | 50.0 | 5.0% |
| Other | 14.0 | 1.4% |

The compile window of the 9 main-model buckets takes nearly two thirds of the total, and the logs cannot separate how much of it is XLA compilation and how much is the vLLM-layer pipeline. If each bucket went through the full pipeline on only one engine, with the other engines replaying at zero cost, and the profile run were skipped, the theoretical floor would be about 223 s.

## Solution

### Tensor parallel size 1: cross-DP replay

The change itself is small: widen the search for peer artifacts from the same DP index to all DP indices. The graph fingerprint is kept and checked on every replay. Each bucket then goes through the full pipeline on one engine, and the other 7 replay directly.

There are two versions of this change. All Qwen3.5 data in this post comes from the implementation on our self-maintained branch: besides widening the search, it replaces the DP index in the claim lock file name with a uniform marker, which, together with the claim file mechanism mentioned in the previous post, ensures that only one engine compiles each bucket. The version submitted upstream only widens the search. Its switch does not enter the compile cache key, so toggling it does not trigger recompilation. Its effect is measured separately on the reduced-layer GLM-5.2 testbed below.

On the deployments we tested, none of the following evidence found replay changing the output:

- **Program level**: the graphs exported by the 8 engines have identical md5, and the vLLM-layer artifacts have the same byte size, differing only in timing metadata. The expert start index used by expert parallelism is a graph input, not a constant.
- **Accuracy evaluation**: Qwen3.5 DP8 with cross-DP replay enabled averaged 96.82 on GSM8K and 89.21 on MMLU over three rounds. On the finalized image, three rounds gave GSM8K 96.89 and MMLU 89.26, with no significant difference from the original recipe in a per-question paired comparison.
- **Per-logprob comparison with real weights**: on upstream code and a newer torch_tpu version, we deployed DP8 with the real weights of the first 6 layers of DeepSeek-V3.2. Each DP rank sent the same fixed 5 prompts, and every rank ran replayed artifacts for at least 4 buckets. For all 40 outputs, the text and the top-5 logprobs at every position were identical to runs without replay. In the positive control (changing the MoE quantization block size), all 40 differed.

All of this evidence is at the output level. The graph fingerprint cannot see closure constants outside the graph, so on other models or layouts you still need to first confirm that no per-rank values enter closures, or run the same output comparison.

### Tensor parallel size greater than 1: normalizing process group names

When tensor parallel size is greater than 1, the TP ranks within each DP group form their own process group. The last argument of a collective call in the graph (such as `_c10d_functional.all_reduce(..., 'sum', '3')`) is the process group name. Different DP groups have different group names, so their graph fingerprints differ and every replay is rejected. In Qwen3.5 TP2×DP4, the two graphs of the same TP rank in different DP groups differ in 242 lines, all of them group names.

Before computing the graph fingerprint, we replace the group names in collective calls with a uniform placeholder and leave everything else unchanged (a unit test pins down that only group names are normalized). On real graphs, all 361 calls were rewritten, after which the graphs of different DP groups no longer differed at all. With the patch, Qwen3.5 TP2×DP4 went from 0 replays (262 rejected) to 70 replays (0 rejected). On the vLLM 0.29 self-maintained branch we use, the start and end positions of the vocabulary shards are already tensors rather than constants, so after group name normalization the graphs of all 8 workers are identical. Replay then spans both DP groups and TP ranks, and each bucket needs to be compiled only once.

Whether this is safe depends on how the underlying runtime compiles collectives for subgroups: cross-group replay is correct only if the subgroup programs of different DP groups are themselves identical. We confirmed that the runtime version we used at the time satisfies this, but a newer version that upstream pinned later changed the device-assignment-related part of the compile cache, so cross-DP-group replay could load a program with a different device assignment (inference, not verified on hardware). For this reason we did not submit this part upstream, and on our self-maintained branch we added a version check that refuses to normalize and prints a warning when the runtime version is newer or unknown.

### Skipping the profile run

Data-parallel deployments can also set the KV cache size directly with `--kv-cache-memory-bytes` and skip the profile run at startup, with the number of KV blocks still fixed by `--num-gpu-blocks-override`. On Qwen3.5 DP8 the profile run takes about 100 s, and skipping it is necessary to reach the theoretical floor above.

## Gains

In the comparison below, both arms use the same image, and both have parallel precompile enabled and skip the local AOTAutograd save and the profile run. The only difference is whether cross-DP replay takes effect.

<figure>
  <div class="chart" role="img" aria-label="Cold compile time for three Qwen3.5 layouts before and after cross-DP replay takes effect">
    <div class="row pair"><div class="lab">DP8<small>TP1</small></div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 1.0000)"></span><span class="val">741</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.3647)"></span><span class="val">270</span></div></div></div>
    <div class="row pair"><div class="lab">TP2×DP4</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.9483)"></span><span class="val">703</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.3390)"></span><span class="val">251</span></div></div></div>
    <div class="row pair"><div class="lab">TP4×DP2</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.8182)"></span><span class="val">606</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.3256)"></span><span class="val">241</span></div></div></div>
    <div class="legend"><span><i style="background:var(--ink-2)"></i>0 replays</span><span><i style="background:var(--accent)"></i>Cross-DP replay active</span></div>
  </div>
  <figcaption>Cold compile time (seconds) of Qwen3.5-397B on a single TPU v7 host, from weights loaded to service ready, empty cache, with both arms of each layout on the same image. The 0-replay arms were measured once each. Of the arms with replay active, DP8 and TP2×DP4 were each measured three times and averaged, and TP4×DP2 was measured once. The TP2×DP4 control arm had the cross-DP switch on but group names not normalized, so every replay was rejected.</figcaption>
</figure>

| Layout | 0 replays | Cross-DP replay active | Accuracy evaluation |
|---|---:|---:|---|
| Qwen3.5 DP8 | 741.1 s (1 run) | 270.3 s (3 runs: 273.4 / 268.7 / 268.7) | Same arm, three rounds: GSM8K 96.82, MMLU 89.21 |
| Qwen3.5 TP2×DP4 | 702.8 s (1 run) | 251.2 s (3 runs: 249.1 / 246.8 / 257.8) | Finalized image, three rounds: GSM8K 96.79, MMLU 89.30 |
| Qwen3.5 TP4×DP2 | 606.4 s (1 run) | 241.3 s (1 run) | One round: GSM8K 97.04, MMLU 89.18 |

With cross-DP replay enabled, cold compile time depends little on how tensor parallelism is split: TP2×DP4 takes 251 s and TP4×DP2 takes 241 s, while with 0 replays the two differ by nearly 100 s (different images, one run each). This matches the expectation that each bucket is really compiled only once. Replay itself is cheap: in one DP8 measurement, the time for each engine from entering a bucket to finishing its replay had a median of 1.5 s, and the longest, 61.5 s, occurred when several engines were waiting on a claim at the same time.

Compared with the very first original recipe, Qwen3.5 DP8 went from 1008.1 s (mean of three runs) to about 270 s. In between, however, we also changed the image and vLLM version, turned on several compile-time switches covered in the previous post, and skipped the profile run, so the whole gain cannot be attributed to cross-DP replay.

On throughput, replay changes only where the program comes from, not the program itself. The formal benchmark of Qwen3.5 DP8 with cross-DP replay enabled showed no drop against historical benchmark results of the original recipe, but the two measurements were taken on different dates and nodes, so they only show that it is no worse.

## Trying it on Hy4

We also tried a layout mixing tensor and data parallelism on Hy4. TP8×DP2 is deployed across two hosts. The original recipe averaged 1520.0 s of cold compile over three runs. With both cross-DP replay (with group name normalization) and the profile-run skip enabled, one run measured 931.3 s. After group name normalization, the graphs of all 16 ranks were identical line by line, and rejected replays fell from more than 330 to 0. This comparison also changed the image and combined the two changes, so it is for reference only.

In the end TP8×DP2 was not used for Hy4's production deployment. The main reason is that the mixed-step sequence parallelism in Hy4's production config requires a single DP group, which is structurally incompatible with TP8×DP2. On performance, under the first-round default config (one run each at concurrency 8 and 64), the extra communication from data parallelism added 81–90 ms to each mixed step. With 8K input and 1K output, throughput was 21% lower than TP16 at concurrency 8, 9% lower at concurrency 32, and roughly on par at concurrency 64. TP16 has a single DP group, where the same-DP replay from the previous post already takes full effect, so it does not need the changes in this post.

## Upstream validation

To confirm that cross-DP replay is equally effective on upstream code, we deployed DP8 on TPU v7x with a GLM-5.2 config reduced to 6 layers and dummy weights, and compared three versions of the code: the upstream baseline, the baseline plus cross-rank replay, and that plus cross-DP replay. Each was measured three times, from serve start to the health check passing:

<figure>
  <div class="chart" role="img" aria-label="Ready time of three implementations on upstream code">
    <div class="row"><div class="lab">Upstream baseline</div><div class="track"><span class="fill base" style="width:calc((100% - 5.5em) * 0.9003)"></span><span class="val">180.7</span></div></div>
    <div class="row"><div class="lab">+ Cross-rank replay</div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 1.0000)"></span><span class="val">200.7</span></div></div>
    <div class="row"><div class="lab">+ Cross-DP replay</div><div class="track"><span class="fill" style="width:calc((100% - 5.5em) * 0.6827)"></span><span class="val">137.0</span></div></div>
  </div>
  <figcaption>Time (seconds) from serve start to the health check passing, GLM-5.2 reduced to 6 layers, dummy weights, DP8, mean of three runs each, same image.</figcaption>
</figure>

Cross-DP replay is 63.7 s faster than cross-rank replay alone (the three paired runs on the same pod were −61, −70 and −60 s), and 43.7 s faster than the upstream baseline (−24%). Note also that on this reduced-layer testbed, cross-rank replay on its own, in a deployment with tensor parallel size 1, was 20 s slower than the baseline. The gap falls in the main-model compile phase, and we have not yet found the cause.

Because model outputs carry no signal with dummy weights, correctness was instead validated with the real weights of the first 6 layers of DeepSeek-V3.2; the results are given above. Cross-DP replay stacks on top of cross-rank replay and has been submitted upstream, where it is pending review.

## Scope and limitations

Cross-DP replay applies to data-parallel deployments with tensor parallel size 1 on vllm-torchtpu. It requires all engines to share the same compile cache root, parallel precompile to be enabled, and the main-model programs traced by every engine to be identical. In such deployments, once replay is on, cold compile is essentially reduced to compiling the slowest bucket once plus the serial segments that cannot be parallelized.

A few points to keep in mind:

- With tensor parallel size greater than 1, process group names must be normalized before replaying across DP, and the safety of this approach has so far only been confirmed on an older runtime version.
- The graph fingerprint cannot see closure constants outside the graph, such as per-device values captured in a Pallas kernel closure. Letting more ranks share the same artifact amplifies the risk from such constants. All current correctness evidence is at the output level (accuracy evaluation and per-logprob comparison).
- For deployments with a single DP group (such as Hy4's TP16), the changes in this post bring no additional gain.
- Pure data-parallel deployments spanning multiple hosts have not been tested.
- Most control arms in this post were measured only once, and the contribution of skipping the profile run was not isolated.

## Series

Overview: [Beating B200 from Scratch: Porting and Optimizing Hy4 Inference on TPU v7](https://blog.maxwell-x.dev/en/hy4-on-tpu-v7/)

1. [From 2 tok/s to Beating B200: Optimizing Hy4 Inference on TPU v7](https://blog.maxwell-x.dev/en/hy4-tpu-vs-b200/)
2. [Hy4 Weight Loading on TPU v7: From 857 Seconds to 68](https://blog.maxwell-x.dev/en/hy4-weight-loading/)
3. [95 Minutes to 14: Cold Compile Optimization for Hy4 on TPU v7](https://blog.maxwell-x.dev/en/hy4-cold-compile/)
4. [Cold Compile Optimization, Part 2: Cross-DP Compile Reuse for Data-Parallel Deployments on TPU](https://blog.maxwell-x.dev/en/hy4-cold-compile-dp/)
5. [Cold Compile Optimization, Part 3: Cross-Rank Reuse for Sequence-Parallel Buckets, 48 Minutes to 17.7](https://blog.maxwell-x.dev/en/hy4-cold-compile-sp/)

::: postscript
Data comes from our data-parallel cold compile optimization records and upstream validation from 2026-10-02 to 10-08.
:::
