Skip to content

fix(eval): the interval of a Monte Carlo row of widely spread deltas counts its resamples on exact sums - #893

Merged
antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:fix/sign-flip-mc-spread
Nov 18, 2026
Merged

antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:fix/sign-flip-mc-spread

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#865: sign_flip_interval of 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 at main by #867 (ShiftTest.p sums 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 with signs @ x in floats. On main, with p = sign_flip_p(row) of 5e-05:

row lower end on main exact
[1e16] + [1.0] * 19 0.9474 1.0
[1e20] + [1.0] * 19 0.0001 1.0
[1e300] + [1.0] * 19 0.0001 1.0

The 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 had ShiftTest(row).p(0.0) == 1.0 on main, against 0.8906 from sign_flip_p.

The issue offers two fixes: sum exactly in ShiftTest.p, or bisect on the exact sign_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

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] * 19 spans exactly 40 at 0 but more once the shift moves, and its lower end is 1.0 on this branch against 0.9999969 on main. Those rows are slower to search: sign_flip_interval of [1e16] + [1.0] * 19 takes about 0.2 s, and of [1e300] + [1.0] * 19 about 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 (on main 7125813):

  • 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%.
  • On main's code the new test file fails 3 of 3: the lower end is 7.1e-08 for 1e300 and 0.9474 for 1e16 where 1.0 is exact, and the mixed-sign row's p(0) is 1.0 against 0.8906.
  • The hash-collision test fails with the check of the fallback in _exact_hits negated (the call returns 0, not 1) and the file's other four tests pass; the changed lines of _exact_hits are all covered.
  • [2.0 ** 40] + [1.0] * 19: lower end 1.0000000000172804 on this branch (0.9999968529 on main, as measured in the review).
  • Mutants, each failing the test named: the exact branch disabled (spread > 4000) fails the lower-end assertion; dropping the + 1 of the exact p fails the p(0) assertion; a raised threshold in _exact_hits fails the lower-end assertion; ignoring the sign of a delta in the limbs fails the mixed-sign test. The mutation job of ci-local leaves 8 survivors on changed lines, equivalent or not worth an assertion: negating every limb sum (abs follows), the limb width 62 to 63, the spread > 40 threshold to 41, and the first-limb index.
  • Not run: the other Python versions (3.11, 3.12, 3.14).
  • Merged together with fix/score-cv-overflow on main b62613a: pytest -n auto 22866 passed, 19 skipped, mypy clean, ruff check clean.

Open questions

None.

Revert

A plain revert restores the float search for Monte Carlo rows of widely spread deltas. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…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>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 17, 2026 21:19
@antonwolfy antonwolfy self-assigned this Nov 17, 2026
@exai-bot

exai-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 4 selected item(s).

CI at 5902d57: 26 passing, 3 skipped.

Review details
  • Commit reviewed: 5902d57 against merge base dfca446
  • Coverage: 4 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 82k tokens (47k from cache), 24s
  • Tool calls: 8 (6 file_read, 1 ci_status, 1 local_check_results)
  • Sign-flip p-value calculations and Monte Carlo spread: 4 files

Comment thread dokimi/dokimi/eval/sign_flip.py Resolved
@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.83%. Comparing base (7125813) to head (5902d57).
⚠️ Report is 20 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     
Files with missing lines Coverage Δ
dokimi/dokimi/eval/sign_flip.py 98.97% <100.00%> (+0.09%) ⬆️

... and 73 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread dokimi/dokimi/eval/sign_flip.py Resolved
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>
@vchamarthi

Copy link
Copy Markdown
Contributor

🟢 Ready for re-review · 1 commit on fix/sign-flip-mc-spread (c79ba9e..dfca446)

Next: a re-review of the new head. Nothing needed from @antonwolfy.

Changes

  • ShiftTest.p passes only the non-tied columns and values to _exact_hits.
  • _exact_hits drops all-zero limbs and sums each distinct row of limb sums once.

Threads and comments

  • 2 fixed; each answered in its thread.
  • Fixed (comment by exai-bot): four failing checks from the 1e300 test timing out – Limb loop sped up as in the reply on _exact_hits.

Verified on the new head: ✅ 1/1 tests fail before the fix, pass after · ⚠️ 1 answered as fixed without a test that shows it · ✅ full suite with main merged in: 22840 passed · ✅ second reader: nothing raised

What each test shows
  • p(0) with tied deltas equals sign_flip_p: fails before, passes after.
  • the 1e300 interval stays exact and now runs in about 6s: passes.
  • Left to GitHub's own checks: agent-quality.yml:external-catalog-smoke, ci.yml:static / pre-commit, ci.yml:static / Install gitleaks, ci.yml:static / Scan commits, ci.yml:fidelity / Install the pinned Claude Code, ci.yml:test-latest, ci.yml:package-smoke, ci.yml:windows-smoke.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread dokimi/dokimi/eval/sign_flip.py Resolved
Comment thread dokimi/dokimi/eval/sign_flip.py Resolved
Comment thread dokimi/dokimi/eval/sign_flip.py Resolved

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 from 1e-8 takes 218.9 s through sign_flip_interval on 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] * 19 gives 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:11 still ends its clause with floats cannot resolve in fewer):.
  • Open question for @antonwolfy: A 1000-delta row ([1e300] plus 999 deltas from 1e-8 in steps of 1e-12) takes 218.9 s through sign_flip_interval on 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 · ⚠️ 4 broken variants of the changed code: 3 caught by the tests, 1 not · 3 mutations tried · 12 edge inputs tried

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

Comment thread dokimi/dokimi/eval/sign_flip.py Resolved
…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>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) Change class: not computed (no receipt profile for this repo, or receipt.py failed)

@napetrov (#893 (review)): Its three findings are the threads 4607788090, 4607788101 and 4607788106; each is answered there.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) 🟡 Not approved yet · reviewed dfca446

@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.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

🟢 Ready for re-review · 1 commit on fix/sign-flip-mc-spread (c79ba9e..dfca446)

@vchamarthi (#893 (comment)): A recap of dfca446, which settles threads 4607242525 and 4607242847. I checked both at this head; see their replies.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@antonwolfy
antonwolfy merged commit 075f939 into intel:main Nov 18, 2026
29 checks passed
@antonwolfy
antonwolfy deleted the fix/sign-flip-mc-spread branch November 18, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants