Bit-Exact After the TP Shape Changes?
TP1 has no collective, so bit-exact agreement across tensor-parallel shapes can only come from one shared tree for the on-GPU K reduction and the cross-GPU reduction. TBIK already builds that tree.
Where deterministic inference stands
Floating-point addition is not associative. In bf16, (a+b)+c and a+(b+c) often differ in the last bit. Every matmul and every softmax in a large-model forward pass sums thousands of terms. Change the order and the last bit moves. Under greedy decoding, a top-1 that flips between two close candidates sends the rest of the continuation down another path. For a long time this was treated as unavoidable noise.
In 2025, Thinking Machines pointed out that the main source of nondeterminism in inference serving is not a race among GPU threads. It is the batch size changing the kernel’s tile choice and split, and therefore the summation order. They published a set of batch-invariant kernels with a fixed tile, so the same request yields the same bits no matter which other requests share its batch (He et al., 2025). vLLM then added VLLM_BATCH_INVARIANT. The switch replaces matmul, normalization, and related operators, pins NCCL to the tree algorithm, one channel, and the Simple protocol, and turns off the custom allreduce. It requires compute capability 8.0 or newer (vLLM batch invariance). SGLang’s deterministic mode takes the same path. It fixes custom allreduce to a single-stage kernel that sums in rank order, and on H100 it is about 34% slower on average (LMSYS, 2025).
These modes provide several invariants that are independent of each other: the same bits from run to run at a fixed shape, the same bits across batch sizes, and sometimes the same bits between prefill and decode. A different GPU model and a different parallel shape are two further axes. Getting the first few does not hand you the last two.
Why the parallel shape changes
Tensor parallelism (TP) splits one layer’s weights across GPUs. The Megatron split cuts the first MLP matrix by columns. Each GPU computes some of the output columns and needs no communication. The second matrix is cut by rows, along the reduction dimension K. Each GPU produces a partial sum with the full output shape but only a slice of K, and an allreduce adds those partial sums (Shoeybi et al., 2019). The attention output projection works the same way. An 8B dense model with hidden size 4096 and intermediate size 14336 has two row-parallel reductions in every layer.
The TP degree changes in real systems. A serving stack scales instances with load, and a request can move from a TP4 instance to a TP1 instance. In reinforcement learning, the rollout side and the trainer side often use different parallel configurations. The probability of the same trajectory is computed twice, and any numerical gap becomes off-policy bias. The usual response is an importance correction, or bit-exact alignment at one fixed shape. The natural question is whether the deterministic promise still holds when the TP shape changes.
TL;DR
Deterministic inference already makes one fixed deployment shape repeat bit for bit. The natural guess is to extend that to a changing tensor-parallel degree, so TP1, TP2, and TP4 emit the same bits.
The hard part is not the collective. A row-parallel layer splits K by the TP degree and rounds each piece. TP1 has no collective, so tuning NCCL can never make TP1 agree with TP4. The on-GPU K reduction and the cross-GPU reduction have to share one fixed tree.
TBIK (arXiv 2511.17826) already builds that tree on vLLM and reports bit-exact TP 1/2/4/8, at 22% to 63% end to end against native BF16, and only for power-of-two TP and row-parallel layers. The tree is already there. What remains is extension and a lower cost. It is still unclear who actually needs cross-shape agreement. The conjecture fails before any GPU measurement.
The conjecture we can test
The starting judgment was that a numerical result only has to be stable inside one deployment shape, and that mathematical equivalence is enough across shapes. Elastic serving and separated training and inference make that old assumption too weak. The plan was a canonical arithmetic DAG that does not depend on the TP shape. Split the K dimension of each row-parallel layer into a globally fixed number of chunks C, where C is a common multiple of the TP degrees we support. Reduce each chunk on a fixed tree. TP1 simulates the same split and the same rounding points inside one kernel. When TP is larger than 1, each GPU computes its own chunks and the GPUs merge them on the same tree. This looked feasible because a fixed-order exact mode on one GPU is already cheap, and pushing it to many GPUs looked like one extra convention on the collective.
The split is on the GPU, not in the collective
The existing switches are not enough, and the reason is visible before any measurement. Figure 1 is the same sum of K=8 tiles under three executions.
(a) and (b) differ in three places: where the split falls, how many intermediate roundings occur, and the order of the adds. Pinning NCCL’s algorithm, protocol, and channel count can make (a) repeatable for one rank count and one topology. It cannot change (b), because TP1 has no collective to configure. Any plan that only touches the communication library therefore cannot make TP1 agree with TP4. The GEMM kernel on the TP1 side has to adopt the same K split and the same tree as TP4. That is (c). This follows from the reduction structure. It does not depend on a measurement.
We estimated the cost of (c) with a closed-form model (Figure 2). The model uses the Llama-3-8B shape and nominal A100 PCIe parameters: 1.5 TB/s of HBM, 312 TFLOPS of bf16, 25 GB/s of effective cross-GPU PCIe, 15 microseconds of latency per collective, and C=4.
The left panel says the TP1 cost grows with the batch. Decode at batch 1 is negligible, about 0.1%. Batch 64 is about 5%. An 8K-token prefill is about 18%. If the rounding at the split boundaries is fused into one kernel, there is no extra memory traffic. The right panel says the real cost is multi-GPU communication. An all-gather delivers every partial sum to every GPU, so the volume is about the rank count times an allreduce. For small messages the latency term dominates, and this path is faster than the two rounds of a ring: about 0.51× at decode batch 1 and 0.89× at batch 64. For large messages the bandwidth term dominates, and an 8K prefill is about twice the ring. The estimate assumes PCIe and nominal bandwidth. The ratios move on an NVLink machine.
Prior work already built this tree
In the search we ruled out the existing systems one by one. The deterministic modes in vLLM and SGLang, a pinned NCCL configuration, Megatron’s deterministic mode, and the true on-policy alignment in RL frameworks all hold only inside their own fixed parallel shape. Neither the docs nor the code claim agreement across TP shapes. ReproBLAS uses binned floating point so a sum does not depend on order, which removes the problem at the root, but it is CPU BLAS and MPI reductions (Demmel and Nguyen, 2015).
Searching by mechanism turned up Tree-Based Invariant Kernels, TBIK (arXiv 2511.17826). Its TP-invariant matmul is a persistent Triton kernel. It reduces K by tiles on a binary tree, and the upper levels of that tree are exactly the cross-GPU cuts at different TP degrees. The tree TP1 computes inside one GPU is the same tree TP4 assembles from on-GPU pieces plus the cross-GPU levels. That is Figure 1(c). The cross-GPU part is a tree allreduce. Small tensors use a custom kernel over IPC. Large tensors fall back to an all-gather and then add pairs in a fixed hierarchy. The paper explains why it does not use NCCL: inside a node, NCCL is still a chain reduction. The implementation is a patch that replaces RowParallelLinear in vLLM 0.11, switched on by two environment variables. It reports bit-exact agreement, in BF16, for Qwen3, Llama-3.1, Mistral, and related models, at TP 1/2/4/8 and batch sizes 8/16/32. The same kernels are used on the FSDP training side, so TP1 training and multi-GPU rollout probabilities differ by zero. The end-to-end cost against native BF16 is 22% to 63%. The tree matmul alone is 2% to 25%, and the tree allreduce is at most 10%. The boundary is stated clearly. TP must be a power of two. Only row-parallel layers are covered. Attention requires chunked prefill to be off. There are no results for MoE, pipeline parallelism, or fp16.
Why the conjecture does not hold
For the conjecture to stand, existing systems would have to be unable, in principle, to agree across shapes. TBIK refutes that, and it refutes it with the mechanism we were about to propose: one tree covering both levels of the reduction. What is left is TP degrees that are not powers of two (a fixed chunk count plus a linear fold does not require a power of two), expert parallelism for MoE, and a lower overhead. Those are extensions and engineering on the same mechanism. They are not a new capability.
The second reason is demand. The migration cases we wanted to serve are single GPU to single GPU, and a single-GPU exact mode already covers them. Aligning training and rollout is the use TBIK itself chose, and same-shape alignment plus an importance correction is already common practice. We could not find a user for whom bit-exact agreement across TP shapes is irreplaceable.
One gap remains. TBIK’s consistency claim comes from its paper and its code. We did not reproduce it on our own hardware. The Volta GPUs we have do not meet the compute-capability requirement of vLLM’s deterministic mode, and they have no native bf16. The only way that gap would hurt the technical conclusion is if TBIK failed under a wider set of conditions, and that failure sits in the extensions already listed above.
What this analysis supports directly
Bit-exact agreement across TP shapes, on a row-parallel layer, requires the on-GPU K reduction and the cross-GPU reduction to be the same logical DAG. TP1 has no collective. Pinning NCCL’s algorithm, protocol, and channel count does nothing. To judge whether a deterministic scheme can cross shapes, look first at whether it specifies the tree inside the K dimension.
Determinism has at least five independent axes: run to run, batch, prefill versus decode, GPU model, and parallel shape. Having one does not give you another. When you read the documentation of a deterministic mode, check which axis it actually claims.
The numbers below are a closed-form estimate, on PCIe at nominal bandwidth. The main cost of cross-shape agreement is not on the TP1 side. Once the rounding is fused into one kernel, a single GPU barely adds memory traffic. The cost is on the multi-GPU side, where an all-gather replaces an allreduce. Communication for a large-batch prefill roughly doubles. Small-batch decode is faster. The crossover is set by the message size and the latency of one collective.
Among existing open implementations, the deterministic modes in vLLM and SGLang give same-shape agreement only. TBIK gives cross-shape agreement for power-of-two TP, at 22% to 63% end to end against native BF16. That denominator is not a same-shape deterministic mode. A comparison has to use the same one.
Searching for deterministic inference by the name of the problem finds systems that share the name and not the invariant. Searching by the mechanism finds the work that actually covers it. Once the mechanism can be written in one sentence, search for that sentence before any characterization experiment.
TBIK already covers the defining case
What stays is the search result. TBIK already builds this tree on vLLM and reports bit-exact TP 1/2/4/8. Against native BF16 the end-to-end cost is 22% to 63%, and only for power-of-two TP and row-parallel layers. The tree itself is already in prior work. What remains is extending it to more shapes and lowering the cost. It is still unclear who cannot do without bit-exact agreement across shapes. The conjecture fails before any GPU measurement.
TP1 没有 collective,所以跨 TP 形状的逐位一致只能靠让卡内 K 维归约与卡间归约共用一棵树,而这件事 TBIK 已经做出来了。
确定性推理走到了哪一步
浮点加法不满足结合律,(a+b)+c 与 a+(b+c) 在 bf16 下常常差一个末位。大模型推理里每个矩阵乘、每次 softmax 都是成千上万项的求和,求和顺序一变,末位就变,贪心解码时某个位置的 top-1 在两个接近的候选之间翻转,后面的整条续写就走到另一条路上。长期以来这被当成不可避免的噪声。
2025 年 Thinking Machines 指出,推理服务里不确定性的主要来源不是 GPU 线程的竞态,而是 batch 大小改变了 kernel 的 tile 选择与切分策略,进而改变了求和顺序;他们给出一组固定 tile 的 batch invariant kernel,让同一请求不论和谁拼 batch 都得到同样的比特(He et al., 2025)。此后 vLLM 加了 VLLM_BATCH_INVARIANT 开关,它替换 matmul 与归一化等算子,同时把 NCCL 固定为 tree 算法、单 channel、Simple 协议,并关掉自研的 custom allreduce,要求计算能力 8.0 以上的 GPU(vLLM batch invariance)。SGLang 的确定性推理模式走同一条路,把 custom allreduce 固定成按 rank 顺序求和的单阶段 kernel,在 H100 上平均慢约 34%(LMSYS, 2025)。
这些模式给的是几种互相独立的不变量:同一形状下 run 与 run 之间一致,不同 batch 之间一致,有时还有 prefill 与 decode 之间一致。GPU 型号不同与并行形状不同是另外两个维度,拿到前面几个并不自动拿到后面两个。
为什么并行形状会变
张量并行(Tensor Parallelism,TP)把一层的权重切到多张卡上。Megatron 式的切法把 MLP 的第一个矩阵按列切(column-parallel),每张卡算输出的一部分列,不需要通信;第二个矩阵按行切(row-parallel),也就是沿求和维 K 切开,每张卡算出完整形状但只含 K 的一段的部分和,再用 allreduce 相加(Shoeybi et al., 2019)。attention 的输出投影同理。一个 8B 的 dense 模型隐藏维 4096、中间维 14336,每层有两次 row-parallel 归约。
TP 度数在实际系统里会变。推理服务随负载伸缩实例,一个请求可能从 TP4 的实例迁到 TP1 的实例;强化学习的 rollout 端与 trainer 端常用不同的并行配置,同一条轨迹的概率在两端算两次,任何数值差都会变成 off-policy 偏差,现有的做法是做重要性修正或在同形状下逐位对齐。所以一个自然的问题是:确定性的承诺能不能在 TP 形状改变时仍然成立。
TL;DR
确定性推理已经能让同一种部署形状下的输出逐位重复。自然的猜想是把这个承诺推广到 TP 度数变化的时候,让 TP1、TP2、TP4 给出同样的比特。
难点不在 collective。row-parallel 层把 K 维按 TP 切开,每段各自舍入。TP1 没有任何 collective,所以只调 NCCL 永远不可能让 TP1 和 TP4 一致。卡内的 K 维归约和卡间归约必须共用同一棵固定的树。
检索找到了 TBIK(arXiv 2511.17826)。它已经在 vLLM 上用这棵树做到了 TP 1/2/4/8 的逐位一致,相对原生 BF16 的端到端代价是 22% 到 63%,而且只限于 TP 度数是 2 的幂,以及 row-parallel 层。这棵树已经被做出来了。剩下的是扩展和把开销做低。谁真正需要跨形状一致,也没有明确答案。所以这个猜想在任何 GPU 实测之前就不成立。
可检验的猜想
我们的出发点是这样一个判断:数值结果只需要在固定部署形状内稳定、跨形状只要数学等价,这条旧假设在弹性服务与训推分离下不再够用。我们想定义一个与 TP 形状无关的规范算术 DAG:把 row-parallel 层的 K 维切成全局固定的 C 份(C 取所支持 TP 的公倍数),每份按固定树归约,TP1 在一个 kernel 内模拟同样的切分与舍入点,TP 大于 1 时每张卡算自己那几份,再按同一棵树跨卡合并。当时觉得可行,是因为单卡上固定顺序的精确模式已经被做到很低的代价,把它推到多卡看起来只差一个 collective 的约定。
关键在卡内,而不在 collective
先看为什么现成的开关不够。图 1 画的是同一段 K=8 个 tile 的求和在三种执行下的形状。
(a) 与 (b) 的差别有三处:切分点不同,中间舍入的次数不同,相加顺序不同。固定 NCCL 的算法、协议与 channel 数只能让 (a) 在同一卡数与拓扑下可重复,它改变不了 (b),因为 TP1 根本没有 collective 可调。所以任何只动通信库的方案都不可能给出 TP1 与 TP4 一致,TP1 端的 GEMM kernel 必须主动采用与 TP4 相同的 K 切分与同一棵树,这就是 (c)。这一条是从归约结构直接推出来的,不依赖任何测量。
我们用闭式模型估了 (c) 的代价(图 2)。模型取 Llama-3-8B 的形状,A100 PCIe 的名义参数:HBM 1.5 TB/s,bf16 312 TFLOPS,卡间 PCIe 有效 25 GB/s,每次 collective 延迟 15 微秒,C=4。
左图说明 TP1 端的代价随 batch 增长,decode batch 1 可以忽略,约 0.1%;batch 64 约 5%;8K token 的 prefill 约 18%。如果切分边界的舍入融合进一个 kernel 内完成,就没有额外访存。右图说明真正的代价在多卡通信:all-gather 让每张卡收到全部部分和,通信量约为 allreduce 的卡数倍。小消息时延迟项占主导,它比 ring 的两轮还快,decode batch 1 约 0.51 倍,batch 64 约 0.89 倍;大消息时带宽项占主导,prefill 8K 约为 ring 的 2 倍。估算的前提是 PCIe 互联与名义带宽,NVLink 机器上比例会不同。
前作已经做出了这棵树
组合攻击阶段我们逐个排除了现成系统:vLLM 与 SGLang 的确定性模式、NCCL 固定配置、Megatron 的确定性模式以及 RL 框架的 true on-policy 对齐,都只在各自固定的并行形状下成立,文档与代码都不声称跨 TP 形状一致。ReproBLAS 用分箱浮点让求和与顺序无关,能从根上解决问题,但只有 CPU BLAS 与 MPI 归约(Demmel and Nguyen, 2015)。
按机制检索时找到了 Tree-Based Invariant Kernels(TBIK)(arXiv 2511.17826)。它的 TP invariant matmul 是一个 Triton persistent kernel,把 K 维按 tile 做二叉树归约,树的上层恰好对应不同 TP 下的卡间切分,所以 TP1 在卡内算出的树与 TP4 卡内加卡间拼出的树相同,与图 1(c) 一致。卡间部分是一个 tree allreduce:小张量走基于 IPC 的自定义 kernel,大张量回落到 all-gather 后按层级固定配对相加。论文解释了为什么不用 NCCL:NCCL 在节点内仍是链式归约。它以补丁形式替换 vLLM 0.11 的 RowParallelLinear,打开两个环境变量即可使用,报告在 BF16 下 Qwen3、Llama-3.1、Mistral 等模型上 TP 1/2/4/8 与 batch 8/16/32 全部逐位一致,并把同一套 kernel 用到 FSDP 训练端,使 TP1 训练与多卡 rollout 的概率零差异。代价方面,端到端相对原生 BF16 为 22% 到 63%,tree matmul 单独 2% 到 25%,tree allreduce 至多 10%。它的适用边界也写得清楚:TP 必须是 2 的幂,只处理 row-parallel 层,attention 需要关掉 chunked prefill,没有 MoE、流水线并行与 fp16 的结果。
为什么这个判断不成立
我们的猜想要成立,需要现有系统在原理上做不到跨形状一致。TBIK 把这一条推翻了,用的就是我们准备提出的那棵树。剩下能做的,是 TP 度数不是 2 的幂、MoE 的专家并行,以及更低的开销。这些都是同一机制上的扩展,不是新的能力。
另一个原因是需求。我们想服务的迁移,实际都是单卡到单卡,单卡上的精确模式已经覆盖了。RL 里训推对齐是 TBIK 自己选的需求方。同形状对齐,再加重要性修正,已经是常见做法。跨 TP 形状的逐位一致究竟对谁不可替代,我们没有找到明确答案。
有一处没能排除。TBIK 的一致性来自它的论文和代码,我们没有在自己的机器上复现。手头的 Volta 卡达不到 vLLM 确定性模式要求的计算能力,也没有原生 bf16。这个偏差只有一种情形会伤到结论,就是它在更广的条件下失效。那恰好落在上面已经归进扩展的范围里。
从这次分析可以直接得到什么
跨 TP 形状要逐位一致,row-parallel 层的卡内 K 维归约和卡间归约必须是同一个逻辑 DAG。TP1 没有 collective。固定 NCCL 的算法、协议和 channel 数都没用。看一个确定性方案能不能跨形状,先看它有没有规定卡内 K 维的树。
确定性至少有五个互不蕴含的维度:两次运行之间、不同 batch、prefill 与 decode、GPU 型号、并行形状。拿到其中一个,并不等于拿到另一个。读确定性模式的文档时,要逐项看它声称的是哪一个。
下面的数是闭式估算,前提是 PCIe 互联和名义带宽。跨形状一致的主要代价不在 TP1。融合进一个 kernel 之后,单卡几乎不多访存。代价在多卡这一端,用 all-gather 代替 allreduce。大 batch 的 prefill,通信量大约翻倍。小 batch 的 decode 反而更快。交叉点由消息大小和每次 collective 的延迟决定。
现成的开源方案里,vLLM 和 SGLang 的确定性模式只保证同一种形状内部一致。TBIK 给出 2 的幂 TP 上的跨形状一致,相对原生 BF16 的端到端代价是 22% 到 63%。这个分母不是同形状的确定性模式。比较时要换成同一个分母。
按问题的名字去检索确定性推理,找到的往往是名字相近、不变量却不同的系统。按机制检索,才会找到真正已经覆盖这件事的工作。机制一旦能写成一句话,就值得在跑任何表征实验之前,按这句话检索一次。
定义性的能力已经被 TBIK 覆盖
最值得记住的是检索结果。TBIK 已经用这棵树,在 vLLM 上做到了 TP 1/2/4/8 的逐位一致。相对原生 BF16,端到端代价是 22% 到 63%,而且只限于 TP 度数是 2 的幂,以及 row-parallel 层。这棵树本身已经被前作做出来了。剩下的是扩到更多形状,以及把开销做低。谁真正离不开跨形状的逐位一致,也还没有明确答案。所以这个猜想在任何 GPU 实测之前就不成立。