<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P]]></title><description><![CDATA[<p dir="auto">前段时间的 H3 视频比赛，我折腾了 AMD 同代的异构 TP，也折腾了 NV 不同代的异构 TP。当时就想，如果能实现 A+N 的 TP 就好玩了，于是有了这个帖子。</p>
<p dir="auto">为了让 A+N 的 TP 跑起来，我折腾了个跨平台 CCL，打算起名 FCCL——Fast (Fcys) Collective Communications Library。之所以发在硬件区，是因为跨平台跨进程的集合通信库不止能用来生成视频，后面能发挥的空间很大，比如 LLM。</p>
<p dir="auto">当然也不限于 AMD 和 NV 的卡，理论上所有走 PCIe 的 GPU 或加速设备都能接。Intel 那边我也测了：目前 Intel 自家的 oneCCL 通信有 bug，生成的视频满屏彩噪；改用 FCCL 之后能正常出片，但速度偏慢，这个得慢慢调。</p>
<hr />
<p dir="auto">原因大家都知道——NVIDIA 的通信库只认自家卡，AMD 的也只认自家卡。两套库互不相通，跨厂商的 TP 从第一步就起不来。</p>
<p dir="auto">所以我写了一套走主机内存的通信，把这件事跑通了。</p>
<p dir="auto">原理图：<br />
<img src="https://upload.lcz.me/uploads/5ecd07f3-3764-4104-bb8e-b6eac3555cd3.png" alt="file.png" class="img-markdown  img-fluid" /></p>
<hr />
<p dir="auto">实际应用（H3）：<br />
<img src="https://upload.lcz.me/uploads/500d384e-8d1e-4aee-9450-2fdc195710d2.png" alt="byp_294_768p_00001_九宫格.png" class="img-markdown  img-fluid" /></p>
<hr />
<p dir="auto">所有数字本机实测，代码在本机跑过。平台：W7900（ROCm 10.0）+ RTX PRO 5000（CUDA 13.0），两卡之间 PCIe 4.0 x16。</p>
<hr />
<h2>一、一句话结论</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>维度</th>
<th>结论</th>
</tr>
</thead>
<tbody>
<tr>
<td>能不能跑</td>
<td>能。1 GiB 收发做到同厂商 P2P 的 91%</td>
</tr>
<tr>
<td>比厂商库的主机路径</td>
<td>快 19%</td>
</tr>
<tr>
<td>代价</td>
<td>4 MB 以下的小消息明显吃亏；对主存带宽要求高</td>
</tr>
<tr>
<td>最大价值</td>
<td>不用换卡就能组 TP，显存能合起来用</td>
</tr>
<tr>
<td>什么时候别用</td>
<td>两张卡算力差太远，不如直接用快的那张</td>
</tr>
</tbody>
</table>
<p dir="auto">后面几节是把这张表拆开讲。</p>
<hr />
<h2>二、先看主结果：1 GiB 收发</h2>
<p dir="auto">同一台机器，三种链路同一口径：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>链路</th>
<th>耗时</th>
<th>busbw</th>
<th>相对</th>
</tr>
</thead>
<tbody>
<tr>
<td>双 A 卡走 RCCL P2P</td>
<td>46.14 ms</td>
<td>46.54 GB/s</td>
<td>快 9.5%</td>
</tr>
<tr>
<td><strong>A + N 走主机内存（我这套）</strong></td>
<td><strong>50.49 ms</strong></td>
<td><strong>42.53 GB/s</strong></td>
<td>基准</td>
</tr>
<tr>
<td>两张 N 卡跨代走 NCCL</td>
<td>60.26 ms</td>
<td>35.64 GB/s</td>
<td>慢 19%</td>
</tr>
</tbody>
</table>
<p dir="auto">能到 P2P 的 91%，比我预期好，本来以为 80% 就不错了。</p>
<p dir="auto">毕竟这条路是绕的：数据要从显存搬到主机内存，再让另一张卡从主机内存搬回去。相当于绕了一圈，还能做到 P2P 的九成，说明 PCIe 双向并发本身就不是瓶颈。</p>
<hr />
<h2>三、但小消息很难看</h2>
<p dir="auto">同一批测试，按数据大小拆开：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>数据大小</th>
<th>RCCL</th>
<th>我这套</th>
<th>NCCL</th>
</tr>
</thead>
<tbody>
<tr>
<td>4 KB</td>
<td>0.20</td>
<td>0.06</td>
<td>0.39</td>
</tr>
<tr>
<td>1 MB</td>
<td>22.41</td>
<td>9.92</td>
<td>20.74</td>
</tr>
<tr>
<td>16 MB</td>
<td>44.22</td>
<td>24.71</td>
<td>31.81</td>
</tr>
<tr>
<td>64 MB</td>
<td>45.99</td>
<td>36.69</td>
<td>33.06</td>
</tr>
<tr>
<td>256 MB</td>
<td>46.43</td>
<td>41.36</td>
<td>34.78</td>
</tr>
<tr>
<td>1 GiB</td>
<td>46.54</td>
<td>42.53</td>
<td>35.64</td>
</tr>
</tbody>
</table>
<p dir="auto">4 KB 的时候我这套只有 0.06 GB/s，是三种里最差的。原因很简单：每块数据都要走一遍「写标志位 → 对端轮询 → 读 → 回执」的握手，数据越小，握手占比越大。</p>
<p dir="auto">32 MB 之后才开始反超 NCCL。所以这东西的使用前提很明确——<strong>大块数据</strong>。实际训练推理都是几百 MB 级别的层输出，正好在甜点区。</p>
<p dir="auto">RCCL 二十几 MB 就顶在 46.5 不动了，那是 P2P 的物理上限。NCCL 走主机内存，16 MB 之后也涨不动——它撞的是同一个墙，只是没有人帮它做双向重叠。</p>
<hr />
<h2>四、一个反直觉的结果</h2>
<p dir="auto">这套东西在我这台机器上能拿到 1.67 倍加速（双工 vs 单块）。同一份代码搬到另一台机器（双 R9700，PCIe 5.0），耗时还是 50.5 ms 左右，但加速比掉到 1.09 倍。</p>
<p dir="auto">第一反应是代码在 Gen5 上有问题，查了半天才发现不是。</p>
<p dir="auto">这类方案的数据要过一遍主机内存，1 GiB 需要大约 85 GB/s 的同时读写能力。那台机器只插了 4 条内存，实测同时读写只有 72 GB/s——瓶颈从 PCIe 跑到内存去了。</p>
<p dir="auto">把关系理出来是这样：<strong>内存需求 ≈ 4 × PCIe 单向上限</strong>。</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>PCIe</th>
<th>单向上限</th>
<th>内存需求</th>
<th>四条 DDR4/DDR5 够不够</th>
</tr>
</thead>
<tbody>
<tr>
<td>3.0 x16</td>
<td>~13 GB/s</td>
<td>~52 GB/s</td>
<td>刚好</td>
</tr>
<tr>
<td>4.0 x16</td>
<td>~26 GB/s</td>
<td>~104 GB/s</td>
<td>不够，要 8 条</td>
</tr>
<tr>
<td>5.0 x16</td>
<td>~44 GB/s</td>
<td>~177 GB/s</td>
<td>差 2 倍多</td>
</tr>
</tbody>
</table>
<p dir="auto">所以有个挺反直觉的结论：<strong>老平台反而省心，新平台容易在这翻车</strong>。手里是 PCIe 3.0 主板的朋友不用担心内存，插四条 DDR4 就够跑满双工。</p>
<hr />
<h2>五、这套东西的价值到底在哪</h2>
<p dir="auto">说实话，不是速度。</p>
<p dir="auto">我拿它跑 ComfyUI 的 MiniMax-H3 视频生成，1344×768、124 帧、20 步，两张卡一起算能跑完（双工 961 秒，单块 1035 秒）。但跑 20 步这件事本身，PRO5000 单卡也能干，只是慢一点。</p>
<p dir="auto">要想实现速度上有客观的提升，要求两张卡原始算力差距不大，当然LLM得实际情况不能等同于H3的视频生成，AMD的LLM性能差距没有那么明显。</p>
<p dir="auto">真正跑不动的是更大的档位。单卡跑 362 帧 1088p 的时候，48G 显存直接贴顶，VAE 解码就 OOM；两张卡切开，每卡只吃 30G 左右，还留十几 G 余量。</p>
<p dir="auto"><strong>所以它的价值是把显存从 48G 变成 96G（实际约 94.6G），速度是附带的。</strong></p>
<p dir="auto">这里要提醒一句：TP 不会让显存翻倍。模型权重能切，但中间激活、VAE、文本编码器这些切不了，所以收益是「从放不下到放得下」，不是「空间翻倍」。</p>
<hr />
<h2>六、什么时候别用它</h2>
<p dir="auto">这条比性能数字有用。</p>
<p dir="auto">我那个 W7900 + PRO5000 的组合，主要是证明这条路走得通，不是证明它快。实际跑 20 步：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>对比</th>
<th>结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>vs 双 W7900 TP2</td>
<td>2501 s vs 3027 s，快 17%</td>
</tr>
<tr>
<td>vs PRO5000 单卡</td>
<td>2501 s vs 约 1250 s，慢一倍</td>
</tr>
</tbody>
</table>
<p dir="auto">慢的原因不在通信——每步通信只占 7% 的时间——在 AMD 卡算力太弱，把整体拖住了。</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>两卡算力差距</th>
<th>实测</th>
</tr>
</thead>
<tbody>
<tr>
<td>相近（N+N 跨代）</td>
<td>1.27×</td>
</tr>
<tr>
<td>差 5.7 倍（W7900 vs PRO5000）</td>
<td>0.50×，比单卡还慢</td>
</tr>
</tbody>
</table>
<p dir="auto">判断标准很简单：<strong>两张卡跑同一个任务，时间差不超过 1.5 倍，才值得试</strong>。差一倍以上，直接用快的那张，别折腾。</p>
<p dir="auto">不同应用选卡的方向要根据实际情况来推导。</p>
<hr />
<h2>七、稳定性</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>项</th>
<th>结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>1 GiB 连跑 1500 轮</td>
<td>p99 50.61 ms，抖动 &lt;0.2%</td>
</tr>
<tr>
<td>跨尺寸来回切</td>
<td>720 次，全部正常</td>
</tr>
<tr>
<td>正确性检查</td>
<td>104 项全过</td>
</tr>
</tbody>
</table>
<p dir="auto">顺带说个教训：我早期有个版本 104 项 bench 全绿，但实际跑 H3 单步就崩——因为bench 每轮都填同一个均匀值、张量还是连续的，把「跨 stream 读到半成品」和「非连续张量丢结果」两个 bug 同时掩盖了。所以判据不能只看 bench，得看端到端结果。</p>
<hr />
<p dir="auto">数据就这些，后面测了新卡再往上补。</p>
]]></description><link>https://lcz.me/topic/3250</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 03:38:29 GMT</lastBuildDate><atom:link href="https://lcz.me/topic/3250.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Nov 2026 13:17:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Wed, 25 Nov 2026 03:08:22 GMT]]></title><description><![CDATA[<p dir="auto">FCCL 1.3.0：4 KB 小消息从 63 压到 39 µs，跟同机 RCCL P2P 打平了</p>
<p dir="auto">折腾了两天，1.3.0 发出来了。先把结论甩前面：<strong>4 KB <code>all_reduce</code> 从 63 µs 压到 39 µs，同机 RCCL P2P 是 40 µs，打平了。</strong> 1.2.4 的时候这块还落后 3.4 倍，一直是我心里的一根刺。</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/ca62badf-2fd1-4810-a37e-01fb54cb8293.png" alt="01-4k-vs-rccl.png" class="img-markdown  img-fluid" /></p>
<p dir="auto">改的东西其实很少，一句话能说完：<strong>以前每轮要 CPU 阻塞着等两次 DMA 落地，现在 ready/ack 两面旗改成 GPU 在流内自己写、自己等（<code>cuStreamWriteValue32</code> / <code>cuStreamWaitValue32</code>，HIP 那边对应 <code>hipStreamWriteValue32/WaitValue32</code>），CPU 只在最后自旋一下。</strong></p>
<p dir="auto">至于为什么是 16 KB 以内才开快路——测出来的。20 KB 起 HIP 会换到另一条拷贝引擎，快路反而亏 36%，所以阈值定死在 16 KB，<code>FCCL_GPUSIG_MAX_KB=0</code> 可以关掉。</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/537cfd52-c5c4-4288-b179-c805cfe1312c.png" alt="02-latency-size.png" class="img-markdown  img-fluid" /></p>
<h2>为什么我这么在意 4 KB</h2>
<p dir="auto">因为<strong>视频生成每层都在等它</strong>。ComfyUI 跑 MiniMax-H3 做 TP=2，每个采样步里每层都有一次 <code>all_reduce</code>，全是这种几 KB 的高频小消息，通信大概占整个采样步的 7%。小消息慢，就等于整个采样步在等同步。</p>
<p dir="auto">这是我当初写 FCCL 的原因：机箱里躺着两张不同品牌、不同型号的卡，各自跑都挺好，想合起来跑一个模型，发现根本没有库能用——NCCL 只认 CUDA，RCCL 只认 ROCm，混插机器上连第一轮集合通信都起不来。</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/8ea464cf-81b4-4bc0-9a67-8846e4e7a3c5.png" alt="03-1gib-threeway.png" class="img-markdown  img-fluid" /></p>
<p dir="auto">1 GiB 大消息本来就还好：42.5 GB/s，同厂商 P2P 的 94%，比自己的单块路径快 1.67×。真正的谷底在 1–16 MB，只有 RCCL 的 57–60%——那是路径差异，RCCL 走 GPU 间 P2P 直连、我这边要过主机内存两遍，物理上补不回来，我也不打算补。</p>
<h2>顺便说两件我觉得最值的事</h2>
<p dir="auto"><strong>一、不等分是真有用。</strong> 两张卡算力差 1.68×，五五分 28:28 就是让快卡每步空等慢卡。按反比分 36:20 之后，端到端从 814 s 掉到 563 s，比最快的那张单卡还快 45%。但注意——卡差到 3.8× 的时候，48:8 也只能追平单卡（547 s），再往偏反而更慢。<strong>差距超过 3 倍，别折腾 TP，直接用快的那张。</strong></p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/08f78619-3f53-4a89-bab8-7c6dc72adc36.png" alt="04-tp2-uneven-a.png" class="img-markdown  img-fluid" /><br />
<img src="https://upload.lcz.me/uploads/4b15118a-0deb-47c0-90e7-00415d8086b3.png" alt="05-tp2-uneven-b.png" class="img-markdown  img-fluid" /></p>
<p dir="auto"><strong>二、PD 分离是跨品牌少数"两个厂家都做不到"的事。</strong> N 卡有 FP8 但显存小，A 卡显存大但没有 FP8 tensor core。让 N 卡跑 prefill（5451 tok/s，比 A 卡 W4A16 快 58%）、两张 A 卡扛 decode（252K KV 池），单品牌凑不出这个组合。</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/9fc34e06-e2ff-43e2-9392-b3aa0af92fa1.png" alt="06-pd-prefill.png" class="img-markdown  img-fluid" /></p>
<p dir="auto">代价也很清楚：KV 得过主机内存。8K 请求搬 788 MB 用 41 ms，占 TTFT 的 2.7%。<strong>这是代价，不是卖点</strong></p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/7df68a36-88e5-4c94-b7a1-8c2e4fd61c5f.png" alt="07-pd-ttft.png" class="img-markdown  img-fluid" /></p>
<h2>一个大家容易担心的门槛</h2>
<p dir="auto">数据要过主机内存，所以"跑满 PCIe"大概需要 4 倍的单卡单向带宽（Gen4 x16 约 104 GB/s，Gen5 约 177–214）。</p>
<p dir="auto">但<strong>这只是理想条件，不是能不能用的门槛</strong>。带宽不够的时候不会跑不起来，只是吞吐按比例掉。实测那台只有 72 GB/s 的 R9700 机器（需求 ~177），双工还有 1.09×，出片完全够用。</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/203078a6-67eb-49de-a114-d8e61ef71fad.png" alt="08-host-mem.png" class="img-markdown  img-fluid" /></p>
<p dir="auto">真实负载里通信只占一小段：视频生成一个采样步 8.4 s、通信约 7%；PD 的 KV 传输占 TTFT 2.7%。所以带宽这事，对个人和中小规模的出片/推理，基本不是卡点。</p>
<h2>装法</h2>
<pre><code>pip install "git+https://github.com/Fcys11/fccl"
pip install numpy     # venv 里没有的话：FCCL 不声明依赖，pip 不会自动带
</code></pre>
<p dir="auto">纯 Python，不编译、不要 root、不要 NVLink 桥、不要 RDMA 网卡。两个进程各锁一张卡就行。</p>
<h2>最后说清楚边界，省得白折腾</h2>
<ul>
<li><strong>正在规划买卡的，别用这个。</strong> 买两张同型号、上 NCCL/RCCL，省心得多。FCCL 是给"卡已经在手里"的人用的。</li>
<li><strong>有 NVLink 或 RDMA 的，别用这个。</strong> 设备间直连一定更快。</li>
<li><strong>两张卡算力差 3 倍以上的，别用这个。</strong> 最优切分也只是追平单卡。</li>
<li>反过来：手里有杂卡、不想再买、想要"一个模型吃两张卡"而不是各跑各的——那它挺合适的。</li>
</ul>
]]></description><link>https://lcz.me/post/35826</link><guid isPermaLink="true">https://lcz.me/post/35826</guid><dc:creator><![CDATA[fcys]]></dc:creator><pubDate>Wed, 25 Nov 2026 03:08:22 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 06:02:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fcys" aria-label="Profile: fcys">@<bdi>fcys</bdi></a>  超过四卡后可能还得额外处理 NUMA 这类问题，但说实话，很多时候这些老卡的计算能力、功耗，以及并行时的通信开销，和它们实际带来的性能提升并不成正比。 不过我倒觉得，对老卡来说或许有个思路真能落地，AMD 有一项叫 XIO 的技术，已经能让 GPU 主动发起 NVMe I/O，也有用 SDMA 做卡间搬运的实现，目前这部分是开源的，用它让一块显卡去访问另一块老卡的显存，老卡也不用调度多少CU，功耗开销会非常低。这样一来，但却能拥有廉价、高速的显存扩展？</p>
]]></description><link>https://lcz.me/post/35170</link><guid isPermaLink="true">https://lcz.me/post/35170</guid><dc:creator><![CDATA[Bunsei]]></dc:creator><pubDate>Sun, 22 Nov 2026 06:02:18 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 05:43:24 GMT]]></title><description><![CDATA[<p dir="auto">牛逼，这个想法很好，抓紧研究，就指望你了，到时候给你开个专业，定制网页，你也可以自己定制，<img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/1f602.png?v=2bf455356c3" class="not-responsive emoji emoji-android emoji--joy" style="height:1.4em;width:auto;vertical-align:middle" title="😂" alt="😂" /></p>
]]></description><link>https://lcz.me/post/35166</link><guid isPermaLink="true">https://lcz.me/post/35166</guid><dc:creator><![CDATA[terry]]></dc:creator><pubDate>Sun, 22 Nov 2026 05:43:24 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 05:33:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry" aria-label="Profile: terry">@<bdi>terry</bdi></a> FCCL就像是一个最高的管理者，理论上可以按用户需求去分别指派给不同的算力单位工作项目，分配任务可以根据算力单位的能力进行切分。</p>
<p dir="auto">我现在在用pro5000+双7900跑QWEN3.8 27B，pro5000负责prefill的部分，双7900负责decode。目前prefill的速度刚才看数字到8000了（这个暂时还没复测不一定准），在优化decode的部分。</p>
<p dir="auto">我有个不成熟的想法，那些高显存高带宽的洋垃圾，是不是可以扬长避短了，比如说v100</p>
]]></description><link>https://lcz.me/post/35165</link><guid isPermaLink="true">https://lcz.me/post/35165</guid><dc:creator><![CDATA[fcys]]></dc:creator><pubDate>Sun, 22 Nov 2026 05:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 05:21:58 GMT]]></title><description><![CDATA[<p dir="auto">这个帖子应该置顶1个月，继续更新。</p>
]]></description><link>https://lcz.me/post/35160</link><guid isPermaLink="true">https://lcz.me/post/35160</guid><dc:creator><![CDATA[terry]]></dc:creator><pubDate>Sun, 22 Nov 2026 05:21:58 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 05:20:08 GMT]]></title><description><![CDATA[<p dir="auto"><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2b50.png?v=2bf455356c3" class="not-responsive emoji emoji-android emoji--star" style="height:1.4em;width:auto;vertical-align:middle" title="⭐" alt="⭐" /> 版主审定：本帖设为<strong>精华</strong>，作者 <strong>+6 积分</strong>奖励，希望再接再厉！</p>
<blockquote>
<p dir="auto">奖励凭证：精华 +6 分 · 编号 f3250-1915-1</p>
</blockquote>
]]></description><link>https://lcz.me/post/35158</link><guid isPermaLink="true">https://lcz.me/post/35158</guid><dc:creator><![CDATA[Xiaote]]></dc:creator><pubDate>Sun, 22 Nov 2026 05:20:08 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sun, 22 Nov 2026 00:55:50 GMT]]></title><description><![CDATA[<p dir="auto">R9700+B70双卡TP出视频成功，好玩</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/a27a5a6b-b7e4-4154-9540-fbb989653a92.jpg" alt="九宫格_起时间均分_带时间码.jpg" class="img-markdown  img-fluid" /></p>
]]></description><link>https://lcz.me/post/35133</link><guid isPermaLink="true">https://lcz.me/post/35133</guid><dc:creator><![CDATA[fcys]]></dc:creator><pubDate>Sun, 22 Nov 2026 00:55:50 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sat, 21 Nov 2026 13:39:24 GMT]]></title><description><![CDATA[<p dir="auto"><img src="https://upload.lcz.me/uploads/9c74deb6-7be0-4ffe-ad26-1a56d1c8f839.png" alt="7c57b29a-4d23-4eea-8ed5-3b68259b9b7b.png" class="img-markdown  img-fluid" /></p>
<p dir="auto">要收益最大化，一定要用速度差不多的两张卡，这里能看出来5000一直在悠闲的等比生产队的驴都累的7900</p>
<p dir="auto">LLM的话应该会好很多</p>
<p dir="auto"><a href="https://github.com/Fcys11/fccl" rel="nofollow ugc">https://github.com/Fcys11/fccl</a></p>
<p dir="auto">项目比较复杂，特意建了个仓库，代码，坑，还有使用说明，版本迭代说明自取吧，希望大家都能复现。</p>
]]></description><link>https://lcz.me/post/35080</link><guid isPermaLink="true">https://lcz.me/post/35080</guid><dc:creator><![CDATA[fcys]]></dc:creator><pubDate>Sat, 21 Nov 2026 13:39:24 GMT</pubDate></item><item><title><![CDATA[Reply to 【跨品牌 TP · 分享贴】为了验证跨品牌 TP，我写了个FCCL，还真跑通了！10楼更新1.3.0,4k延迟追平P2P on Sat, 28 Nov 2026 07:18:04 GMT]]></title><description><![CDATA[<p dir="auto">二，主结果：1 GiB 收发</p>
<p dir="auto">同一台机器，三种链路同一口径：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>链路</th>
<th style="text-align:right">耗时</th>
<th style="text-align:right">busbw</th>
<th style="text-align:right">相对</th>
</tr>
</thead>
<tbody>
<tr>
<td>双 A 卡走 RCCL P2P</td>
<td style="text-align:right">46.14 ms</td>
<td style="text-align:right">46.54 GB/s</td>
<td style="text-align:right">快 9.5%</td>
</tr>
<tr>
<td><strong>A + N 走主机内存（我这套）</strong></td>
<td style="text-align:right"><strong>50.49 ms</strong></td>
<td style="text-align:right"><strong>42.53 GB/s</strong></td>
<td style="text-align:right">基准</td>
</tr>
<tr>
<td>两张 N 卡跨代走 NCCL</td>
<td style="text-align:right">60.26 ms</td>
<td style="text-align:right">35.64 GB/s</td>
<td style="text-align:right">慢 19%</td>
</tr>
</tbody>
</table>
<p dir="auto">能到 P2P 的 91%，比我预期好，本来以为 80% 就不错了。</p>
<p dir="auto">毕竟这条路是绕的：数据从显存搬到主机内存，再让另一张卡搬回去。绕一圈还能做到 P2P 的九成，<br />
说明 PCIe 双向并发本身不是瓶颈。</p>
<p dir="auto">最新版本（1.2.5）复测是 50.480 ms / 42.54 GB/s，跟 1.2.4 差 0.02%，等于没动。</p>
<hr />
<h2>三、但小消息很难看</h2>
<p dir="auto">同一批测试按大小拆开：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>数据大小</th>
<th style="text-align:right">RCCL</th>
<th style="text-align:right">我这套</th>
<th style="text-align:right">NCCL</th>
</tr>
</thead>
<tbody>
<tr>
<td>4 KB</td>
<td style="text-align:right">0.20</td>
<td style="text-align:right">0.06</td>
<td style="text-align:right">0.39</td>
</tr>
<tr>
<td>1 MB</td>
<td style="text-align:right">22.41</td>
<td style="text-align:right">9.92</td>
<td style="text-align:right">20.74</td>
</tr>
<tr>
<td>16 MB</td>
<td style="text-align:right">44.22</td>
<td style="text-align:right">24.71</td>
<td style="text-align:right">31.81</td>
</tr>
<tr>
<td>64 MB</td>
<td style="text-align:right">45.99</td>
<td style="text-align:right">36.69</td>
<td style="text-align:right">33.06</td>
</tr>
<tr>
<td>256 MB</td>
<td style="text-align:right">46.43</td>
<td style="text-align:right">41.36</td>
<td style="text-align:right">34.78</td>
</tr>
<tr>
<td>1 GiB</td>
<td style="text-align:right">46.54</td>
<td style="text-align:right">42.53</td>
<td style="text-align:right">35.64</td>
</tr>
</tbody>
</table>
<p dir="auto">4 KB 的时候只有 0.06 GB/s，三种里最差。原因很简单：每块数据都要走一遍<br />
「写标志位 → 对端轮询 → 读 → 回执」，数据越小握手占比越大。</p>
<p dir="auto">32 MB 之后才开始反超 NCCL。所以使用前提很明确——<strong>大块数据</strong>。</p>
<hr />
<h2>四、一个反直觉的结果：内存才是墙</h2>
<p dir="auto">这套东西在我这台机器上能拿到 1.67 倍加速（双工 vs 单块）。同一份代码搬到另一台机器<br />
（双 R9700，PCIe 5.0），耗时还是 50.5 ms 左右，但加速比掉到 1.09 倍。</p>
<p dir="auto">第一反应是代码在 Gen5 上有问题，查了半天发现不是。</p>
<p dir="auto">这类方案的数据要过一遍主机内存，1 GiB 需要大约 85 GB/s 的同时读写能力。那台机器只插了<br />
4 条内存，实测同时读写只有 72 GB/s——瓶颈从 PCIe 跑到内存去了。</p>
<p dir="auto">把关系理出来是这样：<strong>内存需求 ≈ 4 × PCIe 单向上限</strong>。</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>PCIe</th>
<th style="text-align:right">单向上限</th>
<th style="text-align:right">内存需求</th>
<th>四条 DDR4/DDR5 够不够</th>
</tr>
</thead>
<tbody>
<tr>
<td>3.0 x16</td>
<td style="text-align:right">~13 GB/s</td>
<td style="text-align:right">~52 GB/s</td>
<td>刚好</td>
</tr>
<tr>
<td>4.0 x16</td>
<td style="text-align:right">~26 GB/s</td>
<td style="text-align:right">~104 GB/s</td>
<td>不够，要 8 条</td>
</tr>
<tr>
<td>5.0 x16</td>
<td style="text-align:right">~44 GB/s</td>
<td style="text-align:right">~177 GB/s</td>
<td>差 2 倍多</td>
</tr>
</tbody>
</table>
<p dir="auto">所以有个挺反直觉的结论：<strong>老平台反而省心，新平台容易在这翻车</strong>。<br />
手里是 PCIe 3.0 主板的朋友不用担心内存，插四条 DDR4 就够跑满双工。</p>
<hr />
<h2>五、重点来了：光切两半没用，要按算力反比切</h2>
<p dir="auto">这一段是我折腾最久、也是唯一真正把「跨厂商 TP」从「能跑」变成「有用」的东西。</p>
<h3>5.1 默认的 28:28 是错的</h3>
<p dir="auto">TP 的常规做法是把模型对半切，两张卡各算一半。这假设了一个前提：<strong>两张卡一样快</strong>。</p>
<p dir="auto">我把通信关掉、只留计算各跑一遍（两张卡各跑半宽模型）：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>单端（只算不通信）</th>
<th style="text-align:right">每步</th>
</tr>
</thead>
<tbody>
<tr>
<td>R9700（AMD）</td>
<td style="text-align:right">51.72 s</td>
</tr>
<tr>
<td>B70（Intel）</td>
<td style="text-align:right">87.06 s</td>
</tr>
</tbody>
</table>
<p dir="auto">B70 慢 68%。对半分的时候，R9700 每步空等约 35 秒——<strong>四成的算力在睡觉</strong>。</p>
<p dir="auto">按算力反比，R9700 应该干 62.7% 的活。56 个 attention head 里最接近的是 <strong>36:20</strong>。</p>
<p dir="auto">下面这台机器的是第三台机器上的实测（R9700 + Intel B70，1344×768 / 294 帧 / 6 步）：</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/89aeee91-ec44-43c4-bbff-41da9865cc2b.png" alt="chart-split-A.png" class="img-markdown  img-fluid" /></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>配置</th>
<th style="text-align:right">端到端</th>
<th style="text-align:right">每步</th>
<th style="text-align:right">相对最快单卡</th>
</tr>
</thead>
<tbody>
<tr>
<td>R9700 单卡</td>
<td style="text-align:right">814 s</td>
<td style="text-align:right">100.9 s</td>
<td style="text-align:right">1.00×</td>
</tr>
<tr>
<td>TP2 对半 28:28</td>
<td style="text-align:right">676 s</td>
<td style="text-align:right">92.4 s</td>
<td style="text-align:right">1.20×</td>
</tr>
<tr>
<td><strong>TP2 反比 36:20</strong></td>
<td style="text-align:right"><strong>563 s</strong></td>
<td style="text-align:right"><strong>71.0 s</strong></td>
<td style="text-align:right"><strong>1.45×</strong></td>
</tr>
</tbody>
</table>
<p dir="auto">切成 36:20 之后两端每步 72.06 / 72.18 秒，几乎同时收工——算得对，实测也对得上。<br />
两端 PSNR 45.57 dB。</p>
<p dir="auto"><strong>这里要注意的不是「比对称切分快 22%」，而是「比最快的单卡快 45%」。</strong><br />
在这台机器上，两张卡拼起来是真赚的。</p>
<h3>5.2 但换一台机器，同样的招数就不灵了</h3>
<p dir="auto">我自己的机器是 W7900 + RTX PRO 5000，两张卡算力差了 3.8 倍（W7900 慢得多）。<br />
照样扫了一遍切分：</p>
<p dir="auto"><img src="https://upload.lcz.me/uploads/f9238e1a-28de-4734-b547-2544444e7707.png" alt="图2-等分vs不等分-W7900+PRO5000.png" class="img-markdown  img-fluid" /></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>配置</th>
<th style="text-align:right">端到端</th>
<th style="text-align:right">每步</th>
</tr>
</thead>
<tbody>
<tr>
<td>TP2 对半 28:28</td>
<td style="text-align:right">1053 s</td>
<td style="text-align:right">125.2 s</td>
</tr>
<tr>
<td><strong>TP2 反比 48:8</strong></td>
<td style="text-align:right"><strong>547 s</strong></td>
<td style="text-align:right"><strong>52.3 s</strong></td>
</tr>
<tr>
<td>52:4（再往偏）</td>
<td style="text-align:right">—</td>
<td style="text-align:right">56.3 s ↑</td>
</tr>
</tbody>
</table>
<p dir="auto">不等分比对半快了 48%，很漂亮——<strong>但它只是追平了 PRO 5000 单卡一个人跑</strong>。</p>
<p dir="auto">再往偏（52:4）反而变慢了：慢卡不再是瓶颈之后，快卡自己成瓶颈了。因为每层都有两次<br />
all_reduce，慢卡哪怕只算 8 个头也要参与每一次同步，它的固定开销成了地板。</p>
<h3>5.3 所以结论是这条</h3>
<blockquote>
<p dir="auto"><strong>不等分切分能挽回的是「浪费」，挽回不了「算力差」本身。</strong></p>
<p dir="auto">两张卡差距在 1.5 倍以内，组 TP 明显划算；<br />
超过 3 倍，就算切到最优也只跟最快那张单卡打平——<strong>那就直接用快的那张，别折腾</strong>。</p>
</blockquote>
<p dir="auto">这个结论我放在文档最显眼的位置，因为不想让人踩完坑才发现不划算。</p>
<p dir="auto">顺便给个可操作的方法：<strong>组异构 TP 之前，先用单端模式量一下两张卡各自跑多快</strong>。<br />
半小时的测量，能省掉几天的调参。</p>
<hr />
<h2>六、几个不满足会「静默出错」的约束</h2>
<p dir="auto">这块是给想照做的人看的，踩过才知道疼。</p>
<p dir="auto"><strong>1. head 数必须是偶数</strong>（int8 ConvRot 量化要求输入特征能被 256 整除）</p>
<pre><code>35 × 128 = 4480 → 4480 / 256 = 17.5
ConvRot group size 256 does not divide input features 4480
</code></pre>
<p dir="auto">这个会直接崩，好发现。下面这个不会。</p>
<p dir="auto"><strong>2. head 数必须是 4 的倍数</strong></p>
<p dir="auto">我试过 34:22：跑通了、尺寸全对、无死锁、日志全绿——<strong>但 PSNR 只有 14.33 dB，画面完全不一样</strong>。<br />
28:28 / 32:24 / 36:20 全都正常，差别只在 34=2×17、22=2×11 不是 4 的倍数。</p>
<p dir="auto"><strong>3. 验收只能看 PSNR，不能看「跑通了」</strong></p>
<pre><code class="language-bash">ffmpeg -i rank0.mp4 -i rank1.mp4 -lavfi "[0:v][1:v]psnr" -f null - 2&gt;&amp;1 | grep PSNR
# 正确：&gt; 40 dB     错误：~14 dB
</code></pre>
<p dir="auto">还有个反直觉的点：<strong>PSNR 高也可能是「一致地错」</strong>。两端都算错同样的内容，一致性照样很高。<br />
所以它只能证明「切分没让两端分叉」，画质本身还得跟单卡出片比。</p>
<hr />
<h2>七、稳定性，以及 1.2.5 修掉的两个坑</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>项</th>
<th style="text-align:right">结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>1 GiB 连跑 1500 轮</td>
<td style="text-align:right">p99 50.60 ms，抖动 &lt;0.2%</td>
</tr>
<tr>
<td>跨尺寸来回切</td>
<td style="text-align:right">720 次全部正常</td>
</tr>
<tr>
<td>正确性检查</td>
<td style="text-align:right">104 项全过</td>
</tr>
</tbody>
</table>
<p dir="auto">顺带说个教训：早期有个版本 104 项 bench 全绿，但实际跑 H3 单步就崩——因为 bench 每轮都填<br />
同一个均匀值、张量还是连续的，把「跨 stream 读到半成品」和「非连续张量丢结果」两个 bug<br />
同时掩盖了。<strong>所以判据不能只看 bench，得看端到端结果。</strong></p>
<p dir="auto">1.2.5 修的两个坑也都值得说：</p>
<p dir="auto"><strong>坑一：bcast 连续调用会读到「撕」的数据</strong></p>
<p dir="auto">老版本 root 写完就返回，不等对端读完；下一次调用直接把对端正在读的那段覆盖一半。<br />
接收端拿到的字节数是对的、内容一半新一半旧，<strong>不报错</strong>。</p>
<p dir="auto">在别的机器上复现出来很吓人：1 MB × 300 轮，<strong>290 轮撕裂</strong>。而且撕裂率取决于两端速度差——<br />
rank0 快的时候几乎必中。这解释了线上为什么「偶发」。</p>
<p dir="auto">更逗的是老版本自己的测量数据就自相矛盾：同一个操作，rank0 测出 7 微秒、rank1 测出 63 微秒，<br />
差 9 倍。那就是竞态在时序上的体现。加了背压之后两端完全一致，4 MB 还快了 41%<br />
（1.021 → 0.598 ms，因为原来那个「快」是假的）。</p>
<p dir="auto">代价是 1 KB 从 1 微秒变 2 微秒，多一次往返。</p>
<p dir="auto"><strong>坑二：<code>flags</code> 文件从不删除，同名重启必然卡 120 秒</strong></p>
<p dir="auto">清理代码算错了路径，实际文件从来没被删过。残留文件里带着上一轮的标记，会让对端「秒过」握手，<br />
然后本端清零、永远等不到报到——120 秒超时。而 session 名一般是固定的，同名重启是常态。</p>
<p dir="auto">更麻烦的是只修「自己不再产残留」不够：别人留下的（被 kill -9 的进程、老版本）照样会卡。<br />
所以加了「读到残留就清零重来」。这条是外部机器实测出来的，我自己没测到——<strong>感谢那位帮我做<br />
验证的朋友</strong>。</p>
<hr />
<h2>最小可跑示例</h2>
<p dir="auto">两个终端，各一张卡：</p>
<pre><code class="language-bash"># 终端 1（rank0，比如 NVIDIA 卡）
CUDA_VISIBLE_DEVICES=0 python3 bench_sweep.py --rank 0 --mode msg --mb 1200 --sizes 4k,1g --iters 20

# 终端 2（rank1，比如 AMD 卡）
ROCR_VISIBLE_DEVICES=0 python3 bench_sweep.py --rank 1 --mode msg --mb 1200 --sizes 4k,1g --iters 20
</code></pre>
<p dir="auto">两端会各自打印 <code>RESULT ... ok=True</code>。<code>ok=False</code> 就是数值不对，别忽略。</p>
<p dir="auto"><strong>两端必须同时起、同时退出</strong>。只起一端会死等（1.2.5 会在 30 s 后报超时，老版本会一直挂着）。</p>
<h2>不等分切分怎么用</h2>
<p dir="auto">参考实现已经支持了，环境变量控制：</p>
<pre><code class="language-bash">TP_HEAD_SPLIT=36,20 bash &lt;你的启动脚本&gt;      # 56 个 head 拆成 36 + 20
# 不设 = 回退对称 28:28
</code></pre>
<p dir="auto">两端必须传<strong>同一个值</strong>。细节（包括为什么必须是 4 的倍数、为什么 <code>rows == 10752</code><br />
这个判断会静默废掉 TP）见 <code>examples/h3-tp2/README.md</code> 的「二·补」一节。</p>
<h2>两个平台的环境变量不一样</h2>
<p dir="auto">同一份库，两个组合的正确参数不同，<strong>混用会死锁</strong>：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>项</th>
<th>AMD + Intel</th>
<th>AMD + NVIDIA</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>FCCL_DUPLEX</code></td>
<td><strong>0</strong>（Intel 端无 duplex 实现）</td>
<td>1（默认，16 MB 分块双工）</td>
</tr>
<tr>
<td><code>FCCL_BLOCK_MB</code></td>
<td>1200（让 Intel 侧 <code>chunks=1</code>）</td>
<td>275（默认）</td>
</tr>
<tr>
<td>共享区</td>
<td><code>/dev/hugepages</code>（2 MiB 大页）</td>
<td><code>/dev/shm</code>（两端都 pin 过，页大小无影响）</td>
</tr>
<tr>
<td><code>FCCL_COPY_CHUNK_MB</code></td>
<td>128</td>
<td>不用</td>
</tr>
</tbody>
</table>
<p dir="auto">AMD + Intel 必须单块路径：设 <code>FCCL_DUPLEX=1</code> 时 AMD 端会等 Intel 上报块大小，<br />
而 Intel 端根本不走双工 → 60 秒超时。</p>
<h2>常见环境变量</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>变量</th>
<th>默认</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>FCCL_DUPLEX</code></td>
<td>1</td>
<td>分块双工流水（同厂商/ AMD+NVIDIA 用；AMD+Intel 必须 0）</td>
</tr>
<tr>
<td><code>FCCL_DUPLEX_BLOCK_MB</code></td>
<td>16</td>
<td>双工块大小，两端必须一致</td>
</tr>
<tr>
<td><code>FCCL_BLOCK_MB</code></td>
<td>275</td>
<td>单块路径的块宽</td>
</tr>
<tr>
<td><code>FCCL_SHM_MODE</code></td>
<td>600</td>
<td>共享文件权限；跨 uid 部署才需要 666</td>
</tr>
<tr>
<td><code>FCCL_XPU_PIPELINE</code></td>
<td>1</td>
<td>Intel 流水开关，设为 0 可强制单块</td>
</tr>
</tbody>
</table>
<h2>硬件要求（这条比代码重要）</h2>
<p dir="auto">数据要过一遍主机内存，所以<strong>主存同时读写带宽 ≈ 4 × PCIe 单向上限</strong>：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>PCIe</th>
<th style="text-align:right">单向上限</th>
<th style="text-align:right">需要的主存同时读写</th>
</tr>
</thead>
<tbody>
<tr>
<td>3.0 x16</td>
<td style="text-align:right">~13 GB/s</td>
<td style="text-align:right">~52 GB/s（四条 DDR4 够）</td>
</tr>
<tr>
<td>4.0 x16</td>
<td style="text-align:right">~26 GB/s</td>
<td style="text-align:right">~104 GB/s（要 8 条）</td>
</tr>
<tr>
<td>5.0 x16</td>
<td style="text-align:right">~44 GB/s</td>
<td style="text-align:right">~177 GB/s（四条 DDR5 差 2 倍多）</td>
</tr>
</tbody>
</table>
<p dir="auto">不够的话不是跑不动，是跑不出双工收益——速度会掉回单块水平。</p>
]]></description><link>https://lcz.me/post/35078</link><guid isPermaLink="true">https://lcz.me/post/35078</guid><dc:creator><![CDATA[fcys]]></dc:creator><pubDate>Sat, 28 Nov 2026 07:18:04 GMT</pubDate></item></channel></rss>