让大模型推理结果可复现,不降性能也不改代码
LLM-42: Enabling Determinism in LLM Inference with Verified Speculation
- 用调度机制实现确定性推理,不依赖修改计算内核
- 仅对需要确定性的请求施加验证开销,平均延迟增益30%
- 适合对结果一致性要求高的科研、金融等场景使用
大模型推理中,相同提示可能在不同运行中产生不同输出。系统层面的非确定性源于浮点数运算的非结合性,以及动态批处理和随批量变化的GPU内核归约顺序。直接禁用动态批处理虽能消除非确定性,但严重降低吞吐量;而使内核与批大小无关,则需重构内核并引入固定开销。受推测解码启发,本文提出LLM-42:一种基于调度的确定性推理方法。核心观察是,若序列处于一致状态,即使使用动态批处理,下一词元也大概率一致。多数GPU内核采用形状一致的归约方式。因此,LLM-42通过非确定性快速路径生成候选词元,并通过轻量级验证回滚循环确保一致性:验证器以固定形状归约顺序重放候选词元,确认一致则提交,不一致则回滚。该方法基本复用现有内核,开销仅与需确定性的流量成正比。
原文摘要 · Abstract (English)
In LLM inference, the same prompt may yield different outputs across different runs. At the system level, this non-determinism arises from floating-point non-associativity combined with dynamic batching and GPU kernels whose reduction orders vary with batch size. A straightforward way to eliminate non-determinism is to disable dynamic batching during inference, but doing so severely degrades throughput. Another approach is to make kernels batch-invariant; however, this tightly couples determinism to kernel design, requiring new implementations. This coupling also imposes fixed runtime overheads, regardless of how much of the workload actually requires determinism. Inspired by ideas from speculative decoding, we present LLM-42, a scheduling-based approach to enable determinism in LLM inference. Our key observation is that if a sequence is in a consistent state, the next emitted token is likely to be consistent even with dynamic batching. Moreover, most GPU kernels use shape-consistent reductions. Leveraging these insights, LLM-42 decodes tokens using a non-deterministic fast path and enforces determinism via a lightweight verify-rollback loop. The verifier replays candidate tokens under a fixed-shape reduction schedule, commits those that are guaranteed to be consistent across runs, and rolls back those violating determinism. LLM-42 mostly re-uses existing kernels unchanged and incurs overhead only in proportion to the traffic that requires determinism.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。