Property-Based Testing for Robust Softmax and Cross-Entropy
Muhammad Maaz
Key points
From the paper's conclusion- Overall, this work shows that property-based testing can be a powerful tool for discovering and fixing numerical issues in machine learning libraries.
Abstract
A recent paper of Barron et. al. (2026) identified two numerical issues with the softmax and cross-entropy functions in virtually all standard machine learning libraries (e.g., PyTorch and JAX). We show that these issues can be recovered through simple property-based tests in Hypothesis. However, our tests identify an additional edge case where their implementation fails. We then propose an even more robust softmax implementation which passes these tests and also supports use in causal attention masking. We compare our implementation with theirs and discuss some of the differences. Overall, this work shows that property-based testing can be a powerful tool for discovering and fixing numerical issues in machine learning libraries. Our implementations and property-based tests can be found at https://github.com/mmaaz-git/softmax-fix.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- A Fix for Softmax and Cross-EntropyarXiv · 2026
- On numerical issues of divergences between nearly equal distributionsarXiv · 2026
- The KL Divergence Is Never Negative, Except in PyTorcharXiv · 2026
- Continuum AttentionarXiv · 2026
- Invertible Logits Transformation for Accuracy-Preserving Post-Hoc Uncertainty CalibrationarXiv · 2026
- Language models suffer from a curse of ambiguityarXiv · 2026