Repository navigation
fix: Fitness rejects implausibly large finite log-likelihoods - #1545
Merged
Merged
Conversation
`Fitness.call` guarded NaN and inf log-likelihoods but passed any finite value straight through, however impossible its magnitude. RAL pilot 341908_5 was killed by exactly that hole: a non-positive-definite regularization matrix made the fp64 Cholesky return finite garbage (log_l up to 3e+303), Nautilus accepted it as its best point, shell_log_l reached ~1e56 and f_live never terminated -- the run was ledgered as "0 calls / thrashes" having in fact made 90,000 calls. Add a magnitude ceiling alongside the existing isnan/isinf `where`s, so any |log_likelihood| above it maps to `resample_figure_of_merit`. It sits inside `call`, so every consumer inherits it: numpy, `_jit`, `_vmap`, Nautilus `n_batch`, BlackJAXNUTS. `af.NSS` samples through its own inline JAX closure rather than `Fitness.call`, so that closure moves into a module-level `nss_log_likelihood_from` factory carrying the same guard -- one implementation, directly testable. The ceiling is read once in `__init__` from `general.test.log_likelihood_ceiling` (default 1e20; null or inf disables) and kept as a static Python float, since the comparison it feeds is traced by JAX and cannot branch in Python. The value is coerced with `float` because PyYAML parses a bare `1e20` as a string. Value-only, exactly like the guards it sits beside: under `jax.grad` both branches of the `where` are differentiated, so this cannot repair a non-finite derivative -- the docstring caveat is extended to say so. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoFQxXV9W59icpEyiGL4eG
This was referenced Aug 29, 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.
Closes #1543.
Summary
Fitness.callguardedNaNandinflog-likelihoods but passed any finitevalue straight through, however physically impossible its magnitude. RAL pilot
341908_5(slam_source_pix_nn, freeAdaptSplitonDelaunayNN) was killed byexactly that hole: a non-positive-definite regularization matrix made the fp64
Cholesky return finite garbage (
log_lup to3e+303), Nautilus accepted it asits best point,
shell_log_lreached~1e56, andf_livenever terminated. Therun was ledgered as "0 calls / thrashes" when it had in fact made 90,000 calls
and reached maxL 30,701.
This adds a magnitude ceiling beside the existing isnan/isinf
wheres, soany
|log_likelihood|above it is mapped toresample_figure_of_merit. It livesinside
call, so every consumer inherits it — numpy,_jit,_vmap, Nautilusn_batch, BlackJAXNUTS.af.NSSsamples through its own inline JAX closurerather than
Fitness.call, so that closure moves into a module-levelnss_log_likelihood_fromfactory carrying the same guard: one implementation,directly testable, and no test that merely resembles the sampled path.
The ceiling is read once in
Fitness.__init__and kept as a static Pythonfloat — the comparison it feeds is traced by JAX, so it cannot be a Python branch
and cannot be looked up per call. The value is coerced with
floatbecausePyYAML parses a bare
1e20as a string (it needs a decimal point or a signedexponent to resolve a float).
Like the guards it sits beside, this is value-only, never gradient: under
jax.gradboth branches of anxp.whereare differentiated, so it cannot repaira non-finite derivative. The existing caveat paragraph in the
calldocstring isextended to say so explicitly.
API Changes
Behavioural, opt-out via config, with no signature or import changes to anything
that existed before:
Fitness.callnow maps a finite|log_likelihood|abovegeneral.test.log_likelihood_ceilingtoresample_figure_of_merit, inaddition to the
NaN/infit already mapped. Default ceiling1e20, which is~15 orders of magnitude above anything a real fit reaches, so no legitimate fit
changes. Setting the key to blank (
null) orinfrestores the previousbehaviour exactly.
general.test.log_likelihood_ceilingin the packagedautofit/config/general.yaml. A workspace whosegeneral.yamlpre-dates thekey inherits the
1e20default rather than losing the guard.autofit.non_linear.fitness.get_log_likelihood_ceiling()reading that key, and
Fitness.log_likelihood_ceilingholding the resolvedstatic float.
af.NSS's inline log-likelihood closure is now built byautofit.non_linear.search.nest.nss.search.nss_log_likelihood_from, with the-1e30sentinel named asNSS_INVALID_LOG_LIKELIHOOD. Same numerics asbefore, plus the ceiling.
Downstream (PyAutoGalaxy / PyAutoLens / the workspaces) needs no change.
Tests
test_autofit/non_linear/test_fitness_assertions.py— numpy path: values abovethe ceiling (both signs) rejected, plausible values (including a real fit's
~3e4) passed untouched, the guard disabled by
inf, theNaN/infguardsstill intact, idempotence against a finite
-1e99resample sentinel, and theconfig reader's coercion (string
"1e20",null, unparseable, non-positive,key absent).
test_autofit/non_linear/test_fitness_ceiling_jax.py—jax.jitandjax.vmappaths,pytest.importorskip-gated.vmapis the load-bearing one:every parameter is a tracer there, so a ceiling that was not a static Python
float would fail even where jit-on-concrete passed. Test values are chosen
inside float32 range so the magnitude guard is what rejects them, not an
overflow to
infcaught by the isinf guard.test_autofit/non_linear/search/nest/nss/test_log_likelihood_ceiling.py— theNSS closure, via the real factory.
Full suite: 2337 passed, 3 skipped.
Notes
The upstream cause of the garbage likelihoods —
Adapt*regularization squaringits coefficient twice (λ⁴), driving the regularization matrix non-PD — is a
separate PyAutoArray task. This guard is the backstop that stops any such
numerical failure from silently burning a multi-hour run, whatever produces it.