Repository navigation
searches: standalone overhead demo for MultiStartGradient NaN accounting - #127
Merged
Merged
Conversation
PyAutoFit#1472 adds per-step value-NaN / gradient-NaN lane accounting to MultiStartGradient. This measures whether that costs run time, against a real lens likelihood rather than a toy objective. The feature ships unconditionally, so there is no flag to A/B inside one process and a standalone script cannot hold two library versions. Instead the two halves are measured separately and divided: a real jitted vmapped value_and_grad step as the denominator, each accounting variant as the numerator. Includes a duplicate-baseline CONTROL run. Without it the script could only report "we measured no impact", which is unfalsifiable; with it, it reports an overhead against a measured noise floor -- a claim that can fail. Records the counter-intuitive result the design turned on: reducing gradient finiteness on device but OUTSIDE the jit is the WORST option, not the best, because an un-jitted reduction costs a kernel dispatch plus a host round-trip to save a few KB that were never the bottleneck. Refs PyAutoLabs/PyAutoFit#1472 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The first version differenced two end-to-end loops. On a real lens likelihood that puts a ~4us effect and a ~1s step on the same stopwatch: the run-to-run jitter (~10-35ms) is ~1000x the signal, so variants came out NEGATIVE -- faster than a baseline doing strictly less work -- and the verdict line would have called a 9ms regression "below the noise floor". Measure the numerator directly instead: the accounting op on a cached gradient at microsecond resolution, with Python call overhead measured by a _noop control and subtracted, divided by the separately-measured real step cost. The end-to-end loop stays as a labelled sanity check that now reports its own resolution and states that it bounds rather than measures. `fused` is measured on a proxy objective at the real array shapes, because differencing the two real jitted calls hits the same resolution wall. Its cost is a property of the shapes, not the likelihood. Documented as an upper bound on the reduction in isolation. Local CPU (mge, 16 starts, 1.03s/step): fused 4.1us (0.00039% of a step), host 7.0us, eager 29.4us. Ordering stable across three independent runs; magnitudes move ~50% between CPU runs. Also adds per-rep progress output -- the run is many minutes on CPU and a silent process is indistinguishable from a hung one. Refs PyAutoLabs/PyAutoFit#1472 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
A standalone demonstration that the per-step value-NaN / gradient-NaN accounting added in PyAutoLabs/PyAutoFit#1473 does not cost run time, measured against a real lens likelihood rather than a toy objective.
Result (local CPU,
mge, 16 starts, ndim 15, 1.03 s/step):The counter-intuitive ranking is the point:
eagerlooks like the obvious optimization overhost— it shrinks the transfer from(n_starts, ndim)floats to(n_starts,)bools — and is in fact the worst, because an un-jitted reduction buys a kernel dispatch plus a host round-trip to save a few KB that were never the cost. That inversion is what selected the shipped design.Design note: why this is not a before/after diff
The feature ships unconditionally, so there is no flag to A/B inside one process and a standalone script cannot hold two library versions. The script measures the two halves separately and divides: the accounting op on a cached gradient at microsecond resolution as the numerator, the real jitted vmapped
value_and_gradstep as the denominator.The first version instead differenced two end-to-end loops, which put a ~4 µs effect and a ~1 s step on the same stopwatch. Run-to-run jitter (~10–35 ms) was ~1000× the signal, so variants came out negative — faster than a baseline doing strictly less work — and the verdict line would have called a 9 ms regression "below the noise floor". That loop is retained as a labelled sanity check which now reports its own resolution and states that it bounds rather than measures.
A duplicate-baseline control run is included deliberately. Without it the script could only report "we measured no impact", which is unfalsifiable; with it, it reports an overhead against a measured noise floor — a claim that can fail.
Caveats (stated in the script and the README)
fusedis measured on a proxy objective at the real array shapes, because differencing the two real jitted calls hits the same resolution wall. Its cost is a property of the shapes, not the likelihood. This is an upper bound on the reduction in isolation; XLA's fusion into the real backward pass is not captured.hostvariant's true cost — a device→host copy is a same-address-space memcpy there. A GPU row is still owed, and is the reason to run this on the laptop GPU and then the A100 (whose faster likelihood shrinks the denominator and so inflates the overhead fraction — the conservative case).Test Plan
ruff check+ruff format --checkclean (the PR gate)AUTOLENS_PROFILING_SMOKE=1(imports + setup, exit 0) and added to the smoke list inlint.ymlresults/searches/multi_start_nan_accounting/jax_enable_x64set explicitly — it is not inherited undersbatch, and float32 would halve the gradient array, understating the exact quantity under test)Related but distinct:
scripts/misc/hazards/checks/nonfinite_gradient.pydetects non-finite gradients on a likelihood surface; this measures what it costs to count them during a fit.Generated by the PyAutoLabs agent workflow.