CompositeLikelihood subsets have data-dependent shapes and cannot compile under JAX

Open
#67 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
22/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

The problem is in CompositeLikelihood, which selects each row's sub-likelihood with nonzero(group == k), producing data-dependent shapes that JAX cannot compile. Start by reproducing the failure: build a model using CompositeLikelihood and compile it with mode="JAX". The issue leaves the fix open, so agreeing on an approach with the maintainers comes first. Done means the model compiles under JAX and its predictions match the C and Numba backends.

Written by the indexing model from the issue text.

Description

CompositeLikelihood (#42, being ported onto the likelihood-graph design from #50) picks each observation's sub-likelihood from group labels computed from the inputs, e.g. group=X[:, kind_col]. Each evaluation selects the rows of group k with nonzero(group == k), whose length depends on the data. The C and Numba backends handle this, but JAX needs static shapes, so a model using CompositeLikelihood will not compile with mode="JAX".

A possible fix is to evaluate every sub-likelihood on every row and keep each row's own term with switch(group == k, value_k, 0). Shapes stay static, at K times the work. Rows outside a sub-likelihood's support can produce inf or NaN values whose gradients become NaN even where masked, so the inputs of masked rows need to be replaced with safe values before evaluation (the "double where" pattern).

This is just a guess at a fix. Numba works fine. Open to other options for fixing this. Only hits someone doing prediction with a CompositeLilkelihood using JAX.

Dominant language
Jupyter Notebook
Stars
16
Forks
5
Avg merge
2d 49m
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pymc-devs/ptgp

All issues in pymc-devs/ptgp

Similar issues

More Machine Learning issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.