Repository navigation
fix(eval): the sign-flip interval of deltas near the float maximum scales instead of overflowing - #770
Open
antonwolfy wants to merge 3 commits into
Open
fix(eval): the sign-flip interval of deltas near the float maximum scales instead of overflowing#770antonwolfy wants to merge 3 commits into
antonwolfy wants to merge 3 commits into
Conversation
…ales instead of overflowing (intel#725) The interval search starts each end at about twice the largest delta and sums sign patterns of the shifted deltas, so for deltas such as [1e308, 0.0] the far bound, the shifted deltas or the matmul sums left the float range: a RuntimeWarning (invalid value encountered in matmul) under -W error, and a nan in the comparisons without it. When the largest delta is above max float / (8 * n), sign_flip_interval now divides every delta by a power of two (exact), runs the same search with EPS and TOL divided the same way, and multiplies each end back. An end the float range cannot hold is None (open), never inf. Rows below the threshold run the search unchanged. sign_flip_p, computed on the unscaled deltas, neither warns nor gives a wrong value at 1e308. test_repo_compare_overflow.py: twelve deltas of plus and minus 1e307 were refused by sign_flip_summary only because the interval search overflowed; the search now runs, so the test expects the summary instead of the CompareError. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #770 +/- ##
=======================================
Coverage 95.72% 95.72%
=======================================
Files 415 415
Lines 55363 55386 +23
Branches 9516 9520 +4
=======================================
+ Hits 52994 53019 +25
+ Misses 1466 1465 -1
+ Partials 903 902 -1
🚀 New features to boost your workflow:
|
…airwise Settles the three Python 3.11 CI failures of test_sign_flip_summary_shifts_deltas_near_the_range_on_a_scaled_copy. The test listed six +1e307 deltas and then six -1e307; checked_mean adds them with sum(), which compensates only from Python 3.12, so on 3.11 the left-to-right partial sum of 6e307 rounds and the mean came out as -2.079e290 instead of 0.0. The deltas now alternate, so every order of summation gives exactly 0.0 and the test checks the scaled interval search on any Python. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
exai-bot
reviewed
Nov 14, 2026
Contributor
Author
|
Review points answered at Follow-up issues opened:
codecov has not reported on this head yet. |
sign_flip_row([1.7e308]*3 + [1.5e308]*3, exact=False) gave p 0.875 and ends (0.0, 1.7e308): the pattern sums went to inf/nan in sign_flip_p, and its p placed 0 inside the interval. sign_flip_p now divides the deltas by the same power of two as sign_flip_interval. Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
Contributor
|
Pushed 1 commit to
The PR description needs these corrections:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The sign-flip interval search starts each end at about twice the largest delta and sums sign patterns of the shifted deltas, so for deltas near the float maximum it leaves the float range (#725). On
main:sign_flip_row/_describe_deltasonmain[1e308, 0.0]RuntimeWarning: invalid value encountered in matmulateval/sign_flip.py:141(an error under-W error)[1.7e308, 0.0],[max, 0.0][max, -max]sign_flip_row;_describe_deltasrefuses it, the magnitudes sum past the range)[max, 1, 1, 1, 1, 1]throughsign_flip_summaryWithout
-W errorananflows through the comparisons, so the ends are silently wrong.repo compare(sign_flip_summary) and the arms track (_describe_deltas) both go throughsign_flip_row->sign_flip_interval, so one fix covers both.Of the two options the issue lists, this takes scaling, not refusing:
check_sum_rangealready lets these deltas through (the sum of their magnitudes is finite), and an open PR on the interaction contrasts asserts that a result comes back for[1.7e308, 0.0]and[max, 0.0], which a refusal insign_flip_rowwould break. When the largest|delta|is abovemax float / (8 * n),sign_flip_intervaldivides every delta by a power of two (exact), runs the same search withEPSandTOLscaled the same way, and multiplies each end back. An end the float range cannot hold isNone(open), neverinf.sign_flip_pruns on the unscaled deltas: it neither warns nor gives a wrong value at 1e308 (plain float sums go toinf, which compares as it should), so it is not scaled.The scaled search gives the right interval for every row tried:
[1e308, 0.0],[1.7e308, 0.0],[max, 0.0]and[max, -max]have open ends (2 deltas); a 6-delta exact row and a 20-delta Monte Carlo row at 1e307 agree with the same rows scaled down by powers of two;[max, 1, 1, 1, 1, 1]has an open upper end because the true end is just past the maximum.Closes #725
Changes
dokimi/dokimi/eval/sign_flip.py:sign_flip_intervalscales as above (_scale_exponent,_scaled_back,_ends);ShiftTesttakes anepsand_endatol, defaulting toEPSandTOL, so the unscaled path is the same call as before. The docstring states that an end beyond the range is open.dokimi/tests/test_sign_flip_float_range.py: rows near the maximum return a dict and warn nothing (sign_flip_rowand_describe_deltas, underwarnings.simplefilter("error")); the ends of a row2**25times larger equal2**25times the ends of the base row (exact and Monte Carlo rows); an end beyond the range isNone.dokimi/tests/test_repo_compare_overflow.py: twelve deltas of plus and minus 1e307 were refused bysign_flip_summary("too large to test") only because the interval search overflowed. The search now runs, so the test expects the summary (finite interval around the mean 0). The deltas alternate in sign:sum()compensates only from Python 3.12, and with six+1e307before six-1e307the 3.11 partial sum rounds, so the mean was-2.079e290on the 3.11 legs. Alternating deltas cancel exactly in any order. The mean of the summary (checked_mean, a plainsum()) still differs by Python version for deltas that cancel only in a compensated sum: tracked in checked_mean returns a rounding residue for deltas that cancel on Python < 3.12 because it uses plain sum() #772.dokimi/docs/benchmarking-and-comparison.md: an end the float range cannot hold is open, neverinf.The
mdeof a spread this large still warns inrepo compare(_roundof an overflowing product): #769.Risk
Rows whose largest
|delta|is at or belowmax float / (8 * n)run the same search as before; scaling by a power of two is exact, so every existing test of the interval passes unchanged. Rows above it used to warn and givenan-driven ends orOverflowError; they now give an interval.repo comparealready drops task values past 1e150, so its CLI output does not change;sign_flip_summarycalled directly on deltas of about 1e307 returns a summary where it raisedCompareError.Testing
On a Linux review host, at
23497de89c0c462a596848668a85e567471188bc(onmain7137604):make ci-local: 0 failed, 33 passed, 14 skipped (docker-needing steps, jobs that do not run on a PR, matrix legs, micromamba, semgrep, fuzz). 20456 tests passed, 19 skipped.python -W erroron[1e308, 0.0]fails atmainwith the matmulRuntimeWarningand returnsp1.0 with open ends here without a warning; the new tests fail onmain's code (12 of 15 failed) and pass here._scale_exponentalways 0) fails 12 of the 15 tests of the new file, and the updatedtest_repo_compare_overflow.pytest; an end that overflows on the way back kept asinfinstead ofNonefailstest_an_end_beyond_the_float_range_is_open(both rows). Not killable:EPSandTOLleft unscaled, and scaling rows below the threshold: scaling is exact, so the ends are the same.-2.0790003224319997e+290reproduces with a left-to-right sum (whatsum()does before 3.12) of the old twelve deltas; the alternating deltas give0.0under that sum, and the test passes withfinite_delta.sumreplaced by it. Mutant:_scale_exponentalways 0 fails the changed test on a copy.Revert
A plain revert restores the old behaviour: the warning and
nan-driven ends for deltas near the float maximum. Nothing is stored.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.md.github/.licenserc.yaml)