perf: batched transform_mapping_matrix in TransformerNUFFT (single nufft2d2 call)#305
Merged
Merged
Conversation
…fft2d2 call) The previous implementation looped over each source-pixel column in Python, scattering each into a (N_y, N_x) image and calling _forward_native separately. Under jax.jit this fully unrolled into n_src distinct nufft2d2 invocations in one trace, ballooning the JIT graph for pixelization-heavy fits — most visibly the rectangular_dspl JAX-likelihood script, where two source planes with mesh_shape=(30,30) gave 1800 inlined NUFFTs and caused 11+ minute slow-compile warnings (and OOM on 16 GB hosts). The replacement scatters all columns into a single (n_src, N_y, N_x) batched array and calls nufft2d2 once with batched f. nufftax natively supports the batched form. Numerical results unchanged (existing test_transformer.py passes); the JIT graph drops from O(n_src) NUFFTs to a single batched NUFFT call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
TransformerNUFFT.transform_mapping_matrixpreviously looped over each source-pixel column in Python, scattering each into a(N_y, N_x)native image and calling_forward_nativeseparately. Underjax.jitthis fully unrolled inton_srcdistinctnufft2d2invocations in a single trace, ballooning the JIT graph for pixelization-heavy fits.This was most visible on
autolens_workspace_test/scripts/jax_likelihood_functions/interferometer/rectangular_dspl.py: two source planes withmesh_shape=(30, 30)gave 1800 inlined NUFFTs in the JIT trace and caused 11+ minute slow-compile warnings + OOM on the 16 GB CI box.The replacement scatters all columns into a single
(n_src, N_y, N_x)batched array and callsnufft2d2once with batchedf.nufftaxnatively supports the batched form. The JIT graph drops from O(n_src) NUFFTs to a single batched NUFFT call.API Changes
None. The method signature, return shape (
(M, n_src)), and numerical result are unchanged.Test plan
pytest test_autoarray/operators/test_transformer.py— 8/8 passpytest test_autoarray/— 750/750 passblack --checkcleaninterferometer/rectangular_dspl.py(with mesh reduced to 8x8) compiles in seconds and produces the same canonical likelihood as the old loop implementationCompanion PR
autolens_workspace_testwill follow with the JAX-likelihood cross-check that exercises this fast path end-to-end.🤖 Generated with Claude Code