Answers are grounded in this paper and cite their sources.
(v3.0): Standard PyTorch F.kl_div computes KL divergence via cancellation-prone log-space subtraction, causing negative outputs in FP16/BF16/FP32 and backward gradient dead-zones/sign-flips under clamp(min=0) patches. We prove formal floating-point truncation and condition-number bounds for a two-branch 6th-order Bregman-Taylor identity with cancellation-free analytic gradients, benchmark our fused Blackwell Triton kernel against FP32-upcast, torch.compile (TorchInductor), and chunked-FP32 up to V=151,936, and validate end-to-end BF16 KL-regularized LoRA post-training on real Qwen3-1.7B (V=151,936) and SmolLM2-1.7B (V=49,152) models. Empirical Findings (NVIDIA GeForce RTX 5090): Forward & backward gradient corruption across 36 regimes (Wilcoxon p=1.45e-11): PyTorch F.kl_div returns negative values on up to 50.4% of inputs and corrupts BF16 reverse-KL gradients (eps=1e-2) with 39.1% sign flips (cos=0.589). Clamping F.kl_div.clamp(min=0) induces 50.4% silent zero-gradient dead-zones and 61.8% sign flips (cos=0.371). Even in FP32 (eps=1e-4), F.kl_div and FP32-upcast yield 48.1% negative outputs and median relative error 21.14 (2,114%); our 6th-order Bregman-Taylor branch cuts median error by 149,111x to 1.42e-04 (0.0% negative, 0.0% error >=1%). Blackwell RTX 5090 kernel scaling vs. torch.compile & chunking at Qwen3 V=151,936 (N=512, BF16 fwd+bwd): Fused Triton runs in 0.90 ms (296.8 MB extra VRAM; Reverse KL 0.90 ms) — 6.54x faster (-80.0% VRAM) vs. FP32-upcast, 1.81x faster (-33.3% VRAM) vs. torch.compile Bregman-Taylor (1.63 ms), and 25.6x faster vs. Chunked-FP32 (23.03 ms). Real end-to-end 1.7B LLM LoRA post-training (3 seeds each): On Qwen3-1.7B (V=151,936), Fused Triton is fastest overall at 25.1 ms/step (1.25x faster end-to-end, -754 MB VRAM vs. FP32-upcast 31.4 ms/step) with 0.0% negative/dead tokens vs. 13.8% negative (BF16 F.kl_div) and 18.3% dead gradients (Clamped). On SmolLM2-1.7B (V=49,152), Fused Triton is both fastest (18.7 ms/step) and lowest-VRAM (4616 MB vs. 4862 MB FP32), eliminating 30.2% negative-KL tokens and 34.1% dead-gradient tokens. Web preprint & reproducible artifacts: https://spaceresearch.ai/papers/pytorch-kl-bregman-stability.html
No takes yet. Share an insight, caveat, or question.
Marcio Diaz (2026) studied this question.
Synapse has enriched 8 closely related papers on similar clinical questions. Consider them for comparative context: