interplane.Get Omega
Read in your language

omega-dnn

aien-dev/omega-dnn

Brought by drakestapleton

branch main Branches Tags History

omega-dnn / docs / TOLERANCE.md

150 lines · 10340 bytes Raw Blame History Source

Tolerance contract

The reference is torch float64 on the same f32 inputs. Every output element y of every op must satisfy

|y − ref| ≤ u32·|ref| + 2·γ(n + 64)·M + 2^-149,    u32 = 2^-24,  u64 = 2^-53,  γ(k) = k·u64 / (1 − k·u64)

Numbers, all from Wolfram (WolframLanguageEvaluator, 2026-10-27):

queryresult
N[2^-24, 17], N[2^-53, 17]5.9604644775390625e-8, 1.1102230246251565e-16
N[gam[2^20 + 64], 6] (largest reduction allowed by the loop bound)1.16422e-10
N[gam[2^20 + 64]/2^-24, 6]0.00195324 — the f64 term stays below 0.2% of u32 per unit of M
N[gam[64], 6]7.10543e-15
N[(Log[2]/2)^14/14! * Exp[Log[2]/2], 6] (exp: Taylor remainder after degree 13 on |r| ≤ ln2/2)5.85118e-18
N[Erfc[6], 6] (erf clamps to ±1 for |x| ≥ 6)2.15197e-17
N[72/(2*70 + 3), 6], N[r/(1 - r)*10^-17, 6] (erf series: term ratio at q = 6 once k ≥ 70; tail after the 1e-17 stop)0.503497, 1.01408e-17
N[Product[72/(2 j + 3), {j, 36, 70}], 6] (erf series at q = 6 has not stopped before k = 70)9.25083e-7
N[2^-149, 6]1.40130e-45

The approximation errors of exp and erf (≤ 2.2e-17 relative) are below γ(64), so they sit inside the f64 term. ReLU and MaxPool are exact (measured worst err/tol 0).

Tightness. The u32 term is the binding one: the measured worst err/tol ratio is 0.96–1.00 for every rounding op (tests/test_ops.py output). With every bound halved (OMEGA_DNN_TOL_SCALE=0.5, negative control) the suite reports violations.

Scope. A defect smaller than about one f32 rounding of the output is invisible by construction: for example perturbing the low half of the Cody–Waite ln2 constant. tests/mutants.py lists the mutants that the suite must kill.

GPU tier (tests/test_gpu.py)

The GPU tier runs CUDApp's native GB10 kernels on the same f32 inputs and holds each chip output element y to the omega-dnn host unit h (the gate) and to torch float64 r (a diagnostic):

gate:        |y − h| ≤ T_chip + T_host,     T_host = u32·|r| + 2·γ(n + 64)·M + 2^-149   (contract above)
diagnostic:  |y − r| ≤ T_chip + 2·γ(n + 64)·M + 2^-149

T_chip bounds the kernel against exact arithmetic. Each one below is derived from the kernel source at the pinned CUDApp sha, does not depend on summation order, and was fixed before any chip run. Each also carries an absolute 2^-124 for products that the chip may flush below 2^-126. Notation: u = 2^-24, g(n) = n·u/(1 − n·u) (the f32 γ).

Hardware constants come from PTX ISA 9.4. ex2.approx.f32 is within 2 ulp of the correctly rounded result, which gives at most 5u relative. rcp.approx.f32 is within 1 ulp, which gives 2u. rsqrt.approx.f32 is within relative 2^-22.9, and Wolfram confirms 138·2^-30 ≥ 2^-22.9, so that value is used.

Negative control on chip. Every op runs CUDApp's own test mutants on cases from the same sweep, and each mutant must fail the gate. A mutant joins a case only where it changes the function; an equivalent mutant cannot fail any gate.

Each receipt records, per mutant run, the shape, rc, gate violations, the measured ratio and, for NO_RESCALE, the predicted ratio. A first attention run placed NO_MAX and NO_RESCALE on equivalent cases, and 10 of 32 mutant runs survived. That run is kept in evidence/GPU-9841bb3a/LOSSES.md.

Numbers, all from Wolfram (WolframLanguageEvaluator, 2026-10-27; u, g as above):

queryresult
138/2^30 >= 2^-22.9True
Maximize/Minimize of (1+e)(3/2 − (1+e)^2(1+d1)(1+d2)/2)(1+d3)(1+d4) − 1 over |e| ≤ 138/2^30, |di| ≤ u (rsqrt + Newton)3.0000002384u, −3.0000006522u → use 3.0000007u
Reduce[ForAll[g, 0<g<1/2, (1-g)^(-1/2)-1 <= g/(2(1-g)) && 1-(1+g)^(-1/2) <= g/(2(1-g))], Reals]True
host_exp2: max |P(f)/2^f − 1| on [−1/2, 1/2] with the f32 Cephes coefficients; Horner rounding max g(12)·ΣP|/P1.5920354e-8; 1.4305125e-6; total 1.4464328e-6 = 24.267u → use 25u
(17 2^-25 + 2^-23)/2^-22; c/2^-2221/8; 2.62500
R_rms(128)/u, R_rms(16384)/u11.0000, 74.5012
R_silu(|g| = 4)/u, R_silu(|g| = 80)/u18.0000, 170.003
R_attn(ctx 64, D 64, S 1, Λ 10); R_attn(ctx 4096, D 128, S 16, Λ 10); R_attn(ctx 64, D 64, S 1, Λ 900)1.69597e-4; 9.12223e-4; 1.45434e-2
steps(1), steps(300), steps(2048)29, 191, 1182
(1 + c)^steps − 1 at K = 300, K = 20481.19544e-4, 7.40027e-4

Scope. The bounds are worst case, so measured chip errors sit well below them. The gate proves that the chip result is a correct f32 evaluation of the same math within its own rounding behaviour. It does not prove bitwise agreement, and the mutants show how far it is from vacuous. Ops and shapes with no CUDApp kernel are listed in README.md ("Not on the GPU") as NOT_RUN or unsupported.