一项于2026年11月23日提交的研究指出,PyTorch框架中的 F.kl_div 函数在CPU和GPU上均存在严重的数值精度问题,导致计算结果可能出现负值或显著误差 1。长期以来,用户报告KL散度出现负值时,标准建议是将其钳制为零,但这实际上掩盖了潜在的静默失败 1。
大规模基准测试显示,在涉及850万输入、18个闭式KL族及 F.kl_div 的测试中,超过85%的FP32值在KL接近 $10^{-7}$ 时具有至少1%的相对误差,约30%的结果在更小的散度下变为负值 1。即便将浮点精度提升一级,仍有7%至51%的FP32值在23种配置中的22种里保持显著错误,表明提高精度无法根本解决该问题 1。这些错误已波及参数拟合、贝叶斯决策、模型蒸馏(导致高达97%的top-1不一致)、量化LLM的KL层级排名以及GPT-2电路边缘评分(影响19%至59%)等下游任务 1。
研究人员提出了基于稳定闭式分解、补偿算术和解析梯度的严格修复方法 1。该方案消除了97%以上的显著错误,并正确对5.67亿个评分 F.kl_div 组件进行了四舍五入处理 1
A research paper submitted on November 23, 2026, identifies severe numerical precision issues in the F.kl_div function within PyTorch, causing it to produce negative values or significant errors on both CPU and GPU devices 1. Although Kullback-Leibler divergence is theoretically non-negative, PyTorch users have long reported instances of negative results, typically addressing them by clamping values to zero 1. Researchers warn that this standard workaround masks underlying silent failures in the computational backend 1.
Benchmark tests involving 8.5 million inputs across 18 closed-form KL families revealed that over 85% of FP32 values exhibited at least 1% relative error when KL divergence approached $10^{-7}$ 1. Approximately 30% of these results turned negative under conditions of smaller divergence 1. Even increasing floating-point precision by one level did not fundamentally resolve the issue; in 22 out of 23 tested configurations, between 7% and 51% of FP32 values remained significantly incorrect 1. To address these defects, the study proposes a rigorous fix utilizing stable closed-form decomposition, compensated arithmetic, and analytic gradients 1. This method eliminated more than 97% of significant errors and ensured correct rounding for 567 million scored components of F.kl_div 1.
The identified numerical flaws have impacted various downstream machine learning tasks, including parameter fitting, Bayesian decision-making, and model distillation 1. In distillation scenarios starting from identical points, the errors resulted in top-1 inconsistency rates as high as 97% 1. Additionally, the defects affected KL hierarchical rankings in quantized LLMs and edge scoring in GPT-2 circuits, with impact rates ranging from 19% to 59% 1.
评论
还没有评论,欢迎留下第一条。