cd /news/machine-learning/finding-overflow-and-nan-edge-cases-… · home › topics › machine-learning › article
[ARTICLE · art-150741] src=discuss.huggingface.co ↗ pub= topic=machine-learning verified=true sentiment=↑ positive

Finding overflow and NaN edge cases in numerical code: numguard

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.

read1 min views1 publishedOct 15, 2026

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.

I 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) 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.

Limits: 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.

Try 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.

── more in #machine-learning 4 stories · sorted by recency
── more on @bhaskar gurram 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/finding-overflow-and…] indexed:0 read:1min 2026-10-15 · —