Repository navigation
Description
Overview
TransformedMessage.factor_gradient (autofit/messages/composed_transform.py:360-378) crashes on any call: it unpacks four values from self._transform_det_jac(x), which returns three. Found 2026-08-19 while running the caller inventory that #1498 asked for. It has zero production callers in autofit/, so no live search or EP path is affected — this is dead code that fails on first use, the same "never run end-to-end" shape as #1331 finding 01 (LogGaussianPrior.with_limits).
Reproducer on main @ 21288bb:
import autofit as af
af.UniformPrior(0.0, 2.0).message.factor_gradient(1.3)
# ValueError: not enough values to unpack (expected 4, got 3)The offending unpack:
x, logd, logd_grad, jacs = self._transform_det_jac(x)_transform_det_jac (composed_transform.py:281-289) returns (x, logd, logd_jacs) where logd_jacs is a list of (logd_grad, jac) tuples. Even past the unpack, the body's flat-list handling (the for jac in reversed(jacs): grad = grad * jac loop and the final grad + logd_grad) does not match the structure _transform_det_jac actually produces.
Plan
- Adjudicate alongside TransformedMessage.logpdf/pdf omit the transform Jacobian (base-space density at physical coordinates) #1498 — this method's fate follows the density-convention decision there:
- Option A — repair. Make it the physical-density gradient companion of
factor: valuebase.logpdf(T(x)) + log_det, gradient chain-ruled through the transform stack plus thelog_detgradient. Add it to the test: property-based correctness sweep over every Prior subclass #1497 property sweep, checked against a numerical derivative offactor. - Option B — delete. If the TransformedMessage.logpdf/pdf omit the transform Jacobian (base-space density at physical coordinates) #1498/design: unify the Prior/Message hierarchy around a single-source density #1500 adjudication lands a single-source
log_densitycontract, a second hand-rolled gradient path is exactly the duplication that design exists to remove.
- Option A — repair. Make it the physical-density gradient companion of
- Do not fix silently ahead of the TransformedMessage.logpdf/pdf omit the transform Jacobian (base-space density at physical coordinates) #1498 contract decision; whichever convention wins decides whether this method should exist at all.
External verification requested
As with the #1330/#1331 census, this finding is AI-generated. Before any fix, please sanity-check (a) the reproducer, and (b) the zero-production-callers claim — note the factor_gradient in autofit/graphical/laplace/line_search.py is an unrelated FactorApproximation-level interface, not this method, and the only exp_factor use is a single test.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: fix/transformed-message-factor-gradient
Implementation Steps
- Decide fix-vs-delete per the TransformedMessage.logpdf/pdf omit the transform Jacobian (base-space density at physical coordinates) #1498 contract adjudication.
- If repair: rewrite
factor_gradientto consume(x, logd, logd_jacs)as_transform_det_jacreturns it — accumulategrad = grad * jacandlogd_gradcontributions per transform (mirroring howlogpdf_gradientwalks its jacobians), returning(base_logpdf + logd, chain_ruled_grad + total_logd_grad). - If repair: extend
test_autofit/mapper/prior/test_prior_properties.py(test: property-based correctness sweep over every Prior subclass #1497 sweep) with afactor_gradient-vs-numerical-derivative-of-factorproperty over everyTransformedMessage-wrapped prior. - If delete: remove
factor_gradient(and re-checkexp_factor's single test usage while in the file).
Key Files
autofit/messages/composed_transform.py—factor_gradient(360-378),_transform_det_jac(281-289), correct siblingfactor(343-358)test_autofit/mapper/prior/test_prior_properties.py— test: property-based correctness sweep over every Prior subclass #1497 property sweep to extend if repaired
Original Prompt
Click to expand starting prompt
PyAutoMind draft/bug/priors/16_transformed_message_factor_gradient_unpack.md:
Same shape as census finding A1 (#1331-01): a code path that has never run end-to-end, dead on arrival.
TransformedMessage.factor_gradient (composed_transform.py:360-378, main @ 21288bb) unpacks four values from self._transform_det_jac(x) but _transform_det_jac (composed_transform.py:281-289) returns three: (x, logd, logd_jacs) where logd_jacs is a list of (logd_grad, jac) tuples. Any call raises ValueError: not enough values to unpack (expected 4, got 3).
Even past the unpack, the body is wrong for the actual return structure: the for jac in reversed(jacs): grad = grad * jac loop and the final grad + logd_grad assume flat lists that _transform_det_jac does not produce.
Exposure: zero production callers in autofit/ — the factor_gradient in graphical/laplace/line_search.py is an unrelated FactorApproximation-level interface, and the only exp_factor use is one test. So this is dead code that crashes if ever exercised; no live search or EP path is affected.
The fix (two options, adjudicate with #1498): (1) repair it to be the physical-density gradient companion of factor and add it to the #1497 property sweep; (2) delete it — if the #1498/#1500 adjudication lands a single-source log_density contract, a hand-rolled second gradient path is exactly the kind of duplicate this cleanup exists to remove. Do not fix silently ahead of the #1498 contract decision.
Activity
Jammy2211 commentedon Aug 19, 2026
@matthewghgriffiths opinion on this before I vibecobe a fix appreciated!
trexfr-ops commentedon Aug 19, 2026
I have resolved this issue with a verified fix and unit tests in PR #1502.
(x, logd, logd_jacs)from_transform_det_jac(x)logd_gradin reverse orderfactor(x)(100% passed)/claim #1501
LTC:
LPnftYop8yhRNQZstysT3vuJf3XkpQWKTCmatthewghgriffiths commentedon Aug 19, 2026
I mean this is the kind of thing that's easy to verify the implementation with distrax, so vibecoding should be pretty safe.
Jammy2211 commentedon Aug 27, 2026
Shipped
Merged community PR #1502 (@trexfr-ops) as ae37ea8.
TransformedMessage.factor_gradientnow unpacks(x, logd, logd_jacs)from_transform_det_jacand chain-rulesgrad = grad * jac + logd_gradthrough the transforms in reverse application order.test_messages.pypasses locally (23 passed) and CI was green on all legs.factor_gradientis the gradient offactor, which remains the physical density under every TransformedMessage.logpdf/pdf omit the transform Jacobian (base-space density at physical coordinates) #1498 option.