cd /news/machine-learning/inside-the-sfpu-how-a-40-year-old-ro… · home topics machine-learning article
[ARTICLE · art-125306] src=dev.to ↗ pub= topic=machine-learning verified=true sentiment=· neutral

Inside the SFPU: How a 40-Year-Old Rounding Trick Breaks on Modern AI Accelerators

A developer working on tt-metal, Tenstorrent's ML framework, identified a subtle numerical bug in the SFPU math unit that causes intermediate overflow in floating-point computation chains such as exp(x) * exp(-x). The fix reorders computation to avoid storing intermediate results that exceed the representable range, and the developer notes that round-to-nearest-even rounding can produce small deviations from PyTorch reference values when converting back to fp32 after intermediate fp16/bf16 computation.

by read1 min views1 publishedSep 10, 2026

In my work on tt-metal (Tenstorrent's ML framework), I encountered a subtle but critical bug in the SFPU (SFPU = Tensor Processing Unit math unit) that caused intermediate overflow in floating-point computation chains. Here's what I found.

The SFPU (StochaSTic Processing Unit, or more likely the hardware math unit) handles transcendental functions like exp, log, and softplus on Tenstorrent chips. These functions use polynomial or rational approximations because the hardware does not implement them directly.

Consider a chain of operations: `exp(x) * exp(-x)`. Mathematically this equals 1 for all x. But in SFPU computation:

`exp(x)` is computed and stored as an intermediate result`exp(-x)` is computed`exp(x) * exp(-x)` overflows if the intermediate result exceeds the fp32 range

The fix was to reorder computation to avoid storing intermediate results that exceed the representable range. Instead of computing and storing both exp values, we restructure the computation graph to use algebraic identities that eliminate the overflow.

The SFPU uses a rounding mode called round-to-nearest-even (IEEE 754 default). This is correct, but when converting back to fp32 after intermediate fp16/bf16 computation, the rounding can cause small but visible differences from PyTorch reference values. The trick: add 0.5 before truncation for round-to-nearest, rather than using the hardware rounding mode.

This is a 40+ year old optimization from IEEE 754, but it interacts subtly with the SFPU's internal precision.

Hardware-accelerated ML frameworks are full of these subtle numerical bugs. The fix required understanding both the mathematical properties of the functions and the hardware-level implementation details. Always test against the reference PyTorch implementation with a wide range of inputs — including edge cases like ±0.0, ±inf, and subnormal numbers.

Follow my bug bounty journey: @truongsontung

── more in #machine-learning 4 stories · sorted by recency
── more on @tenstorrent 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/inside-the-sfpu-how-…] indexed:0 read:1min 2026-09-10 ·