Skip to content

fix: make remaining message and compound-prior xp paths JAX-traceable #1459

Closed

Description

@Jammy2211

Overview

A focused prior/message backend audit performed while fixing #1458 found four additional, independently reproducible JAX tracing failures. Each affected method accepts an xp argument but still calls NumPy/SciPy directly, so a traced value is coerced through __array__ and raises jax.errors.TracerArrayConversionError.

This is not covered by the completed JAX-native prior transforms in #1262 or the NumPy/statistical fixes tracked in #1331.

Confirmed failures

On current main, each of these fails under jax.jit:

  • GammaMessage.log_partition(xp=jnp)
    • uses scipy.special.gammaln(alpha) and np.log(beta)
  • BetaMessage.log_partition(xp=jnp)
    • uses scipy.special.betaln(*self.parameters)
  • Log._instance_for_arguments(..., xp=jnp)
    • ignores xp and calls np.log
  • Log10._instance_for_arguments(..., xp=jnp)
    • ignores xp and calls np.log10

Minimal shape of the reproducer:

jax.jit(
    lambda x: GammaMessage(x + 1, x + 2).log_partition(xp=jnp)
)(jnp.asarray(2.0))

Equivalent JIT calls fail for the other three paths.

Proposed fix

  • Dispatch Gamma/Beta special functions through a JAX-compatible backend when xp is JAX, while preserving SciPy on the NumPy path.
  • Use xp.log / xp.log10 in the compound prior modifiers.
  • Confirm whether compound priors must forward xp recursively to child prior models; add coverage for nested modifiers/compound expressions if so.
  • Add scalar and batched jax.jit regression tests with NumPy/SciPy numerical parity.
  • Keep statistical semantics unchanged.

Verification

  • Direct tests must fail on current main with TracerArrayConversionError and pass after the fix.
  • Run the focused prior/message suites and full PyAutoFit suite.
  • Exercise at least one nested compound-prior expression through the real instance_for_arguments(..., xp=jnp) API.

Relationship to #1458

#1458 addresses fixed-array construction and GammaMessage.to_canonical_form. These four failures are separate call paths and should remain a follow-up PR to keep that repair reviewable.

Activity

  1. Jammy2211 commented on Aug 9, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped in #1461 (squash commit fbe9f45deac2f8f4646d61bdf5f4cb75ac950e30).

    Validation before merge:

    • GitHub Docs: passed
    • GitHub Tests: passed
    • supported JAX 0.7.0 direct suite: 32 passed
    • JAX 0.10.2 direct suite: 32 passed
    • focused prior/message suites: 317 passed
    • full local PyAutoFit suite: 1701 passed, 4 skipped
    • untouched post-Use xp.stack in messages so JAX can trace fixed arrays #1460 main: 12 expected regression failures, 20 passes

    The implementation also fixed the earlier Beta/Gamma traced-constructor np.broadcast boundary discovered while exercising the original four backend leaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions