---
title: 'From 2 tok/s to Beating B200: Optimizing Hy4 Inference on TPU v7'
author: Forrest Xi
date: '2026-10-08'
url: https://blog.maxwell-x.dev/en/hy4-tpu-vs-b200/
lang: en
updated: '2026-10-09'
tags:
- TPU
- vLLM
- Hy4
- Performance Tuning
- B200
---

# From 2 tok/s to Beating B200: Optimizing Hy4 Inference on TPU v7

> Hy4-preview is a 770B-parameter MoE model with DSA sparse attention and MTP speculative decoding. When first ported to TPU v7, single-stream decoding ran at only 2 tok/s. In the end, across a ten-level benchmark with 8K input / 1K output at concurrency 1–64, 8 TPU v7 chips delivered 3%–19% higher output throughput than 8 B200 GPUs. This post follows the four classes of bottlenecks in the order we hit them: porting the model and getting it correct, getting the model compiled, speeding up sparse-attention prefill with masked-dense, and optimizing mixed steps under high concurrency.

::: tldr
**TL;DR**

- **Result**: in a ten-level benchmark with 8000 input / 1000 output tokens at concurrency 1–64, 8 TPU v7 chips delivered 3%–19% higher output throughput than 8 B200 GPUs, 11%–28% lower time to first token, and lower time per output token at every level (B200 measured once per level).
- **Getting the model to run correctly**: we added MXFP8 quantization support, fixed 6 faults caused by bypassing the MLA wrapper layer, and wired in the learnable attention sink. Output went from garbage back to normal, and GSM8K is in the same range as the B200 side.
- **Getting the model compiled**: Hy4's model class lacked `@support_torch_compile`. Adding it raised single-stream throughput from 2.14 to 48.57 tok/s, and compiling the MTP draft model as well brought it to 100.11 tok/s.
- **Speeding up sparse-attention prefill**: replacing sparse gather with masked-dense cut TTFT at 4K input from 1338.81 ms to 729.04 ms.
- **Optimizing mixed steps under high concurrency**: raising the masked-dense KV length cap, splitting out the speculative verification window, eliminating XLA whole-buffer copies, switching to contiguous DMA writeback and more took concurrency-32 throughput from 0.365 times B200's to 1.046 times.
:::

## Background

### Model

Hy4-preview is an MoE model released by Tencent Hunyuan, with 770B total parameters, 49B active parameters and 78 layers. Two of its structural features have a large impact on the inference system:

- **DSA sparse attention**: for each query, a lightweight indexer first selects the top-2048 from all KV entries, and attention is then computed over those entries (sparse MLA).
- **MTP speculative decoding**: at each decode step the model predicts 3 extra draft tokens, which the main model verifies together; accepted draft tokens are emitted along with the normally generated token.

The official weights use MXFP8 quantization and are 757.88 GiB.

### Experimental setup

| | TPU side | GPU side |
|---|---|---|
| Hardware | 2 × `tpu7x-standard-4t`, topology 2x2x2, 8 TPU v7 chips in total (16 TensorCores) | 1 × `a4-highgpu-8g`, 8 × NVIDIA B200 |
| Parallelism | TP16 + expert parallelism | TP8 + expert parallelism |
| Inference framework | vLLM 0.29.0 + vllm-torchtpu (our own maintained branch) | Official vLLM hy4-preview image (0.1.dev20485+g0fd2e8d50) |
| Libraries | torch 2.13.0, torch_tpu 0.1.1.dev20260912, JAX 0.10.2, libtpu 0.0.47 | torch 2.13.0+cu130, CUDA 13.0, FlashInfer 0.6.17, driver 590.48.01 |
| Attention implementation | masked-dense (when KV ≤ 9216), otherwise sparse | `FLASHMLA_SPARSE` |
| Common settings | MXFP8 weights, fp8 KV cache, MTP k=3 | Same |

Each TPU v7 chip has two TensorCores, each exposed as its own device, so 8 chips give 16 devices and a tensor parallel degree of 16.

### Goal and benchmark method

The final target workload is fixed-length requests with 8000 input / 1000 output tokens, covering ten concurrency levels: 1, 2, 4, 6, 8, 16, 24, 32, 48 and 64. We benchmark the `/v1/chat/completions` endpoint with evalscope, and the metric is output throughput (output tok/s). On the TPU side each level is measured at least twice and averaged (three times at concurrency 32), with B200's formal benchmark results as the reference.

## Results

<figure>
  <div class="chart" role="img" aria-label="Output throughput of TPU v7 and B200 across ten concurrency levels">
    <div class="row pair"><div class="lab">c1</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.1079)"></span><span class="val">122</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.1226)"></span><span class="val">138</span></div></div></div>
    <div class="row pair"><div class="lab">c2</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.1883)"></span><span class="val">212</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.2240)"></span><span class="val">252</span></div></div></div>
    <div class="row pair"><div class="lab">c4</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.3120)"></span><span class="val">352</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.3356)"></span><span class="val">378</span></div></div></div>
    <div class="row pair"><div class="lab">c6</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.3852)"></span><span class="val">434</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.4292)"></span><span class="val">484</span></div></div></div>
    <div class="row pair"><div class="lab">c8</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.4524)"></span><span class="val">510</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.5078)"></span><span class="val">572</span></div></div></div>
    <div class="row pair"><div class="lab">c16</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.6121)"></span><span class="val">690</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.6821)"></span><span class="val">768</span></div></div></div>
    <div class="row pair"><div class="lab">c24</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.7036)"></span><span class="val">793</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.7483)"></span><span class="val">843</span></div></div></div>
    <div class="row pair"><div class="lab">c32</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.8127)"></span><span class="val">916</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.8501)"></span><span class="val">958</span></div></div></div>
    <div class="row pair"><div class="lab">c48</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.8874)"></span><span class="val">1000</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 0.9379)"></span><span class="val">1057</span></div></div></div>
    <div class="row pair"><div class="lab">c64</div><div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.9735)"></span><span class="val">1097</span></div><div class="track"><span class="fill thin" style="width:calc((100% - 5.5em) * 1.0000)"></span><span class="val">1127</span></div></div></div>
    <div class="legend"><span><i style="background:var(--ink-2)"></i>8 × B200</span><span><i style="background:var(--accent)"></i>8 × TPU v7</span></div>
  </div>
  <figcaption>Output throughput (tok/s), 8000 input / 1000 output; the labels on the left are the concurrency. TPU is the final version v2.14, the mean of two measurements per level (three at c32); B200 is one measurement per level.</figcaption>
</figure>

<div class="tw"><table>
  <tr><th>Concurrency</th><th>TPU throughput</th><th>B200 throughput</th><th>TPU / B200</th><th>TTFT (ms)<br>TPU / B200</th><th>TPOT (ms)<br>TPU / B200</th></tr>
  <tr><td class="num">1</td><td class="num">138.10</td><td class="num">121.58</td><td class="num">1.136</td><td class="num">541 / 701</td><td class="num">6.7 / 7.5</td></tr>
  <tr><td class="num">2</td><td class="num">252.34</td><td class="num">212.09</td><td class="num">1.190</td><td class="num">569 / 738</td><td class="num">7.5 / 8.7</td></tr>
  <tr><td class="num">4</td><td class="num">378.09</td><td class="num">351.52</td><td class="num">1.076</td><td class="num">641 / 806</td><td class="num">9.9 / 10.4</td></tr>
  <tr><td class="num">6</td><td class="num">483.52</td><td class="num">433.95</td><td class="num">1.114</td><td class="num">719 / 908</td><td class="num">11.3 / 12.6</td></tr>
  <tr><td class="num">8</td><td class="num">572.09</td><td class="num">509.61</td><td class="num">1.123</td><td class="num">731 / 1010</td><td class="num">13.1 / 14.4</td></tr>
  <tr><td class="num">16</td><td class="num">768.48</td><td class="num">689.56</td><td class="num">1.114</td><td class="num">1052 / 1361</td><td class="num">19.4 / 21.3</td></tr>
  <tr><td class="num">24</td><td class="num">842.96</td><td class="num">792.66</td><td class="num">1.063</td><td class="num">1286 / 1727</td><td class="num">26.6 / 27.9</td></tr>
  <tr><td class="num">32</td><td class="num">957.73</td><td class="num">915.57</td><td class="num">1.046</td><td class="num">1556 / 2040</td><td class="num">31.4 / 32.4</td></tr>
  <tr><td class="num">48</td><td class="num">1056.60</td><td class="num">999.72</td><td class="num">1.057</td><td class="num">2057 / 2587</td><td class="num">42.8 / 44.8</td></tr>
  <tr><td class="num">64</td><td class="num">1126.56</td><td class="num">1096.72</td><td class="num">1.027</td><td class="num">2862 / 3213</td><td class="num">53.1 / 54.5</td></tr>
</table></div>

At all ten concurrency levels, TPU output throughput is higher than B200's, by 3% (c64) to 19% (c2); time to first token (TTFT) is 11%–28% lower, and time per output token (TPOT) is lower at every level. All 2353 requests in this TPU round succeeded. Some caveats: B200 was measured only once per level; the lead at c4 (7.6%) is within the variation between TPU's own two measurements; the lead at c64 is the smallest, and the lowest of the four TPU samples is only 1.7% above B200.

The comparison was made under the following conditions; please state them when citing these numbers:

- The workload is fixed-length requests with 8000 input / 1000 output tokens at concurrency 1–64. The TPU recipe's maximum context is 10240 and B200's is 262144; when any request in a batch has KV over 9216, TPU's mixed step falls back to the sparse path, and that cost was not measured.
- Both sides use fp8 KV cache, which the TPU sparse attention kernel requires. Its effect on B200 cuts both ways: at 4K input and concurrency 1, fp8 KV on B200 gives 13.3% lower throughput and 10.7% higher TTFT than bf16 KV (fp8 side measured once); but with bf16 KV, B200 holds only about 570,000 tokens, so at high concurrency the extra capacity from fp8 works in its favor. The net effect on this post's workload was not measured.
- The two sides produce different numbers of tokens per decode step. By engine statistics, TPU emits an average of 3.03 tokens per step, while B200 emits 2.59 and 2.54 at concurrency 32 and 64 respectively, so TPU produces 17–19% more. This affects how the throughput comparison should be read, and there are two possibilities. If the difference comes from a genuinely higher acceptance rate, it is a real TPU advantage in this configuration and the lead in the table holds. If part of it comes from the two sides handling the end-of-sequence (EOS) token differently, the lead in the table is overstated. The source of the second case: TPU's sampler does not mask EOS, and `ignore_eos` only keeps generating after EOS is sampled, while B200 masks EOS at the sampler, so the tail content generated on the two sides differs. By a rough estimate this effect is on the order of 1 percentage point (inference); the split between the two causes has not been checked token by token.

The sections below follow the four classes of bottlenecks in the order we encountered them.

## Porting the model and getting it correct

At the start, Hy4 was not in vllm-torchtpu's model list. We extracted the `hy_v4` model code (11 files) from the official GPU image and ported it to vllm-torchtpu. The first obstacle was the quantization format: the weight repository is named FP8, but the actual scheme is modelopt MXFP8, which is not on the TPU platform's quantization allowlist. Following the existing MXFP4 implementation, we added an MXFP8 quantization method that dequantizes at load time and requantizes to the FP8 format used at runtime.

The next problem was subtler: the patches were applied but had no effect. The image contained 3 copies of vllm_torchtpu, and the one patched at build time was not the one imported at runtime. In addition, `current_platform.is_tpu()` is always False on out-of-tree platforms like torchtpu, so patches that depended on it had been taking the else branch all along. We changed the platform check to `device_type == "tpu"`, patched every copy in the image, and added a build-time AST comparison to confirm the patches actually land in the code imported at runtime.

Hy4 also instantiates `MLAAttention` directly instead of going through `MultiHeadLatentAttentionWrapper`. Everything the wrapper normally does had to be filled in by hand, which led to 6 separate faults, ranging from a CUDA FlashAttention import error to top-k indices not being truncated to the current step's token count. Among these, fp8 KV cache is a hard prerequisite of the sparse attention kernel and must be enabled.

The first time the service passed its health check, the output was a repeated `" is is is…"`. During debugging we suspected out-of-bounds top-k indices for a while and spent about 10 rounds verifying it, ruling it out only after re-checking each worker separately. The real problem was that the learnable attention sink had not been wired into the sparse kernel's softmax; once it was connected, output returned to normal (we did not run the reverse experiment of zeroing the sink to reproduce the bad output). In the accuracy evaluation that followed, GSM8K scored only 19.67%. Breaking it down, 79% of the answers were empty: the GSM8K 8-shot stop sequence `Q:` was being triggered inside the model's thinking section. After switching to no_think and re-extracting answers offline, full runs landed between 94.3% and 95.4%, in the same range as the 95.60% from the independent port on the B200 side.

## A missing decorator: getting the model compiled

Once the output was correct, single-stream decoding ran at only 1.9–2.3 tok/s, so generating 1000 tokens took more than 8 minutes. The profile showed TPU utilization of only 7.8%, with 94% of the time spent waiting on the host.

The cause was simple: Hy4's model class `HYV4Model` lacked the `@support_torch_compile` decorator, so all 78 layers ran on TPU with op-by-op dispatch and were never compiled into a whole graph. The serve log had in fact been printing `torch.compile is turned on, but the model … does not support it` the whole time. After adding the decorator and removing three patterns that blocked whole-graph compilation (`fp8_dtype()` scanning `/sys/bus/pci` on every call, leftover debug code, and lazy initialization inside forward), single-stream throughput on short prompts rose from 2.14 to 48.57 tok/s; under the 4000 input / 1000 output setting we used from then on, it was 45.82 tok/s.

The B200 side runs with MTP speculative decoding enabled. To match it, we added the 3 registrations missing from Hy4 MTP in vLLM 0.27, and with MTP enabled throughput reached 72.84 tok/s. The profile showed the draft model taking 35.6% of each step's time, again because it was not compiled. From the profile we predicted that adding the decorator to the draft model `HYV4MTP` would cut TPOT by about 30%. Measured TPOT went from 12.38 to 8.66 ms (−30%), matching the prediction, and throughput reached 100.11 tok/s.

With speculative decoding, a single request has only 1+K tokens per step, which used to be padded up to the smallest bucket of 16. Adding a bucket of 8 tokens raised throughput from 112.29 to 126.33 tok/s (+12.5%, with 5 MTP draft tokens at the time; after switching back to 3 to match B200 it was 117.70 tok/s). This gain is measured and reproducible, but the causal chain "half the padding, therefore faster" was not verified on its own.

## Replacing sparse gather with masked-dense

With decoding faster, the bottleneck moved to prefill: at 4K input and concurrency 1, TTFT was 4.37× B200's. TTFT versus input length is almost a straight line through the origin, with the intercept accounting for only 7.6%, which indicates the limit is device compute rather than the host; the per-token slope was 4.80× B200's. Breaking it down further, each of the 16 devices held a full copy of the KV latent, and to fetch at most 2048 distinct rows, the sparse MLA gather materialized about 4.19 million rows, 2048× redundant. 96.3% of the sparse path's device time went into the gather.

Our first attempt was to use dense attention directly when the KV length did not exceed top-k, but the routing flag was constant-folded into the compiled graph during dynamo tracing, so values written at runtime had no effect, and we had to abandon it. What we finally adopted was the masked-dense method from upstream vllm-torchtpu: instead of gathering, it writes the top-k result as a bitmap (done on SparseCore) and computes masked dense attention, which is semantically equivalent to sparse attention. The upstream implementation did not work as-is, and we added three things: wiring in the learnable attention sink; changing the enabling condition, which upstream only fit deployments with 64 attention heads (under TP16 each device has only 4 heads, so the condition was never met), to check the head count after sharding; and refitting the cost model that chooses between masked-dense and sparse for 4 heads per device, with the path selected on device via `lax.cond`.

After masked-dense went live, TTFT at 4K input dropped from 1338.81 ms to 729.04 ms (−45.55%), with 0.19% dispersion across three measurements, GSM8K 94.69% and MMLU 90.14%. On top of that, we made a series of prefill optimizations:

| Change | Mechanism |
|---|---|
| Block-wise indexer KV writes | Writing 524 KB used to trigger a 377 MB reshuffle of the whole pool |
| Page-wise main KV writes | Replaces per-token scatter |
| top-k sort width follows the actual KV length | Previously fixed by max-model-len |
| KV blocks 720 → 192 | The per-layer whole-pool copy cost scales with pool size; the trade-off is that KV capacity drops from 737,280 to 196,608 tokens, so the later production configuration did not keep this change |
| Indexer early exit (from upstream) | When the first chunk's KV length does not exceed top-k, the sort is an identity operation and can be skipped |
| masked-dense query block 32 → 256 | 32 was set for 64-head deployments; with 4 heads per device, 256 uses only 10.9% of VMEM, and results are bit-identical |
| Fused iHC kernel | Hy4's iHC had always taken an fp32 eager fallback on TPU, accounting for 14.4% of device time; rewritten as a Pallas kernel |
| `--xla_tpu_dvfs_p_state=7` | Chip frequency state setting; mechanism not identified |

These changes brought TTFT further down to 419.73 ms (the later part switched to probe measurements on the completions endpoint, which differ from the earlier chat-endpoint method by about 55 ms, so the overall reduction cannot be computed on a single basis). Compared with B200 at 4K input and concurrency 1 at this point: TTFT was 419.73 vs 340.19 ms, still 23% slower (this is the 192-KV-block configuration; the production configuration that keeps 720 blocks is estimated at about 455 ms, not measured); throughput was 147.23 vs 137.45 tok/s, slightly higher, but the difference is only 1.7–2.5 standard deviations. Around the same time we measured the 8K/1K concurrency curve for the first time: single-concurrency throughput was on par, but at high concurrency it was only 23%–42% of B200's, so the focus of the next stage shifted to high concurrency.

## Mixed steps under high concurrency

After migrating to vLLM 0.29, we continued optimizing against the ten levels at concurrency 64 and below from B200's formal benchmark. The starting point: throughput at concurrency 8 was only 53% of B200's, at concurrency 32 only 37%, and TTFT was 3.51× B200's.

Under high concurrency, the main cost is in the "mixed step", a scheduling step that contains several speculative decoding requests and a chunk of prefill at once; at concurrency 32 a mixed step contains 32 speculative decoding requests. Breaking down mixed steps with production profiles, the problems fell into four areas: at 8K input, decode requests have KV lengths of 8000–9000, above the masked-dense default cap of 6144, so the whole mixed step fell back to sparse gather; the speculative verification window (4 tokens per request) was treated as prefill, with each window occupying its own 256-row query block; several pieces of intermediate data were passed through persistent buffers or program inputs, which XLA turned into whole-buffer copies; and KV writeback used per-token scatter.

The single largest gain came from changing one parameter: raising the masked-dense KV length cap from 6144 to 9216. Mixed steps at 8K input no longer fell back to sparse, mixed-step time dropped from about 600 ms to 345 ms, and concurrency-32 throughput rose 40.6%. The later changes are grouped by category below; each was measured on hardware on its own before being merged:

| Category | Change | Concurrency-32 throughput change |
|---|---|---:|
| Attention path | masked-dense KV length cap 6144 → 9216 | +40.6% |
| Speculative verification window | Split the verification window into its own segment in masked-dense (q_len=4) | +21.0% |
| | Give the verification window its own pass in indexer top-k as well | +7.8% |
| Eliminating whole-buffer copies | Replace `jnp.searchsorted` in indexer writes with a single broadcast compare-and-sum | +3.8% |
| | Reuse the bitmap across layers: only 21 of the 78 layers compute top-k, the rest share it | +5.6% |
| | Hand the bitmap off directly along with top-k instead of passing it through a 75 MB persistent buffer; decode steps also use masked-dense | +6.3% |
| Kernel optimization | Remove a 4×4 byte transpose in the kernel caused by a reshape | +6.7% (concurrency 64: +17.0%) |
| | Truncate the prefill attention KV loop at the causal position; one 8000-token prompt goes from 256 to 144 block iterations | +3.9% |
| | KV pages per block in the decode window kernel 3 → 9 | Concurrency-64 decode attention 21.54 → 16.92 ms/step |
| Parallelism | Enable sequence parallelism for mixed steps: all-reduce split into reduce-scatter + all-gather, iHC computes only this rank's 1/16 | +6.1% (mnbt 2048 recipe; +4.1% on the 8192 recipe) |
| Writeback | rope KV writeback becomes one contiguous DMA per page per sequence, with written bytes identical byte for byte | +7.2% |
| | Indexer K writeback also switched to contiguous DMA; scoring and SparseCore top-k interleaved in 2048-token chunks | Concurrency 64: +2.9% |
| Scheduling parameters | mnbt 2048 → 8192, taking in the whole prompt at once; TTFT down 6.7%–27.1%, concurrency-64 throughput −5.5% | — |

During optimization we also found and fixed two correctness problems. The indexer K cache wrote unaligned MTP windows to the wrong position; after the fix, mid-generation divergence in long-context generation went from 3 questions to 0. `swiglu_limit=10` in the Hy4 config was silently dropped by the TPU adaptation layer; after restoring it, the setting took effect as configured, performance was unchanged and accuracy evaluation passed.

<figure>
  <div class="chart" role="img" aria-label="Concurrency-32 throughput rising from 334 to 954 tok/s, versus 916 for B200">
    <div class="row"><div class="lab">Start<small>×0.365</small></div><div class="track"><span class="fill base" style="width:calc((100% - 5.5em) * 0.3507)"></span><span class="val">334</span></div></div>
    <div class="row"><div class="lab">KV cap 9216<small>×0.513</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.4929)"></span><span class="val">470</span></div></div>
    <div class="row"><div class="lab">Separate verify window<small>×0.621</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.5965)"></span><span class="val">569</span></div></div>
    <div class="row"><div class="lab">Indexer opts and fix<small>×0.679</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.6517)"></span><span class="val">622</span></div></div>
    <div class="row"><div class="lab">Cross-layer bitmap reuse<small>×0.752</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.7218)"></span><span class="val">688</span></div></div>
    <div class="row"><div class="lab">Sequence parallelism<small>×0.797</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.7649)"></span><span class="val">730</span></div></div>
    <div class="row"><div class="lab">No byte transpose<small>×0.850</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.8163)"></span><span class="val">779</span></div></div>
    <div class="row"><div class="lab">Direct bitmap handoff<small>×0.905</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.8689)"></span><span class="val">829</span></div></div>
    <div class="row"><div class="lab">Contiguous rope writeback<small>×0.971</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.9316)"></span><span class="val">889</span></div></div>
    <div class="row"><div class="lab">Causal cutoff + 9 pages<small>×1.029</small></div><div class="track"><span class="fill alt" style="width:calc((100% - 5.5em) * 0.9873)"></span><span class="val">942</span></div></div>
    <div class="row"><div class="lab">Contiguous indexer writeback<small>×1.042</small></div><div class="track"><span class="fill" style="width:calc((100% - 5.5em) * 1.0000)"></span><span class="val">954</span></div></div>
    <div class="row"><div class="lab">B200</div><div class="track"><span class="fill base thin" style="width:calc((100% - 5.5em) * 0.9599)"></span><span class="val">916</span></div></div>
    <div class="legend"><span><i style="background:var(--ink-2)"></i>Start / B200</span><span><i style="background:repeating-linear-gradient(135deg,var(--accent-2) 0 4px,transparent 4px 7px);border:1px solid var(--accent-2)"></i>Intermediate</span><span><i style="background:var(--accent)"></i>Final</span></div>
  </div>
  <figcaption>Concurrency-32 output throughput (tok/s), 8000 input / 1000 output; the figure in parentheses is the multiple of B200. Intermediate versions are mostly the mean of 3 measurements within the same serve; the last two rows take one pass from the formal benchmark (their three-pass means are 938.42 and 957.73). The first nine rows use the mnbt 2048 recipe and the last two use mnbt 8192. Between the fourth and fifth rows there were also three versions that only touched cold compile and stability; together with a change in measurement method, this means the 622 → 688 increase in that segment cannot all be attributed to bitmap reuse (its isolated gain is +5.6%).</figcaption>
</figure>

Cumulatively, concurrency-32 throughput went from 334.47 to 957.73 tok/s (three-pass mean), from 37% of B200's to 5% above B200; final results at every concurrency level are in the "Results" section at the start of this post. Several directions were tried and not adopted:

| Direction | Outcome |
|---|---|
| TP8 × DP2 | The extra communication from data parallelism costs 81–90 ms per mixed step; the best configuration was only 2% higher at concurrency 64 (within noise) and 8.8% lower at concurrency 32 |
| Dual micro-batch interleaving + offloading collectives to SparseCore | The offload itself works, but the two batches did not actually interleave; `optimization_barrier` was removed by XLA |
| MTP draft count 3 → 2 at high concurrency | Estimated device time almost unchanged and output about 20% lower; not run on hardware |
| mnbt 16384 (matching B200's default) | HBM OOM at compile time |
| MLA layout fusion | In production it introduced an `as_strided_inverse` costing 185 ms per mixed step, and throughput at the four levels tested dropped 4.3%–16.2%; mechanism not identified |

## Curvature Drive: the tuning workflow behind the second half

The fourth stage of optimization was driven by Curvature Drive, an engine we built. It is an agent engine for TPU inference tuning that is capable of Recursive Self-Improvement (RSI): beyond running the tuning, it improves its own process, evaluation methods and knowledge base at the end of each round, so the next round starts from a better position.

**It integrates TPU domain knowledge.** Curvature Drive has a built-in, continually growing TPU inference knowledge base, currently 280 experience cards. They cover TPU hardware specs (the chip-to-TensorCore mapping, HBM and VMEM capacity, ICI topology and so on), Pallas kernel development techniques, XLA compilation and caching behavior, how to capture and read profiles, methods for breaking device time down by bottleneck type, and known pitfalls of each model on TPU. Each card records the software environment it was validated in; when the environment changes, the card is flagged for re-review and serves only as a prior reference, and cannot by itself rule out a direction.

**It explores.** Before proposing each optimization hypothesis, the engine first runs a frontier scan: it checks upstream code and issues / PRs, official documentation, the source of strong kernels and related papers, to first answer "how have others solved this bottleneck", and it periodically summarizes new developments in the outside community. The experiment queue also has an exploration quota: at least 1 in every 5 experiments is exploratory, dedicated to re-examining directions that experience says are not worthwhile or that were rejected under an older environment.

**Every step has gates and evaluation.** An optimization is split into fixed stages: freeze the goal and the comparison basis, measure the noise across repeated measurements, and attribute time using production profiles. Before going on hardware, each hypothesis gets an upper-bound estimate of its gain and written falsification conditions. Predictions must be registered before the data arrives. A change must first be proven to have actually taken effect before its effect is evaluated. Adopted changes must pass three rounds of accuracy evaluation and a long-context verbatim comparison, and are baked into the image and the deployment recipe. A separate reviewer agent checks the direction and looks for counterexamples at key points, and the author has to respond to each item.

**It evolves itself.** At the end of each round, the engine writes reusable lessons into new experience cards, and conclusions later overturned by evidence are registered as retracted rather than deleted. Changes to the procedure itself are submitted as proposals, merged after human review, and evaluated by replaying a fixed set of historical decision questions to confirm the change makes it stronger rather than weaker. On 12 historical decision questions, the group using Curvature Drive scored 93.3% and the group without it scored 82.5%. After the Hy4 round, 23 new experience cards entered the knowledge base.

On Hy4, this stage covered 14 versions, 38 experiments and 41 optimization hypotheses. A few examples:

- **A hypothesis retracted and reopened**: "raise the masked-dense KV cap" was first rejected on paper on the grounds that "the decode branch would take the mixed batch first". It later turned out that because of `reorder_batch_threshold=1` the speculative windows are not counted as decode, so the premise was wrong. After the rejection was retracted and the hypothesis reopened, it became the largest single gain of this stage (+40.6%).
- **A change stopped by the accuracy gate**: the indexer verification window change gave a 7.8% speedup, but MMLU came in low in two rounds and a rollback was required. It was re-adopted only after alternating restarts with three rounds each (5700 questions) confirmed there was no regression. The long-context verbatim comparison in the same period caught the indexer K cache writing to the wrong position.
- **A version stopped by the formal benchmark**: after the version enabling sequence parallelism was first baked in, the speculative acceptance rate readings in the formal benchmark were abnormal (0.76 at concurrency 1 and 0.565 at concurrency 64, versus about 0.68 normally), and the decoded output was garbage. The cause was a warm start after a change in pod placement, which loaded a cache compiled under a different placement. This version was withdrawn, and the fix was to add the rank-to-device placement to the compile cache key. In a later isolation experiment, however, garbage output showed an acceptance rate of 0.680, which looks completely normal, so acceptance rate is not a reliable correctness metric; since then every formal benchmark has included checks on the output content.

An introduction to Curvature Drive and live progress on its tasks are at <https://rsi.maxwell-x.dev>.

## Accuracy

The final version scores GSM8K 95.00 / 94.77 / 95.07 over three rounds, MMLU 90.04, and 100% on RULER niah_single_1@8192; on 40 long-context questions its output is verbatim identical to the previous version.

The only truly like-for-like accuracy comparison between the two sides is RULER (100% on both). GSM8K is close to B200's 95.60%, but the KV data type, parallelism and answer extraction differ, so this cannot be taken to mean accuracy is on par. Long-chain reasoning tasks such as GPQA and AIME get truncated under the 10240 context cap and can only be evaluated in no_think mode, which is not comparable with B200. Two numeric paths also have lower precision than the CUDA reference implementation and have not been specifically validated: the rope part of the KV (k_pe) is stored as per-tensor fp8, versus bf16 on CUDA; and iHC's hc_fn weights are rounded to bf16, with a relative error of 1.7e-3 measured in isolation.

## Lessons and where they apply

Looking back at the four stages, several lessons carry over to other models:

- **When porting a GPU-only model**, check three things first: whether the quantization format is on the platform allowlist; whether the image contains multiple packages with the same name and whether patches land on the copy imported at runtime; and whether the model bypasses the framework's wrapper layers.
- **When a model on TPU is "one or two orders of magnitude slower"**, the most common cause is not a particular op but that the model never entered compilation and is running in eager mode with op-by-op dispatch. Check the torch.compile message in the serve log first, then the share of host wait time in the profile.
- **masked-dense suits DSA / sparse MLA models deployed with tensor parallelism**, especially when each device gets few attention heads and the upstream default condition will not trigger. Parameters inherited from GPU deployments (enabling conditions, block sizes) often carry implicit assumptions such as the head count, and need to be rechecked when the sharding changes.
- **Mixed-step optimization pays off most for workloads with "long input + speculative decoding + medium-to-high concurrency".** When investigating, rely on op-level data from production profiles: writing a single element to a persistent buffer or passing a large tensor as a program input can each be turned into a whole-buffer copy by XLA, and this kind of overhead often does not show up in isolated tests. The speculative verification window is also easily treated as prefill by the scheduler and needs separate handling.

## 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 the porting log from 2026-08-28 to 2026-10-08, the experiment records of the tuning workflow, TPU-side formal benchmarks #147 and #153–#160, and B200-side formal benchmark #926.
:::
