feat: migrate jax_profiling/imaging/mge.py to pytree inputs#11
Merged
Conversation
Replaces the flat 1D parameter vector passed into jit/vmap with a ModelInstance pytree built via autofit.jax.register_model(model). The full-pipeline closure now takes the pytree directly and runs analysis.log_likelihood_function(instance=params_tree) under jit+vmap. Fitness.call and model.instance_from_vector are unchanged — the production path is untouched; this is a workspace-side demonstration of the new opt-in pytree API landing in PyAutoConf #93 and PyAutoFit #1220. Regenerates the corresponding results summary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 16, 2026
5 tasks
Jammy2211
pushed a commit
that referenced
this pull request
Apr 17, 2026
Matches the pattern shipped in mge.py (#11) and pixelization.py (#12): pass a ModelInstance pytree through jit/value_and_grad instead of a flat 1D vector + Fitness/instance_from_vector inside the trace. - register_model(model) once after eager instance build - params_tree = jax.tree_util.tree_map(jnp.asarray, instance) - per-step closures take params_tree and build Tracer from params_tree.galaxies (dropping inner instance_from_vector calls) - test_grad tree-flattens gradient output for statistics - PART C full pipeline uses AnalysisImaging(use_jax=True) .log_likelihood_function(instance=params_tree) in place of Fitness - NNLS kappa diagnostic (_diagnose_kappa) uses pytree params Verified: all 9 gradient tests PASS, all 4 NNLS kappa values report FULLY FINITE GRADIENTS.
4 tasks
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
Replaces the flat 1D parameter vector used by the MGE JAX profiling script with a pytree
ModelInstancebuilt via the newautofit.jax.register_model(model)API. The full-pipeline closure now runsanalysis.log_likelihood_function(instance=params_tree)directly underjax.jit+jax.vmap— noinstance_from_vectorinside the trace.Fitness.callandmodel.instance_from_vectorare untouched, so the production sampler path is unaffected. This is a workspace-side demonstration of the opt-in pytree API landing upstream.Scripts Changed
jax_profiling/imaging/mge.py— register pytrees once, then pass theModelInstancepytree directly intojit/vmap; replacesFitness.call(param_vector)withanalysis.log_likelihood_function(instance=params_tree)viaal.AnalysisImaging(dataset, use_jax=True); updates the vmap section to broadcast leaves withjax.tree_util.tree_mapinstead of stacking a flat vector.jax_profiling/imaging/results/mge_likelihood_summary_hst_v2026.4.13.6.json— regenerated summary from the pytree pipeline.jax_profiling/imaging/results/mge_likelihood_summary_hst_v2026.4.13.6.png— regenerated bar chart.Upstream PRs
Test Plan
python jax_profiling/imaging/mge.pyruns end-to-end on hst instrumentFitImaging.log_likelihood🤖 Generated with Claude Code