mlsanityData to 24 Nov 2026

The KL Divergence Is Never Negative, Except in PyTorch

arXiv 2611.30835 ↗Submitted 23 Nov 2026Announced 24 Nov 2026cs.LGcited by 0

Not on the map. Why?

Abstract (arXiv)

A Kullback--Leibler (KL) divergence is never negative, yet PyTorch users have reported negative values for years, and the standard advice is to clamp them at zero. The sign is only the visible part of a silent failure. Many machine-learning applications compare nearby distributions, where conventional KL formulas lose accuracy. On 8.5 million inputs with certified references across 18 closed-form KL families and F.kl_div, we find widespread errors in values and gradients on CPU and GPU. Among scalar families in ordinary parameter ranges, over 85% of FP32 values have at least 1% relative error near KL 10^(-7) (FP16: 10^(-3)), and about 30% become negative at smaller divergences. More precision is not the cure: evaluated one precision higher, the same formulas still leave 7--51% of FP32 values significantly wrong for 22 of 23 configurations. Stable closed-form decompositions, compensated arithmetic, and analytic gradients remove over 97% of significant errors in the working format. Strict repairs eliminate significant errors on 7.2 million scored closed-form samples and correctly round all 567 million scored F.kl_div components. The errors affect parameter fitting, Bayesian decisions, identical-start distillation (up to 97% top-1 disagreement), KL-based layer rankings in a quantized LLM, and 19--59% of GPT-2 circuit edge scores. With the repaired code they all but vanish. Code and data: https://github.com/xi-xiaoran/stablekl

Key facts. No citing papers in the map yet (data through 24 Nov 2026). Builds on 32 of its 65 references that are in the map. Submitted 23 Nov 2026, announced 24 Nov 2026.

Builds on

32 of 65 references.

References · 32

  1. 2019PyTorch: An Imperative Style, High-Performance Deep Learning Librarycited by 20,787
  2. 2017Proximal Policy Optimization Algorithmscited by 16,156
  3. 2015Distilling the Knowledge in a Neural Networkcited by 10,967
  4. 2024DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Modelscited by 10,542
  5. 2024Qwen2.5 Technical Reportcited by 5,525
  6. 2016Pointer Sentinel Mixture Modelscited by 3,344
  7. 2015Trust Region Policy Optimizationcited by 2,662
  8. 2022GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformerscited by 2,115
  9. 2022Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 smallcited by 1,269
  10. 2017Mixed Precision Trainingcited by 1,234
  11. 2023On-Policy Distillation of Language Models: Learning from Self-Generated Mistakescited by 1,201
  12. 2021A White Paper on Neural Network Quantizationcited by 519
20 more
  1. 2019HAWQ: Hessian AWare Quantization of Neural Networks with Mixed-Precisioncited by 425
  2. 2018Pyro: Deep Universal Probabilistic Programmingcited by 385
  3. 2023LLM-QAT: Data-Free Quantization Aware Training for Large Language Modelscited by 355
  4. 2020ZeroQ: A Novel Zero Shot Quantization Frameworkcited by 278
  5. 2019A Study of BFLOAT16 for Deep Learning Trainingcited by 269
  6. 2023How does GPT-2 compute greater-than?: Interpreting mathematical abilities in a pre-trained language modelcited by 217
  7. 2023MiniLLM: On-Policy Distillation of Large Language Modelscited by 162
  8. 2021Comparing Kullback-Leibler Divergence and Mean Squared Error Loss in Knowledge Distillationcited by 142
  9. 2017TensorFlow Distributionscited by 111
  10. 2019Taxonomy of Real Faults in Deep Learning Systemscited by 100
  11. 2025Defeating the Training-Inference Mismatch via FP16cited by 84
  12. 2023Stable and low-precision training for large-scale vision-language modelscited by 83
  13. 2025Grokking at the Edge of Numerical Stabilitycited by 61
  14. 2022The Numerical Stability of Hyperbolic Representation Learningcited by 53
  15. 2019The continuous Bernoulli: fixing a pervasive error in variational autoencoderscited by 43
  16. 2026Quantization-Aware Distillation for NVFP4 Inference Accuracy Recoverycited by 30
  17. 2024Transformer Circuit Faithfulness Metrics are not Robustcited by 27
  18. 2020Revisiting BFloat16 Trainingcited by 24
  19. 2022DeepStability: A Study of Unstable Numerical Methods and Their Solutions in Deep Learningcited by 13
  20. 2026A Fix for Softmax and Cross-Entropycited by 5

Built on by

Not cited yet.