# Roofline — AI Infra Field Notes by Forrest Xi / Forrest Xi 的 AI Infra 实战笔记 > Everything AI infrastructure: chips, interconnects, compilers, frameworks, training and inference — hands-on notes from hardware to software 关于 AI Infra 的一切:从芯片、互联到编译器、框架与推理训练,软硬件全栈的实测与思考 Author: Forrest Xi, GCP Solution Architect Every post is also published as Markdown at `index.md` (linked below). All posts in one file: https://blog.maxwell-x.dev/llms-full.txt ## 文章(中文) - [FastH3 在 TPU v6e 上的适配与优化:148 GB 的视频生成模型,每美元性能做到 4 卡 B200 的 1.55 倍](https://blog.maxwell-x.dev/fasth3-on-tpu-v6e/index.md): FastH3 是 FastVideo 从 MiniMax H3 蒸馏出的少步数音视频生成模型,权重约 148 GB,而一颗 TPU v6e 只有 32 GB HBM。我们先在 4 颗 v6e 上把它跑通(5 秒视频 72.4 秒),再换到 8 颗 v6e 调到 18.9 秒;按 GCP DWS Calendar 价格,每美元性能是 4 卡 B200 官方最快配置的 1.55 倍。这是我们在 TPU 上优化 MiniMax H3 系列的第一篇,后半部分记录同一套方法用在 15 秒视频和常驻服务上的进展,以及下一步的方向。 (2026-10-28) - [冷编译优化(三):让序列并行档位跨 rank 复用,48 分钟到 17.7 分钟](https://blog.maxwell-x.dev/hy4-cold-compile-sp/index.md): Hy4 为降低首 token 时延启用混合步序列并行、把单步最多处理的 token 数(max_num_batched_tokens,简称 mnbt)提到 8192 之后,冷编译从约 14 分钟回升到 48 分钟。根因是序列并行的切片把 rank 编号写进了计算图:16 个 rank 各自追踪出不同的程序,彼此的编译产物互相拒收,每个 rank 都把 5 个序列并行档位串行编了一遍。把 rank 改为运行时从一次组内 all_to_all 取得后,冷编译降到 18.7 分钟;再把采样侧小图的预编译按 rank 错开、把编译产物的保存挪到后台,降到 17.7 分钟,与不开序列并行的同配方持平。 (2026-10-12) - [冷编译优化(二):TPU 数据并行部署的跨 DP 编译复用](https://blog.maxwell-x.dev/hy4-cold-compile-dp/index.md): 上一篇介绍的跨 rank 回放,只在同一个 DP 编号内查找可复用的编译产物。在纯数据并行的部署里,每个推理引擎各占一个 DP 编号,回放一次都不会发生。我们把回放放宽到跨 DP 查找,并为张量并行与数据并行混合的布局归一化了图指纹中的进程组名。在自维护分支、同一镜像下,Qwen3.5 DP8 从权重加载完成到服务就绪的时间从 741 秒降到 270 秒,TP2×DP4 从 703 秒降到 251 秒。 (2026-10-09) - [Hy4 在 TPU v7 上的权重加载:从 857 秒到 68 秒](https://blog.maxwell-x.dev/hy4-weight-loading/index.md): Hy4-preview 的官方权重有 757.88 GiB。部署在两台 TPU v7 host 上时,直接读原始 checkpoint 需要 857 秒。我们分析了慢的原因:每个 rank 都读全量、vLLM 的预取在大模型上被跳过、多 host 下预取只覆盖一半文件。改用每 rank 预切分的权重缓存,并补齐上游加载器的两处缺口后,加载时间降到 68.5 秒。本文介绍问题分析、方案和收益,以及这种缓存的适用场景和代价。 (2026-10-08) - [从 2 tok/s 到超越 B200:Hy4 在 TPU v7 上的推理性能优化](https://blog.maxwell-x.dev/hy4-tpu-vs-b200/index.md): Hy4-preview 是一个 770B 参数、采用 DSA 稀疏注意力和 MTP 投机解码的 MoE 模型。刚移植到 TPU v7 时,单流解码只有 2 tok/s;最终在 8K 输入 / 1K 输出、并发 1–64 的十档压测中,8 颗 TPU v7 的输出吞吐比 8 卡 B200 高 3%–19%。本文按优化过程中依次遇到的四类瓶颈展开:把模型移植过来并跑对、让模型进入编译、用 masked-dense 加速稀疏注意力的 prefill、优化高并发下的混合步。 (2026-10-08) - [从零开始超越 B200:Hy4 在 TPU v7 上的推理适配与优化](https://blog.maxwell-x.dev/hy4-on-tpu-v7/index.md): Hy4-preview 是一个 770B 参数、采用稀疏注意力和 MTP 投机解码的 MoE 模型。我们把它从 GPU 移植到 TPU v7,在 8K 输入 / 1K 输出、并发 1–64 的压测中,8 颗 TPU v7 的输出吞吐比 8 卡 B200 高 3%–19%;权重加载从 857 秒降到 68 秒,冷编译从 95 分钟降到约 14 分钟。本文概述这三方面的工作,以及支撑整个过程的调优引擎「曲率引擎」。 (2026-10-08) - [用 Gemini 3.8 Flash TTS 做地道粤语配音:一步步实现与避坑](https://blog.maxwell-x.dev/gemini-tts-cantonese/index.md): 给一支 30 秒的技术宣传片配粤语旁白,从「把说明念了出来」「混进普通话」「英文一口美音」「14 分钟念成 14 秒」一路修到能用。本文按步骤给出可直接运行的请求、每一步为什么这样做,以及每个坑的试听对照。 (2026-10-02) - [95 分钟到 14 分钟:Hy4 在 TPU v7 上的冷编译优化](https://blog.maxwell-x.dev/hy4-cold-compile/index.md): TPU 程序按输入形状编译,Hy4 在 TPU v7 上缓存全空时启动一次要 95 分钟。分析发现,主要开销不在编译器,而在送进编译器的计算图:一个随档位线性放大,一个随 rank 数放大。消除这两个放大因素,再让 rank 之间回放编译产物后,冷编译降到约 14 分钟。本文介绍问题分析、方案、收益、上线前的验证,以及这些方法适用的场景。 (2026-10-01) ## Posts (English) - [Porting and Tuning FastH3 on TPU v6e: a 148 GB Video Model at 1.55x the Performance per Dollar of 4x B200](https://blog.maxwell-x.dev/en/fasth3-on-tpu-v6e/index.md): FastH3 is FastVideo's few-step audio-video model distilled from MiniMax H3. Its weights total about 148 GB, while a TPU v6e chip has 32 GB of HBM. We first got it running on 4 v6e chips (72.4 s per 5-second clip), then moved to 8 chips and brought it down to 18.9 s. At GCP DWS Calendar prices that is 1.55x the performance per dollar of FastVideo's fastest official 4x B200 setup. This is our first post on optimizing the MiniMax H3 family on TPU; the second half covers how the same approach carried over to 15-second clips and a resident service, and where we go next. (2026-10-28) - [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/index.md): After Hy4 turned on mixed-step sequence parallelism and raised the per-step token budget (max_num_batched_tokens, mnbt) to 8192 to cut time to first token, its cold compile climbed from about 14 minutes back to 48. The root cause: the sequence-parallel slice wrote the rank index into the traced graph. Each of the 16 ranks traced a different program, every rank rejected the others' compiled artifacts, and each rank compiled all five sequence-parallel buckets one after another. Reading the rank at run time from one in-group all_to_all brought cold compile to 18.7 minutes; staggering the sampler-side precompile across ranks and moving artifact saving to a background thread brought it to 17.7, on par with the same recipe without sequence parallelism. (2026-10-12) - [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/index.md): 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. (2026-10-09) - [Hy4 Weight Loading on TPU v7: From 857 Seconds to 68](https://blog.maxwell-x.dev/en/hy4-weight-loading/index.md): The official Hy4-preview weights are 757.88 GiB. Deployed across two TPU v7 hosts, loading straight from the original checkpoint took 857 seconds. We analyzed why it was slow: every rank reads the full checkpoint, vLLM skips prefetch for large models, and with multiple hosts prefetch covers only half the files. After switching to a per-rank pre-sharded weight cache and closing two gaps in the upstream loader, load time dropped to 68.5 seconds. This post covers the analysis, the approach and the gains, as well as where this kind of cache fits and what it costs. (2026-10-08) - [From 2 tok/s to Beating B200: Optimizing Hy4 Inference on TPU v7](https://blog.maxwell-x.dev/en/hy4-tpu-vs-b200/index.md): 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. (2026-10-08) - [Beating B200 from Scratch: Porting and Optimizing Hy4 Inference on TPU v7](https://blog.maxwell-x.dev/en/hy4-on-tpu-v7/index.md): Hy4-preview is a 770B-parameter MoE model with sparse attention and MTP speculative decoding. We ported it from GPU to TPU v7. In benchmarks with 8K input / 1K output at concurrency 1–64, 8 TPU v7 chips delivered 3%–19% higher output throughput than 8 B200 GPUs. Weight loading dropped from 857 seconds to 68, and cold compile from 95 minutes to about 14. This post summarizes the work on all three fronts, and the tuning engine behind it, Curvature Drive. (2026-10-08) - [Natural Cantonese Voiceover with Gemini 3.8 Flash TTS: Step by Step, and the Pitfalls](https://blog.maxwell-x.dev/en/gemini-tts-cantonese/index.md): We voiced a 30-second tech promo in Cantonese and fixed it one problem at a time: the model read the directions aloud, slipped into Mandarin, spoke its English with an American accent, and said "14 seconds" instead of "14 minutes". This post gives runnable requests for each step, why each step is there, and before/after audio for every pitfall. (2026-10-02) - [95 Minutes to 14: Cold Compile Optimization for Hy4 on TPU v7](https://blog.maxwell-x.dev/en/hy4-cold-compile/index.md): TPU programs are compiled per input shape, and with an empty cache Hy4 took 95 minutes to start on TPU v7. Our analysis found that most of the cost was not in the compiler but in the computation graphs fed to it: one grew linearly with the bucket, the other with the number of ranks. After removing both multipliers and letting ranks replay each other's compiled artifacts, cold compile dropped to about 14 minutes. This post covers the analysis, the changes, the gains, the validation before production, and where these methods apply. (2026-10-01)