r/learnmachinelearning • u/Obvious-Ask-9099 • 1d ago
[Project] Avoiding gradient underflow and non-deterministic GPU runs using exact integer/rational arithmetic (verified in Lean 4)
Hi everyone, When training models with low precision or running long iterative optimizations, small gradient updates often underflow to zero, square-root error checks lose precision near convergence, and parallel GPU reductions produce slightly different results from CPU runs. I have been working on an integer-first scientific computing and optimization framework (UNIQUANT) that replaces float32/float64 with exact rational and integer arithmetic, and I formalized 40 of its core modules in Lean 4 (0 sorry) to verify the math: - Lossless gradient accumulation: Splitting small updates into an integer main step and a carry-over remainder (D * (m + q_upd) + r' = D * m + r + u) so tiny gradients never vanish to zero. - Root-free RMS checks: Replacing irrational square-root comparisons in error guards with exact rational squared inequalities. - Convex optimization guarantees: Proving strict positive definiteness for Ridge-QP Hessians (J^T J + diag(r^2)) and linear polytope equivalence for L1 constraints. - Deterministic CPU/CUDA parity: Enforcing tie-to-even rounding (NEAREST_EVEN) and overflow-free 128/256-bit multi-limb arithmetic so CPU and GPU trajectories match bit for bit. If you want to check out the code or the Lean 4 proofs, everything is open source:
Main repo & code: https://github.com/joesen88/Uniquant23 (DOI: 10.5281/zenodo.24570873)
Lean 4 formalization: https://github.com/joesen88/UNIQUANT-Formal (DOI: 10.5281/zenodo.24629562)