Migrate mge_gradients.py JAX profiling to pytree inputs#13
Merged
Conversation
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.
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
Migrates
jax_profiling/imaging/mge_gradients.pyto pass aModelInstancepytree throughjit/value_and_gradinstead of a flat 1D parameter vector. Matches the pattern shipped in #11 (mge.py) and #12 (pixelization.py), now thatautofit.jax.register_modelis onmain(PyAutoFit#1220, #1221).Removes
Fitness+Model.instance_from_vectorfrom JIT traces so gradient profiling reflects how a real pytree-native sampler would run.Scripts Changed
jax_profiling/imaging/mge_gradients.py— per-step JIT closures takeparams_tree(built once viajax.tree_util.tree_map(jnp.asarray, instance)) instead of a flatjnp_paramsvector;test_gradhelper tree-flattens the gradient output; PART C full-pipeline gradient now callsAnalysisImaging(use_jax=True).log_likelihood_function(instance=params_tree)in place ofFitness.call; NNLS_diagnose_kappainner loss updated the same way.Test Plan
AnalysisImagingRelated: follow-up to #10.
🤖 Generated with Claude Code