{"slug": "finding-overflow-and-nan-edge-cases-in-numerical-code-numguard", "title": "Finding overflow and NaN edge cases in numerical code: numguard", "summary": "Bhaskar Gurram released numguard, an open-source tool that tests numerical array code for edge cases including NaN, ±inf, overflow, subnormals, cancellation and float16/32/64 precision, comparing results against high-precision references in ULPs and checking metamorphic properties such as translation equivariance for logsumexp. numguard runs as a pytest plugin, a CLI or a GitHub Action with NumPy, PyTorch, JAX or CuPy inputs, and is installable via pip install numguard-ci or pip install pytest-numguard. Gurram noted the tool checks functions rather than whole training runs and that its catalogue finds overflow and cancellation more often than subtle precision drift, and asked for reports of missed edge cases such as bfloat16 accumulation and mixed precision.", "body_md": "Numerical bugs in ML code rarely show up in unit tests. A logsumexp that passes on [1, 2, 3] returns inf on [46341, 46342, 46343] in float32. A log_prob that works at scale 1 returns NaN at scale 300 in float16.\n\nI built numguard ([GitHub - bhaskargurram-ai/numguard: Numerical edge-case testing for array code. Runs your functions on NaN, ±inf, overflow, subnormals, cancellation and float16/32/64, and compares them with high-precision references and metamorphic properties. Works as a pytest plugin, a CLI and a GitHub Action. Optional LLM agent suggests fixes that must pass every check. pip install numguard-ci · GitHub](https://github.com/bhaskargurram-ai/numguard)) to test for this systematically. For each function it runs a fixed catalogue of edge cases in float16, float32 and float64: zeros, empty arrays, NaN and ±inf; huge, tiny and subnormal magnitudes; data with a large offset (cancellation). It compares each result with a higher-precision reference, in ULPs, and checks metamorphic properties such as translation equivariance for logsumexp. It runs as a pytest plugin, a CLI or a GitHub Action, with NumPy, PyTorch, JAX or CuPy inputs.\n\nLimits: references have to come from somewhere (SciPy, longdouble, or mpmath for elementwise functions). It checks functions, not whole training runs, and the catalogue finds overflow and cancellation far more often than subtle precision drift.\n\nTry it with pip install numguard-ci, or pip install pytest-numguard for the pytest plugin. I’d especially like to hear about edge cases the catalogue misses for ML workloads, such as bfloat16 accumulation and mixed precision.", "url": "https://wpnews.pro/news/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard", "canonical_source": "https://discuss.huggingface.co/t/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard/190634#post_1", "published_at": "2026-10-15 15:31:37+00:00", "updated_at": "2026-10-15 15:52:48.052825+00:00", "lang": "en", "topics": ["machine-learning", "ai-tools", "developer-tools", "mlops"], "entities": ["Bhaskar Gurram", "numguard", "NumPy", "PyTorch", "JAX", "CuPy", "SciPy", "mpmath"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard", "markdown": "https://wpnews.pro/news/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard.md", "text": "https://wpnews.pro/news/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard.txt", "jsonld": "https://wpnews.pro/news/finding-overflow-and-nan-edge-cases-in-numerical-code-numguard.jsonld"}}