Repository navigation
fix(ep): release each factor search's internals so JAX executables are collectable - #1634
Merged
Merged
Conversation
…e collectable EP keeps every factor step's Status in EPHistory, and each Status pins its Result. The Result's in-memory search internal (the nautilus/dynesty sampler) holds the Fitness, and under JAX the Fitness holds every compiled likelihood executable of that search. Nothing in EP reads the sampler afterwards, so an N-factor x M-step run retained N*M sets of executables: slope_hierarchy_scale job 342410 (25 factors, 64 GB) held 76 searches' executables after ~3 steps and died with `LLVM ERROR: Unable to allocate section memory!`. `AbstractSearch.optimise` now calls the new `Result.release_search_internal()` before pinning the result on the Status. The `search_internal` property keeps its contract (it falls back to the on-disk dill); child results of a CombinedResult, which share the same sampler object, are released too. Regression test (dynesty, JAX-free): two optimise calls on one AnalysisFactor leave no Fitness alive and `status.result._search_internal is None`, while `.projected_model` / `.samples` / `.model` still resolve. 5-factor JAX Nautilus witness over 4 EP steps: live Fitness 5 -> 12 and RSS 529 -> 633 MB on main; 0 and flat at ~463 MB with the fix. Follow-ups filed in PyAutoMind: analysis-level compile cache across EP steps; vmap(jit) recompiling per Nautilus batch length. Refs PyAutoFit#1631 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HHD38RW1y1VFEvjd7QutS
This was referenced Sep 17, 2026
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
Closes #1631.
An EP run keeps every factor step's
StatusinEPHistory, and eachStatuspins itsResult. TheResult's in-memory search internal (the nautilus / dynesty sampler) holds theFitness, and under JAX theFitnessholds every compiled likelihood executable of that search through its per-instance_vmap/_jit/_gradcaches. Nothing in EP reads the sampler afterwards, so an N-factor × M-step run retained N·M sets of executables: slope_hierarchy_scale job 342410 (25 factors, 64 GB) held 76 searches' executables after ~3 steps and died withLLVM ERROR: Unable to allocate section memory!.AbstractSearch.optimisenow calls the newResult.release_search_internal()before pinning the result on theStatus. Child results of aCombinedResultshare the same sampler object, so they are released too. Ordinarysearch.fit()is untouched.Cross-step compile reuse and the
vmap(jit)batch-length recompiles are real but secondary (a compile is ~2–3 s of an ~8 min factor search); both are filed as follow-up prompts in PyAutoMind, alongside a latent bug found while building the witness (af.Nautilusas an EPdefault_optimiserreadsanalysis._use_jaxunguarded and crashes onPriorFactors).API Changes
No signature changes. One behavioural change on the EP path only: after
optimise,status.result.search_internalis served from the on-disksearch_internal.dill(or isNonewhenoutput.search_internalis off in config) rather than from memory. No consumer in this repo reads it; downstream EP callers were not checked.See full details below.
Test Plan
test_autofit/graphical/test_ep_release_search_internal.pyfails onmain(assert 1 == 0liveFitness;_search_internalis aMultiEllipsoidSampler) and passes with the fixpython -m pytest test_autofit -qserially: 2858 passed, 2 skippedtest_autofit/graphical+non_linear/test_jax_compile.py+non_linear/test_fitness_jax_dispatch.py+non_linear/resultserially: 333 passedEvidence: 5-factor JAX witness
5
AnalysisFactors,af.ex.Analysis(use_jax=True),af.Nautilus(n_live=50, n_batch=10, number_of_cores=1)per factor,LaplaceOptimiseron the prior factors, 4 EP steps,JAX_PLATFORMS=cpu, ~3.5 min per run. LiveFitnesscounted viagc.get_objects()after each step.Note on the test: a weakref on
Fitness.__init__alone cannot probe this, because a dynesty search that resumes from its checkpoint restores the sampler by unpickling and the restoredFitnessnever passes__init__; the test therefore counts liveFitnessobjects as a delta against a pre-measured baseline.test_autofit/graphicalandtest_autofit/non_linear/searchare already flaky underpytest -n autoonmain(the autousedo_remove_outputfixture wipes the sharedtest_autofit/outputacross workers); serial runs are clean.Full API Changes (for automation & release notes)
Removed
Added
autofit.non_linear.result.Result.release_search_internal()— drops the in-memory sampler reference on the result and on itschild_results; thesearch_internalproperty keeps its on-disk fallback.Changed
autofit.non_linear.search.abstract_search.NonLinearSearch.optimise— callsresult.release_search_internal()(guarded withgetattr) beforestatus.result = result.Migration
latest_resultshould enableoutput.search_internalin config and read it through thesearch_internalproperty, which loads the dill.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_018HHD38RW1y1VFEvjd7QutS
Generated by Claude Code