A recent study has identified significant numerical inaccuracies in PyTorch's Kullback–Leibler (KL) divergence computations, including the `F.kl_div` function. Despite KL divergence theoretically never being negative, PyTorch users have reported negative values for years. The research found widespread errors in both values and gradients across CPU and GPU, affecting 18 closed-form KL families and `F.kl_div`.
The analysis, conducted on 8.5 million inputs, revealed that for scalar families within ordinary parameter ranges, over 85% of FP32 values exhibit at least 1% relative error near KL 10^(-7). For FP16, this threshold is 10^(-3). Approximately 30% of these calculations become negative at smaller divergences. The issue is not resolved by higher precision; evaluating formulas one precision higher still leaves 7–51% of FP32 values significantly incorrect in 22 out of 23 configurations.
These numerical errors have practical consequences for various machine learning tasks. Affected areas include parameter fitting, Bayesian decision-making, identical-start distillation (showing up to 97% top-1 disagreement), KL-based layer rankings in quantized Large Language Models (LLMs), and 19–59% of GPT-2 circuit edge scores. The inaccuracies can lead to flawed model training and analysis.
The study proposes solutions involving stable closed-form decompositions, compensated arithmetic, and analytic gradients. Implementing these repairs removes over 97% of significant errors in the working format. Specifically, strict repairs eliminated significant errors on 7.2 million scored closed-form samples and correctly rounded all 567 million scored `F.kl_div` components, effectively resolving the issues in the affected applications.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
A new paper reveals that PyTorch's `F.kl_div` function and other KL divergence calculations frequently produce incorrect values, including negative results, across CPU and GPU. These errors affect machine learning applications like parameter fitting, Bayesian decisions, and LLM analysis, with over 85% of FP32 values showing significant relative error near KL 10^(-7). Stable decompositions and compensated arithmetic can resolve over 97% of these errors.