arXiv:2511.17826cs.LGcs.CL2025-11被引 14

解决大模型推理中因张量并行规模不同导致结果不一致的问题

Deterministic Inference across Tensor Parallel Sizes That Eliminates Training-Inference Mismatch

  • 设计树形结构的不变内核,统一跨GPU计算顺序
  • 实现不同张量并行规模下完全一致的推理结果
  • 适合需要严格可复现性的强化学习与评测场景

大语言模型应用如评委评估、多智能体系统和强化学习越来越依赖确定性推理。然而现有服务框架在不同张量并行(TP)规模下会出现非确定性行为:相同输入在不同配置(如TP大小、批处理大小)下可能产生不同输出,即使使用贪婪解码。这源于浮点运算的非结合性及跨GPU归约顺序不一致。尽管已有工作通过批处理无关内核解决了批大小相关的不确定性,但跨不同TP规模的确定性仍是未解难题,尤其在强化学习中——训练通常采用全分片数据并行(即TP=1),而推理则使用多卡张量并行以提升吞吐,造成天然的训练-推理不匹配。该精度差异可能导致强化学习性能下降甚至崩溃。本文识别并分析了TP导致不一致的根本原因,提出树形不变内核(TBIK),一组保证任意TP规模下比特级完全一致的矩阵乘法与归约原语。核心思想是通过统一的层次二叉树结构对齐组内与组间归约顺序。我们在Triton中实现这些内核,并集成至vLLM与FSDP。实验表明,在不同TP规模下实现了零概率发散与比特级可复现;在采用不同并行策略的强化学习流水线中,vLLM与FSDP之间也实现了比特级一致结果。代码已开源。

原文摘要 · Abstract (English)

Deterministic inference is increasingly critical for large language model (LLM) applications such as LLM-as-a-judge evaluation, multi-agent systems, and Reinforcement Learning (RL). However, existing LLM serving frameworks exhibit non-deterministic behavior: identical inputs can yield different outputs when system configurations (e.g., tensor parallel (TP) size, batch size) vary, even under greedy decoding. This arises from the non-associativity of floating-point arithmetic and inconsistent reduction orders across GPUs. While prior work has addressed batch-size-related nondeterminism through batch-invariant kernels, determinism across different TP sizes remains an open problem, particularly in RL settings, where the training engine typically uses Fully Sharded Data Parallel (i.e., TP = 1) while the rollout engine relies on multi-GPU TP to maximize the inference throughput, creating a natural mismatch between the two. This precision mismatch problem may lead to suboptimal performance or even collapse for RL training. We identify and analyze the root causes of TP-induced inconsistency and propose Tree-Based Invariant Kernels (TBIK), a set of TP-invariant matrix multiplication and reduction primitives that guarantee bit-wise identical results regardless of TP size. Our key insight is to align intra- and inter-GPU reduction orders through a unified hierarchical binary tree structure. We implement these kernels in Triton and integrate them into vLLM and FSDP. Experiments confirm zero probability divergence and bit-wise reproducibility for deterministic inference across different TP sizes. Also, we achieve bit-wise identical results between vLLM and FSDP in RL training pipelines with different parallel strategy. Code is available at https://github.com/nanomaoli/llm_reproducibility.

大模型推理确定性张量并行强化学习

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。