Repository navigation
fix(eval): the interval of a Monte Carlo row of widely spread deltas counts its resamples on exact sums - #893
Conversation
…counts its resamples on exact sums (intel#865) For more than 16 changed deltas, ShiftTest.p counted the resamples with a float matrix product, so the small deltas of [1e16] + [1.0] * 19 were absorbed by the large one and the lower end came out as 0.9474 (0.0001 for 1e20 and 1e300) where the exact p puts it at 1.0. The upper end of that row was already right (about 1e16 / 7). When the shifted deltas span more than 40 binary orders, the resamples are now counted on exact integer sums (limbs summed as int64 products, joined as Python ints), with the same draws and the same observed-sum slack as sign_flip_p, so p(0) still equals sign_flip_p for the seed. Rows below that spread keep the numpy product. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 4 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 #893 +/- ##
==========================================
+ Coverage 95.78% 95.83% +0.05%
==========================================
Files 430 442 +12
Lines 57143 58804 +1661
Branches 9853 10148 +295
==========================================
+ Hits 54735 56356 +1621
- Misses 1497 1522 +25
- Partials 911 926 +15
🚀 New features to boost your workflow:
|
The exact resample count passed tied (zero) deltas to the slack, which scales with the number of values, so p(0) could differ from sign_flip_p. It now takes only the moved columns. The limb sums are joined once per distinct row and zero limbs are dropped, so the 1e300 interval no longer exceeds the test timeout. Signed-off-by: vchamarthi <venkata.sai.gireesh.chamarthi@intel.com>
|
🟢 Ready for re-review · 1 commit on Next: a re-review of the new head. Nothing needed from @antonwolfy. Changes
Threads and comments
Verified on the new head: ✅ 1/1 tests fail before the fix, pass after · What each test shows
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: not computed (no receipt profile for this repo, or receipt.py failed)
No blocking finding. Two nits and one question, all on the exact Monte Carlo branch; the two earlier threads (tied deltas, CI timeout) are fixed on head. Lane L1, COMMENT only.
| # | Finding | Label | Provenance |
|---|---|---|---|
| 1 | 1000-delta row: 16.8 s base, 203 s head (probed) | question | introduced |
| 2 | spread exactly 40 moves the lower end by 3e-6; body says it does not | nit | changed |
| 3 | docstring clause cut off | nit | introduced (read) |
Coverage: plain and edge passes (medium); probes of the 1e300, mixed, spread-40 and 1000-delta rows on both trees; the PR's four tests run directly on head. Not looked at: pytest (plugin error), two repo-compare test files, agent-quality job still running.
vchamarthi
left a comment
There was a problem hiding this comment.
🟡 Not approved yet · reviewed dfca446
Next: @antonwolfy: answer 3 open threads from napetrov and settle 1 open question (below). 2 nits optional.
Blocking
- Open question, not answered: thread by @napetrov –
[1e300]plus 999 deltas from1e-8takes 218.9 s throughsign_flip_intervalon the head, against 11.5 s on main, and the PR description has no answer on whether that size is reachable. - Still holds on this head: thread by @napetrov –
[2.0 ** 40] + [1.0] * 19gives lower end 1.0000000000172804 on the head and 0.9999968528920362 on main, so the claim that rows below the spread keep their ends does not hold; the changelog fragment says the same. - Still holds on this head: thread by @napetrov – The module docstring at
sign_flip.py:11still ends its clause withfloats cannot resolve in fewer):. - Open question for @antonwolfy: A 1000-delta row (
[1e300]plus 999 deltas from1e-8in steps of1e-12) takes 218.9 s throughsign_flip_intervalon the head, against 11.5 s on main, with the same lower end, 9.113902524445497e-08. State the cost at 1000 deltas in the Risk section, or bound the exact resamples for large n.
Verified on dfca446: ✅ changed tests: 4 passed, fail on main · ✅ full suite with main merged in: 22843 passed · ✅ merges onto main ·
18 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Monte carlo ends | The four changed tests pass on the head: the 1e16 and 1e300 lower ends are 1.0, p(0) equals sign_flip_p for a mixed-sign row of several limbs under seeds 0 and 3, the tied-zero row matches, and the duplicate deltas of the 20-delta rows are covered |
tests on the head, edge input (collections) |
| Changed tests on main | On main three of the four changed tests fail: the 1e16 and 1e300 lower ends and the mixed-sign row. The tied-zero test passes there. The description says 3 of 3; the file has four tests |
same tests on main |
| Full suite | The full test and lint suite passes with main merged in: 22,843 tests pass and none fail, and the changed-line coverage and mutation steps pass | full suite, main merged in |
| Merge | The branch merges onto current main with no conflict | merge onto main |
| Exact-branch gate | Negating the gate if spread > 40: at sign_flip.py:257 fails the changed tests |
broke the code, tests caught it |
| Exact-branch result | Returning None from the exact branch at sign_flip.py:258 fails the changed tests |
broke the code, tests caught it |
| Near float max | [1.7976931348623157e308] + [1.0] * 19 gives p(0) equal to the exact p on the head; main gives 1.0 |
ran it, edge input (numbers) |
| Zero deltas | [0.0] * 20 gives no p on the head, as sign_flip_p does (None) |
ran it, edge input (numbers) |
| Negative deltas | [-1e16] + [-1.0] * 19 gives p(0) equal to the exact p on the head and on main |
ran it, edge input (numbers) |
| Integer delta | [10 30] + [1] * 19 gives p(0) equal to the exact p on the head; main gives 1.0 |
ran it, edge input (numbers) |
| Empty deltas | [] gives no p on the head, as sign_flip_p does (None) |
ran it, edge input (collections) |
| One delta | [1e300] alone gives p(0) equal to sign_flip_p on the head and on main |
ran it, edge input (collections) |
| Out of order | The 20 deltas of [1e16] + [1.0] * 19 reversed give p(0) equal to sign_flip_p on the head and on main |
ran it, edge input (collections) |
| Very large input | [1e16] + [1.0] * 299 (300 deltas) gives p(0) equal to sign_flip_p on the head and on main |
ran it, edge input (collections) |
| Hash collision | _exact_hits on the pair [1, -1, 1] and [-1, 1, 1] with [3.0, 2.0 60, 1.0] returns 1 on the head, the count of the one row whose sum reaches the observed sum |
ran it, edge input (collections) |
| Limb sums | Twelve random rows of 17 to 40 deltas, each with 1e300 and -3.7e100 among them, give p(0) equal to sign_flip_p for seed 1 on the head, and main does not |
ran it, edge input (int64 limbs) |
| Sixteen deltas | [1e16] + [1.0] * 15 has the same interval ends on the head and on main: (1.0000000168623853, 2000000000000001.0) |
ran it |
| Lower end at 1e300 | [1e300] + [1.0] * 19 has lower end 1.0 on the head; main gives 7.12e-08 |
ran it |
…rrect the spread-40 and docstring text Settles the open points of the review of intel#893. A test feeds `_exact_hits` two rows with the same row hash and different sums and checks it counts each on its own sum. The module docstring clause about the float path is completed. The changelog fragment states that a row that spans about 40 binary orders at 0 can cross the 40-order line as the shift moves and change its lower end, and gives the measured times, including a 999-delta row. The fragment of intel#867 no longer says a row of more than 16 such deltas keeps the float search. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#893 (review)): Its three findings are the threads 4607788090, 4607788101 and 4607788106; each is answered there. |
@vchamarthi (#893 (review)): Its blocking points are the threads 4607788090, 4607788101 and 4607788106, answered there. The nit on the hash-collision branch is 4608555776 and the fragment nit is 4608555782. |
@vchamarthi (#893 (comment)): A recap of dfca446, which settles threads 4607242525 and 4607242847. I checked both at this head; see their replies. |
vchamarthi
left a comment
There was a problem hiding this comment.
🟢 Approved · re-reviewed 5902d57
Next: nothing required from @antonwolfy.
Verified on 5902d57: ✅ changed tests: 5 passed, fail on main · ✅ full suite with main merged in: 23552 passed · ✅ merges onto main · ✅ 4 broken variants of the changed code: 4 caught by the tests · 3 mutations tried
7 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Changed tests | The five tests of tests/test_sign_flip_mc_spread.py pass on the head: the 1e16 and 1e300 lower ends are 1.0 with p(0) equal to sign_flip_p, the mixed-sign row and the tied-zero row match sign_flip_p, and the hash-collision pair counts 1 |
tests on the head |
| Main baseline | On main the changed test module fails at collection, since _exact_hits is not defined there, so none of its tests runs on main |
same tests on main |
| Full suite | The whole local suite passes with main merged in: no test fails, and the changed-line coverage and mutation steps pass | full suite, main merged in |
| Merge | The branch merges onto current main with no conflict | merge onto main |
| Hash collision | Negating the collision check at dokimi/dokimi/eval/sign_flip.py:185 is caught by the changed tests |
broke the code, tests caught it |
| Exact gate | Negating the gate spread > 40 at dokimi/dokimi/eval/sign_flip.py:257 is caught by the changed tests |
broke the code, tests caught it |
| Exact branch result | Returning None from the exact branch at dokimi/dokimi/eval/sign_flip.py:258 is caught by the changed tests |
broke the code, tests caught it |
Summary
#865:
sign_flip_intervalof a row with a delta far larger than the others took its ends from a float search that loses the small deltas. The rows of the issue's text ([m, 1, 1, 1, 1, 1], 6 deltas) are already fixed atmainby #867 (ShiftTest.psums up to 16 widely spread shifted deltas exactly,sign_flip.py). What still goes wrong is the Monte Carlo branch, more than 16 shifted deltas, which counted resamples withsigns @ xin floats. Onmain, withp = sign_flip_p(row)of 5e-05:main[1e16] + [1.0] * 19[1e20] + [1.0] * 19[1e300] + [1.0] * 19The upper end of these rows was already right (about
m / 7; the exact p at 1.4e15 is 0.081 and at 1.43e15 it is 0.030), so only the lower end changes. A mixed-sign row of 19 deltas from -1e30 to 1e20 also hadShiftTest(row).p(0.0) == 1.0onmain, against 0.8906 fromsign_flip_p.The issue offers two fixes: sum exactly in
ShiftTest.p, or bisect on the exactsign_flip_p. This takes the first for the Monte Carlo branch only where it is needed: when the shifted deltas span more than 40 binary orders (the test the exact branch uses), the resamples are counted on exact integer sums with the same draws. Rows whose shifted deltas stay at or below that spread at every shift the search tests keep the numpy product and are unchanged.Closes #865
Changes
dokimi/dokimi/eval/sign_flip.py:ShiftTest.pcalls the new_exact_hitsin its Monte Carlo branch whenspread > 40. It reuses_as_integersand_observed(the slack ofsign_flip_p) and the_drawssigns, sop(0)equalssign_flip_pfor the seed. The integers are split into limbs that cannot overflow int64 over all the deltas, each limb is summed as an int64 product, and the limbs are joined as Python ints. No float sum is used. TheShiftTestand module docstrings say so in place of "more of them are not (sign_flip_interval: the ends of a row with one delta far larger than the others come from a float search that loses the small deltas #865)".dokimi/tests/test_sign_flip_mc_spread.py: the 20-delta rows with 1e16 and 1e300 (lower end 1.0,p(0)equal tosign_flip_p), and a mixed-sign row with several limbs, a row of tied deltas, and two rows that share a row hash (the collision fallback of_exact_hits).Risk
Rows of more than 16 shifted deltas that span more than 40 binary orders at a shift the search tests get new lower ends (the exact ones); every other row gives the same ends. The boundary is per shift, not per row:
[2.0 ** 40] + [1.0] * 19spans exactly 40 at 0 but more once the shift moves, and its lower end is 1.0 on this branch against 0.9999969 onmain. Those rows are slower to search:sign_flip_intervalof[1e16] + [1.0] * 19takes about 0.2 s, and of[1e300] + [1.0] * 19about 4 s (it was under 0.1 s), since the limb count grows with the spread. The cost also grows with the number of deltas:[1e300]plus 999 deltas from 1e-8 in steps of 1e-12 takes about 160 s here, with lower end 9.1139e-08. The exact sums are not bounded in this PR; the number is stated for rows of that shape (one delta of 1e300 beside a thousand near 1e-8). The ends are the same from run to run. The fragment of #867 now says such a row is searched on exact sums too.Testing
On a Linux review host, at
5902d57(onmain7125813):make ci-local: 36 passed, 0 failed, 14 skipped (docker/network catalog smoke, the pinned Claude Code, test-latest, deploy jobs, conda-forge, fuzz, the intel-ci matrix, semgrep). 22783 tests passed, 19 skipped; changed-line coverage 100%.main's code the new test file fails 3 of 3: the lower end is 7.1e-08 for1e300and 0.9474 for1e16where 1.0 is exact, and the mixed-sign row'sp(0)is 1.0 against 0.8906._exact_hitsnegated (the call returns 0, not 1) and the file's other four tests pass; the changed lines of_exact_hitsare all covered.[2.0 ** 40] + [1.0] * 19: lower end 1.0000000000172804 on this branch (0.9999968529 onmain, as measured in the review).spread > 4000) fails the lower-end assertion; dropping the+ 1of the exact p fails thep(0)assertion; a raised threshold in_exact_hitsfails the lower-end assertion; ignoring the sign of a delta in the limbs fails the mixed-sign test. The mutation job ofci-localleaves 8 survivors on changed lines, equivalent or not worth an assertion: negating every limb sum (absfollows), the limb width 62 to 63, thespread > 40threshold to 41, and the first-limb index.fix/score-cv-overflowonmainb62613a:pytest -n auto22866 passed, 19 skipped,mypyclean,ruff checkclean.Open questions
None.
Revert
A plain revert restores the float search for Monte Carlo rows of widely spread deltas. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)