﻿# How can fast-math compilation change the numerical benchmark contract?

A practical investigation of how can fast-math compilation change the numerical benchmark contract?, with explicit observations, control cases and evidence limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/field-bench-fast-math-numerical-contract/
Language: en

## The comparison being tested

A team accelerates an inference preprocessing kernel by changing compiler options and reports an unchanged algorithm. The source expression remains familiar, but the permitted floating-point behavior may have changed. The comparison must establish whether both binaries satisfy the application’s numerical contract before a lower runtime becomes an acceptable optimization. Source-level identity alone does not settle that question.

## The confounding mechanism

GCC documents that fast-math enables several relaxed assumptions, including finite-only arithmetic and transformations that can change floating-point results. Reassociation, signed-zero treatment and nonfinite values matter to different applications. These flags do not imply that every result changes or that every optimized program is invalid. They mean that guarantees relied upon by a strict reference cannot simply be presumed for the candidate.

## Fix the experimental contract

Declare valid input ranges, required handling of nonfinite values, acceptable error and downstream decision requirements before timing. Preserve compiler version, target and effective flags for the kernel and linked numerical components. Use a reference and validator whose own build assumptions preserve the properties being tested. A checker compiled under the same invalid assumptions can fail to observe the intended counterexample.

## A step-by-step comparison

First compare the candidate on representative finite inputs against the stated reference. Next exercise boundary and exceptional inputs required by the application contract, including cancellation-sensitive reductions where relevant. Record value-level differences and downstream decisions separately. Only after correctness qualification should matched timing blocks compare the binaries. Keep excluded input classes explicit rather than silently removing difficult cases after a failure.

## Evidence required for the result

Evidence includes the build manifest, effective flags, retained reference outputs, tolerance rules and every failed qualification case. PyTorch’s comparison documentation illustrates that tolerances and NaN handling are explicit choices, not an automatic definition of application equivalence. A deliberately relaxed fixture should be rejected when it violates a required property, even if its ordinary-input error remains small.

## Interpretation and limits

A finite-input application may legitimately accept relaxed arithmetic after validation; strict bitwise identity is not required everywhere. Conversely, passing an average quality score cannot justify ignoring an exceptional value that changes a critical branch. This protocol does not measure a new speedup or certify compiler correctness. It identifies which numerical obligations the reported speed comparison actually preserved.

## Primary references and related reading

A faster binary is comparable only under an explicit numerical contract that its compiler flags preserve. [GCC optimization options](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html); [PyTorch numerical comparison contracts](https://docs.pytorch.org/docs/2.15/testing.html).

The proposed investigation of fast math numerical contract is not an executed deployment benchmark. Related reading: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Why temperature zero is not enough for deterministic SGLang output](/journal/sglang-deterministic-batch-invariance/).
