TorchLean API

NN.Proofs.RuntimeApprox.Reductions.IEEE32

Reductions #

Deployment-aware reduction semantics for ExecFloat.Binary 8 23.

In deployed environments, reductions (sums / dot-products / matmul accumulations) may be evaluated using different valid parenthesizations and, depending on the implementation, different leaf orders. Since floating-point addition is not associative, distinct reduction schedules can produce distinct results.

This module models a reduction as "any result produced by a valid reduction tree over the same leaves" and proves a standard forward-error enclosure that holds uniformly over all such trees.

What this file proves #

Assuming a local rounded-addition model with parameter u, we derive a global enclosure whose parameters depend only on:

This matches the standard $\gamma_k$-style summation bounds where order-dependence is absorbed by $A$ (sum of absolute values) and a growth factor in n.

For ExecFloat.Binary 8 23, we connect the executable add to the real model fp32Round (a + b), but only on the finite branch. If Inf/NaN/overflow is possible, the right semantics is the special-value semantics from FloatLib, so this file keeps those cases out of scope via FiniteEval*.

This is a direct formalization of standard numerical-analysis results for parallel sums:

Instead of bounding nondeterminism, another design direction is to eliminate it via reproducible accumulators/binned sums. That literature is a complement to this file:

ExecFloat.Binary 8 23: evaluation + nondeterminism (expression tree + permutation) #

FiniteEvalSumTree t means:

  • every leaf is finite, and
  • every internal add evaluates on the finite branch (no Inf/NaN result).

We need this hypothesis when relating the executable semantics to the real model fp32Round (toReal a + toReal b): if an add can overflow to Inf or produce a NaN, the correct semantic layer is FloatLib's special-value semantics, not a small-error enclosure.

Instances For

    Real-valued “finite-branch model” of evalIEEE.

    Every internal node uses fp32Round (a+b). This is the usual floating-point model (round-to-nearest) when the result stays finite; our bridge lemmas justify this model under FiniteEvalSumTree.

    Instances For

      Enclosure theorem for nondeterministic FP32 sums.

      sumTreeResult xs r means: r is the result of adding the elements of xs using executable ExecFloat.add, but with an evaluation order that is allowed to vary (a reduction tree plus a permutation of leaves).

      The conclusion produces a witness tree t and a bound on how far toReal r can deviate from the exact real sum of t’s leaves (measured against the leaf scale sumAbsIEEE t).

      Dot-product accumulation (sum of products) #

      The definitions below model computations such as:

      On real hardware, the sum part is where a lot of nondeterminism creeps in: threads compute partial sums and then reduce them with a tree-shaped schedule. Different valid schedules correspond to different parenthesizations and different orders of the same leaf terms.

      We model that explicitly:

      Two important notes (to avoid over-claiming):

      1. Our enclosure bounds the accumulation error (the rounded adds) relative to the real sum of the already-rounded products toReal (mul x y). If you want a bound relative to the exact real dot product Σᵢ (toReal xᵢ) * (toReal yᵢ), you also need a per-product error bound for mul (provided elsewhere).
      2. Some runtimes use fused multiply-add (FMA) for dot products. ExecFloat.Binary 8 23 has an fma, but this particular model uses the more basic “mul then add” semantics.

      Executable semantics #

      evalDotIEEE is the concrete reduction semantics: it returns an ExecFloat.Binary 8 23 result and therefore includes all IEEE special-value behavior and rounding.

      theorem TorchLean.Floats.IEEE754.IEEE32Exec.dotTreeResult_enclosure (xs : Array (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4 × FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4)) (r : FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4) (hres : dotTreeResult xs r) (u : ) (H : RelativeLocalAddBound (fun (a b : ) => fp32Round (a + b)) u) (hu : 0 u) :

      Enclosure theorem for nondeterministic dot-product accumulation.

      dotTreeResult xs r means: the runtime computed r by taking the array of pairs xs, multiplying each pair, and then summing the products using some reduction tree whose leaves are a permutation of xs.

      The conclusion gives a witness tree t for that schedule and an order-independent enclosure: the accumulation result is close (in $\mathbb{R}$) to the exact sum of leaf products, with the same growth factor bound as in the plain-sum case.