Zhen Yang and colleagues tested how PyTorch computes KL divergence, a measure of how far one set of probabilities is from another. When the distributions nearly match, rounding can drown out the small difference. A negative value gives the error away, but a positive value can be wrong too.
- Model compression: In one 8-bit test on Qwen2.5-1.5B, PyTorch’s 16-bit loss ranked 19 of 378 layer pairs in the wrong order. The authors got all 378 right against their reference by starting from logits, the model’s raw prediction scores.
- Training a copy: In a synthetic test, identical models should have stayed identical. The stock loss made the student drift. Replacing just the KL arithmetic left the drift unchanged because it came from the backward pass of the probability conversion. The authors’ logits-based calculation kept the weights fixed.
Clamping a negative result to zero hides the warning. If the measurement is what you care about, keep the raw scores and check the result against a higher-accuracy calculation.
Caveat: The usual 16-bit setup still picked the right layers to keep, and the repair made no measurable difference when the Qwen student started from an 8- or 4-bit copy.