Add cat constraint and CatTransform - #2246
Conversation
Benchmark reportthis PR + run time: 1 faster
compile time: unchanged across 32 benchmarksSignificant changes (1) ─────── run time ─────── ───── compile time ─────
benchmark baseline this PR Δ baseline this PR Δ
──────────────────────────────────────────────────────────────────────────────────
+ log_density_hierarchical 4.0 ms 3.7 ms -5.6% 1.27 s 1.28 s +1.0%Red is slower, green is faster; a row is coloured by the worse of its two columns. A delta in parentheses cleared the threshold on a measurement below the resolution floor, so it is shown without being called a change. † marks a benchmark that could not be compared — see below. Full results
|
| baseline | this PR | |
|---|---|---|
| ref | master |
agent/add-cat-constraint-transform |
| commit | 999d8d1f |
956e3073 |
| numpyro | 0.21.0 | 0.21.0 |
| jax | 0.11.1 | 0.11.1 |
| backend | cpu | cpu |
| python | 3.14.7 | 3.14.7 |
Runner: Linux-6.17.0-1022-azure-x86_64-with-glibc2.39, 4 CPUs.
Produced by this benchmark run.
Closes #1872.
Summary
constraints.catfor applying heterogeneous constraints to consecutive slices, including shape validation, feasible-value construction, equality, and JAX pytree supportCatTransformwith forward/inverse operations, per-component Jacobians, intermediate propagation, andbiject_toregistrationThe public API follows the corresponding PyTorch
constraints.cat/CatTransformnaming and slice semantics. Malformed layouts are rejected explicitly so a constraint cannot silently leave trailing values unchecked.Tests
pytest -q test/test_transforms.py— 239 passedruff checkandruff formaton changed files — passedty check numpyro/distributions/constraints.py numpyro/distributions/transforms.py— passedscripts/update_headers.py --check— passedNo new dependencies.
I used OpenAI Codex to assist with source comparison, implementation, and test execution; I reviewed the final diff and validation results.