Skip to content

ENH: compile estimators entirely with JAX - #582

Open
grayson-helmholz wants to merge 2 commits into
ENH/expose-backendfrom
ENH/jit-estimators
Open

ENH: compile estimators entirely with JAX#582
grayson-helmholz wants to merge 2 commits into
ENH/expose-backendfrom
ENH/jit-estimators

Conversation

@grayson-helmholz

@grayson-helmholz grayson-helmholz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #570

⚙️ Enhancements

On the JAX backend, ChiSquared and UnbinnedNLL are now JIT-compiled as a whole, instead of only JIT-compiling the wrapped function. The estimator body is built once in the constructor as a pure kernel over (parameters, *data) and wrapped in jax.jit, so the reduction, the normalization, and the function evaluation all fuse into a single compiled call that is reused across evaluations. A regression test asserts that a fit loop traces the kernel exactly once.

The analytic gradient() is now jax.jit(jax.grad(core)) over that same kernel, differentiated with respect to its parameters argument. It previously differentiated self.__call__, which forced a re-trace through the bound method on every call.

Data samples are converted to backend arrays once, in the constructor, so JIT-compiled evaluations no longer pay a host-to-device transfer per call.

❗ Behavioral changes

Estimators now import and initialize JAX when they are constructed rather than on the first gradient call, so a configure(jax_precision=...) call made before construction is respected. Estimator results are computed at the configured precision, where a fixed x64 flag was effectively assumed before.

Parameter values handed to an estimator are coerced to float or complex before evaluation. This keeps JIT input types stable — an int value would otherwise re-trace the kernel as soon as the optimizer turns it into a float — but it means integer parameter values no longer reach the wrapped function as integers.

Squash commit messages

* BEHAVIOR: coerce estimator parameters to float or complex
* BEHAVIOR: initialize JAX when constructing an estimator
* ENH: move estimator data to the backend arrays once

@redeboer redeboer linked an issue Aug 7, 2026 that may be closed by this pull request
@redeboer
redeboer force-pushed the ENH/jit-estimators branch from f5b4825 to 1236b1b Compare August 31, 2026 14:44

@redeboer redeboer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'TensorWaves benchmark results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 3b506e9 Previous: f5c1db9 Ratio
benchmarks/ampform.py::TestJPsiToGammaPiPi::test_fit[10000-jax] 0.6168525486949856 iter/sec (stddev: 0) 1.439081184425215 iter/sec (stddev: 0) 2.33

This comment was automatically generated by workflow using github-action-benchmark.

@redeboer redeboer added ⚙️ Enhancement Improvements and optimizations of existing features ❗ Behavior Changes that may affect the framework output labels Sep 1, 2026
@redeboer redeboer changed the title ENH: JIT-compile estimators entirely with JAX ENH: compile estimators entirely with JAX Sep 1, 2026
@redeboer redeboer modified the milestones: 0.4.18, 0.5.0 Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

❗ Behavior Changes that may affect the framework output ⚙️ Enhancement Improvements and optimizations of existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT-compile estimators entirely

2 participants