← NeuralDBG

Blog

Post-mortems and analysis of real PyTorch training failures.

Real Bug 2026-06-13 POST-001

Post-mortem: PyTorch issue #41508 — NaN gradients in nn.MultiheadAttention

A real PyTorch bug (open since 2020, 25+ participants) produces NaN gradients when attn_mask and key_padding_mask together leave a row fully masked. We reproduce it, document NeuralDBG's blind spot on composite modules, and confirm the community workaround.

pytorch attention postmortem BUG-001
Real Bug + Fix 2026-07-04 POST-002

The Silent NaN Factory: varlen_attn and the Padding Problem

varlen_attn silently produces NaN gradients when extra padding tokens exceed cu_seqlens. Forward pass looks fine, backward explodes. NeuralDBG traces the NaN to qkv.weight. PR #188933 adds input validation that converts silent corruption into an explicit error — a real fix, not just a test.

pytorchattentionreal-fixBUG-002
Real Bug 2026-07-04 POST-006

Silent NaN Swallowing: When svdvals Lies About Your Data

torch.linalg.svdvals silently returns finite values for NaN input while svd correctly propagates NaN. This inconsistency causes silent gradient corruption in spectral normalization and condition number estimation. PR #188053 — reviewed by albanD (PyTorch collaborator).

pytorchlinalgreviewedBUG-006
Real Bug 2026-07-04 POST-008

The Billion-Dollar Gradient: When F.normalize Silently Corrupts Your Weights

F.normalize on a zero vector returns ~1,000,000,000,000 in backward pass instead of NaN. This happens naturally after dropout or masked attention. Loss looks normal while weights are silently corrupted. PR #188066 — 13 CI failures fixed, tests now pass.

pytorchnormalizationci-fixedBUG-008
Real Bug — Pipeline PASS 2026-07-04 POST-005

LSTM Batch Pollution: One Bad Sample Corrupts the Entire Batch

CUDA nn.LSTM silently corrupts ALL samples when one sample has NaN input — a sample independence violation. NeuralDBG detects it with +24 anomaly gap, traces the causal chain, and the fix returns anomalies to 0. Perfect 0→24→0 detection.

pytorchlstmcausal-chainBUG-005
Real Bug — Pipeline PASS 2026-07-04 POST-003

Gradient Explosion: When Your Model Produces 100,000x Gradients

MPS backend produces gradients 100x-100,000x too large — finite but wrong, invisible to NaN monitoring. NeuralDBG catches the NORMAL→EXPLODING gradient health transition. Full pipeline (detect→chain→fix→validate) achieves PASS.

pytorchmpscausal-chainBUG-003