Repository navigation
Add matched-stopping precision experiment prep - #291
Merged
Merged
Conversation
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
This is the prep half of #209: a self-contained experiment script plus a README for the CUDA run, no results and no
docs/guides/validation.mdchanges yet (those land once the CUDA run's numbers exist)..context/issue-209/precision_experiment.pyruns the f32-vs-f64 precision contrast and the Fortran-vs-torch implementation contrast under matched stopping, per the issue's design-decision comment: every arm runs to an identical fixed iteration budget (default 2000 and 6000) with every early-stop path disabled, so precision is the only variable in the precision contrast.It also runs an unconstrained diagnostic (default stopping, capped at the largest budget) that records whether/when/why each precision would have stopped early on its own, per the issue's second comment, which asks for that behavior to be reported as a candidate float32 finding rather than engineered away.
.context/issue-209/README.mdgives the one command for the CUDA box, a runtime estimate, and an analysis plan mapping the future results onto the specific confounded rows they replace (docs/guides/validation.md:278-284, the k=152 table) and the rows that are not confounded (docs/guides/validation.md:200-204, the k=30 claim) plus the JOSS paper's LL claim (paper.md:119).Design notes
Suppressing every AMICATorchNG early-stop path needs no monkeypatching, which the issue's second comment asked to check:
use_min_dll=False/use_grad_norm=Falsedisable the two standalone per-iteration checks.Of the two unconditional decrease-branch checks,
min_nd=-1.0is genuinely unreachable (a vector norm is never negative);minlrate=-1.0(not0.0, see "Review round 1 fixes" below) closes the other, since lrate is provably always>= 0.The Fortran binary takes the mirror-image four param-file overrides;
amica15.f90:1058has the identical unconditional decrease-branch check, confirmed by reading the reference source directly.Component correlation reuses the repo's established Hungarian-matched row-normalized-cosine convention (
validate_implementations.py/benchmarks/benchmark_decompose.py), not a fresh metric.A finding from the smoke run
The initial CPU smoke test at a too-small k produced a silent all-NaN Fortran fit (LL stuck at exactly 0.0, exit code 0, no error message):
amica15's fixed-block-size path splits frames acrossmax_threadsOpenMP segments before chunking each segment byblock_size, and ifblock_sizeexceeds one segment's length the run silently degenerates.Bisected directly (frames=5120, threads=4: block_size=1280 gives a real fit, block_size=1281 gives all-NaN).
The script clamps
block_sizeto at mostframes // threadsfor the Fortran call only (torch has no such per-thread split and is unaffected).This is a real amica15 behavior worth knowing for anyone else driving the reference binary at small data/high thread counts, not a bug in this script, and is documented in the script's comments.
Review round 1 fixes
Two correctness gaps in the matched-stopping guarantee, found by review before the unattended CUDA run:
CRITICAL -- Fortran NaN detection had a blind spot.
amica15.f90:1054("Got NaN! Exiting") and:1060("minimum change threshold met") print to stdout only, with nowrite(20,...)twin, while the min_dll/grad_norm messages at:1083-1085/:1094-1095are written to both.The script previously scanned only
run_out/out.txt, so a NaN'd Fortran arm parsed as a cleanmax_iterstop withfinal_ll=nan, which passed the olddegeneratecheck (nan == 0.0isFalse) and could reach_match_correlationwith a NaNW.Fixed by also scanning the already-captured
res.stdoutfor_STOP_MESSAGES, and by broadeningdegenerateto includemath.isnan(final_ll)as an independent second check.IMPORTANT --
minlrate=0.0was not actually unreachable. float32lrateunderflows to an exact0.0after ~147 consecutive LL-decrease halvings (lratefact=0.5applied on every decrease), which is plausible well within a 2000-6000 iteration budget; at that pointlrate <= 0.0fireslrate_floormid-"matched" run, reproducing the exact confound #209 exists to kill.Fixed by using
minlrate=-1.0on the torch side (lrate is provably always>= 0) and"minlrate -1.000e+00"in_write_fortran_param(theE15.3field reads scientific notation cleanly;min_grad_normstays at itsF15.12-field0, which was already genuinely unreachable).Also gated
precision_correlation/implementation_correlationrow inclusion onstop_reason == "max_iter"in addition to not-degenerate, so any early stop that somehow survives the suppression is excluded from the aggregates rather than silently averaged in.IMPORTANT -- implementation-contrast block-size confound. The Fortran arm's per-thread block-size clamp (above) can land below the validated 512-8192 range on a many-core box while torch keeps the full requested
block_size, so a low implementation-contrast correlation could be a block-size artifact rather than a genuine Fortran-vs-torch difference.threadsis now recorded in_config_header, andfortran_block_size/threadsare recorded on everyimplementation_correlationrow and printed in the run's summary output (not only the raw JSON), with an explicit "BELOW FLOOR" flag when the clamp lands under 512.README item 3 now states this caveat explicitly.
Also added two one-line README caveats: CUDA kernel non-determinism is uncontrolled (no
torch.use_deterministic_algorithms), so an anomalous single-seed dip should be checked against a re-run before being attributed to precision; and preprocessing (mean removal, sphering) always runs in float64 on CPU regardless of--device/precision, so the precision contrast is strictly about the EM iterations.Smoke-run evidence (CPU, small budget, post-fix)
A second, wider smoke pass (
--budgets 15,25 --seeds 0,1 --k-values 5,10, 24 matched runs across both k values, both budgets, both seeds) also completed clean: all 24 matched runs stopped viamax_iter, zero degenerate, precision mean|corr|=1.0000, implementation mean|corr|=0.9969 (min 0.9954),threads=14,fortran_block_size in [365, 731](365 flagged below floor, 731 not).Test plan
uv run ruff check .context/issue-209/precision_experiment.pyandruff format --checkclean.uv run ty check .clean (.context/**is excluded fromtyproject-wide, perpyproject.toml, but confirmed anyway).max_iter(confirms stop suppression actually holds, including after theminlrate=-1.0fix) and non-degenerate correlations.git statusafter the run is clean (no stray output files land in the repo tree;--outdefaults next to the script for the real CUDA run).docs/guides/validation.mdrewrite are follow-up work per the approved plan.Partially addresses #209.