Repository navigation
Conversation
Keep double-precision working tensors while retaining float32 promotion for half and bfloat16 inputs. Add exact-value regressions for bootstrap bounds and sign-flip p-values, plus dtype controls.
jlarson4
left a comment
There was a problem hiding this comment.
@AaravMehta-07 Thanks for putting this fix together, solid solution. One comment related to a unique case, and one comment pertaining to tightening our tests
| if n_permutations < 1: | ||
| raise ValueError("n_permutations must be >= 1") | ||
| moved = _to_last(effects, dim).float() | ||
| moved = _to_last(effects, dim).to(torch.promote_types(effects.dtype, torch.float32)) |
There was a problem hiding this comment.
Float64 narrows the rounding problem, but doesn't resolve it. _count_hits still compares with bare >=, and the observed and null means are summed in different orders. So sign patterns that tie exactly can still miss by an ulp and give an anti-conservative p-value, e.g. for effects rounded to one decimal. Could you make the comparison tolerant of floating-point ties, the way scipy's permutation_test does, and add a tie case to the tests?
There was a problem hiding this comment.
Thanks, both findings are addressed in 6a83322.
I reproduced the tie undercount with float64 effects [-1.0, 0.4, -0.5, 0.6]: the previous comparator returned 0.75 instead of the exact 0.875. _count_hits now uses SciPy's directional relative threshold, 100 * eps * abs(observed), without an absolute tolerance floor. Regressions cover two-sided/one-sided ties, scaling by 1e-50, and genuinely distinct tiny means. P-value dtype assertions now cover all supported floating inputs and the float64 Monte Carlo path.
With normal repository pytest options and runtime instrumentation: 21 statistics tests, 106 sparse-probing tests, and the real patching statistics consumer passed. Independent verification passed 45 numerical cases; full mypy passed all 393 source files. Formatting and whitespace checks passed; the existing Makefile isort-path warning and separate exact changed-file checks are documented in the updated description. The repair merges cleanly with current dev in a local merge-tree check. Hosted checks for this new head remain separate from these local results; no GPU/full acceptance qualification is claimed.
AI-assisted follow-up. I have left the review threads open for your assessment.
| low, high = bootstrap_ci(torch.ones(8, dtype=dtype), n_resamples=32) | ||
| assert low.dtype == high.dtype == dtype | ||
| assert low.item() == high.item() == 1.0 | ||
| assert sign_flip_permutation_pvalue(x).item() == 0.5 |
There was a problem hiding this comment.
This checks the bootstrap dtype but not the p-value's, so a cast back to float32 on return would still pass. Can you please assert the p-value's dtype here too?
Use a directional relative roundoff threshold without an absolute floor. Cover rounded ties, tiny-scale separation, and p-value dtype retention. Assisted-by: OpenAI Codex
Description
Preserve float64 precision in
bootstrap_ciandsign_flip_permutation_pvalue, and count floating-point ties consistently in the permutation test.torch.promote_types(input.dtype, torch.float32)instead of narrowing intermediate tensors to float32. Half/bfloat16 still use float32 working tensors; float64 p-values remain float64, and bootstrap bounds retain the input dtype.100 * eps * abs(observed), following SciPy's permutation-test convention. There is no absolute tolerance floor, so genuinely different tiny statistics are not merged into ties.The narrowing can change conclusions: constant float64 samples of
1.00000001lose precision; exact effects[1.0, 1e-8]incorrectly produce p=1 rather than 0.5; scaling by1e-50can underflow the effects. The review also exposed a separate tie issue: rounded float64 effects[-1.0, 0.4, -0.5, 0.6]gave p=0.75 instead of the exact-enumeration result 0.875. Both precision issues are now covered.Type Of Change
Validation
1e-50.make format: exit 0. Its existingisort format .recipe reports a missingformatpath, so both changed files were also checked separately with properisort --check-onlyandblack --checkcommands: passed. Notebook formatting was unavailable because Black's Jupyter extra is not installed; no notebooks changed.uv run ... python -m mypy .: no issues in 393 source files.git diff --check: passed.Validation used actual source with CPU runtimes, including WSL Python 3.12. No full acceptance/integration, model-download, notebook, CUDA/MPS or performance suite was run. Initial local consumer runs accidentally disabled pytest addopts; their logs were retained, the runner was corrected, and the passing results above use the normal configuration. No tests or runtime contracts were weakened to address that runner error.
Checklist
Assistance And Scope
AI tools assisted with investigation, implementation, independent review and local testing. This is a CPU statistical-correctness fix; no GPU, pretrained-model parity, performance or model-quality result is claimed.