Add JAX/flax.nnx backend for CEVAE#957
Merged
Merged
Conversation
Ports pyro.contrib.cevae to jax/flax.nnx under causalml/inference/jax/cevae
xrhd
marked this pull request as ready for review
July 18, 2026 21:55
jeongyoonlee
approved these changes
Jul 20, 2026
jeongyoonlee
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — thanks for the contribution, and welcome!
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.
Proposed changes
Adds a JAX backend for CEVAE (Causal Effect Variational Autoencoder, Louizos et al. 2017) under
causalml/inference/jax/cevae/, usingflax.nnxas the neural network framework andoptaxfor optimization. Exposes the same sklearn-style API as the existing PyTorch implementation (fit,predict,fit_predict,save,load) and follows the opt-incausalml[jax]extra pattern established by #918. A benchmark notebook comparing the two backends side-by-side is included.Resolves #956
Types of changes
Checklist
Changes
causalml/inference/jax/cevae/modeling.py— flax.nnx modules portingpyro.contrib.cevae:FullyConnected, outcome nets (Bernoulli/Exponential/Laplace/Normal/StudentT),DiagNormalNet,PreWhitener,Model,Guidecausalml/inference/jax/cevae/losses.py— ELBO loss (cevae_loss,@jax.jit-compiled)causalml/inference/jax/cevae/cevae.py— sklearn-styleCEVAEwrapper; training viaoptax.adamwwith exponential LR decay matching pyro'sClippedAdamschedule; serialization viaorbax-checkpoint; hardened with a non-finite-loss guard during training and feature-dimension validation at predict timecausalml/inference/jax/cevae/README.md— module documentationcausalml/inference/jax/__init__.py— exportCEVAEtests/test_jax_cevae.py— fit/predict shapes (exercising the defaultstudenttoutcome distribution), ATE recovery, save/load round-trip, and a JAX↔Pyro parity test (each backend runs in its own subprocess to avoid OMP/threading conflicts)docs/examples/cevae_jax_vs_torch.ipynb— benchmark notebook comparing the JAX and PyTorch backends on synthetic data with identical hyperparameters (ATE, MAE, AUUC, training time)Tests
All 4 tests pass locally (macOS arm64, Python 3.13): shapes, ATE recovery, save/load round-trip, and JAX↔Pyro parity.
Dependencies
No dependency changes — uses the existing opt-in
[jax]extra (jax,flax,optax,orbax-checkpoint).Further comments
The implementation mirrors
pyro.contrib.cevaemodule/parameter names so the two backends can be diffed line-by-line. Training is a pure JAX loop withnnx.jit. The dependency stays opt-in viacausalml[jax].The second commit is a polish pass from self-review: ceil-division fix in the LR schedule step count, NaN guard during training, predict-time feature-dimension validation, test coverage for the default
studenttoutcome distribution, plus the JAX vs PyTorch benchmark notebook.References