perf: windowed numba fast path for the kernel-CDF forward transform - #458
Merged
Conversation
…numpy branch) The RectangularAdaptDensity kernel-CDF forward transform dominates the numba CPU likelihood (euclid 1.66 s = 55% of the eval; hst 27 s = 89%): an O(M x N) blocked erf broadcast with ~126 MB per-block temporaries, rebuilt every evaluation. The numpy branch of F_raw now evaluates each dimension's weighted kernel CDF with a numba kernel over sorted points + weight prefix sums and a +-9-bandwidth saturation window — same values to ~1e-13 (dropped tail terms < 1e-19 of the weight sum), 3.0-3.4x on the step. The blocked numpy implementation remains the JAX branch and the differentiable reference; the sort is internal evaluation order on the gradient-free numpy path only, preserving the module's no-sorts differentiability guarantee where it matters. Validated: autolens_profiling pixelization_numba pins PASS at euclid + hst (euclid eval 3.08 -> 1.17 s, hst ~30 -> 10.1 s on a 4-core container, stacked with the merged #453/#455 wins); test_autoarray 1036 passed (+2 new dense-reference equivalence tests, weighted and unweighted, with out-of-range queries exercising the saturated tails). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vcc7MUBMnNU6n8qqS9ioVZ
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.
Closes #457.
What
The
RectangularAdaptDensitykernel-CDF forward transform dominates the numba CPU likelihood on the default Rectangular route — 1.66 s = 55% of a euclid eval, 27 s = 89% at hst (PyAutoLabs/autolens_profiling#151): an O(M×N) blocked erf broadcast with ~126 MB per-block temporaries, rebuilt every evaluation (the traced grid moves with the mass model, so nothing can be memoized across evals).One file of source change (
inversion/mesh/interpolator/rectangular.py): the numpy branch ofF_rawnow evaluates each dimension's weighted kernel CDF with a numba kernel (_kernel_cdf_dim_windowed) over sorted points + weight prefix sums, using a ±9-bandwidth saturation window — points below the window contribute exactly their weight via the prefix sum, points above contribute zero, and only the window is summed witherfc. Dropped tail terms are < 1e-19 of the weight sum, so values match the exact blocked sum to ~1e-13 (fp accumulation noise).Differentiability guarantee preserved: the module's "no sorts anywhere" invariant is a JAX-gradient property; the sort here is internal evaluation order on the gradient-free
xp is npbranch only, and the blocked numpy implementation remains the JAX branch and the differentiable reference.Results (4-core cloud container)
pixelization_numbapinned log-likelihoods pass at rtol 1e-6.Testing
test_autoarray/inversion/pixelization/interpolator/test_rectangular.py(weighted + unweighted, atol 1e-12, with out-of-box queries exercising the saturated tails).test_autoarray/1036 passed, 51 skipped; only the 3 pynufft transformer tests that fail identically on stockmainin this environment.Downstream
No public API change; JAX path untouched; interferometer and all other meshes untouched. Likelihood values shift at the ~1e-13 level (below the solver's own bistability).
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vcc7MUBMnNU6n8qqS9ioVZ
Generated by Claude Code