Skip to content

Add dispatch for Jax Hyp2F1 Function #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

ColtAllen
Copy link
Contributor

@ColtAllen ColtAllen commented Jun 2, 2025

Description

This PR adds Jax support for the Gaussian Hypergeometric function. This was added just before the latest Jax 0.6.1 release, but tests are still somehow passing for Jax 0.5.2.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1439.org.readthedocs.build/en/1439/

@ColtAllen
Copy link
Contributor Author

From the CI run:

AttributeError: module 'jax.scipy.special' has no attribute 'hyp2f1'

Seems we'll need to update the pyproject.toml to minimally support the latest version.

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 2, 2025

If it passes locally without your PR in a recent enough version of JAX we don't need to do anything, we're not testing most jax.special functions. It's enough if it has the same signature as scipy

@ColtAllen
Copy link
Contributor Author

If it passes locally without your PR in a recent enough version of JAX we don't need to do anything, we're not testing most jax.special functions. It's enough if it has the same signature as scipy

In pymc-marketing, Nutpie runs endlessly, and Blackjax and NumPyro raise the following error:

~/mamba/envs/pymc-marketing-dev/lib/python3.10/site-packages/jax/_src/lax/control_flow/loops.py:1975, in _while_transpose_error(*_, **kwargs)

ValueError: Reverse-mode differentiation does not work for lax.while_loop or lax.fori_loop with dynamic start/stop values. 
Try using lax.scan, or using fori_loop with static start/stop.

Are we at the mercy of the jax developers to resolve this?

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 6, 2025

Did they use a fori loop in their hyp2f1 implementation? If so you may want to open an issue with them to use scan instead. But if they used a while loop you're out of luck, that can't be differentiated no matter what.

You may want to try nutpie with the numba backend after #1445

@ColtAllen
Copy link
Contributor Author

Did they use a fori loop in their hyp2f1 implementation? If so you may want to open an issue with them to use scan instead. But if they used a while loop you're out of luck, that can't be differentiated no matter what.

lax.while_loop calls are returned by _hyp2f1_serie, a conditional called when all parameters are > 0. The parameters in question for ParetoNBDModel are Gamma shape & scale params, so we're out of luck 🙁

You may want to try nutpie with the numba backend after #1445

numba supports scipy.special.hyp2f1; hope is kindled!

@ColtAllen ColtAllen closed this Jun 7, 2025
@ColtAllen ColtAllen deleted the jax-hyp2f1 branch June 7, 2025 03:03
@ColtAllen
Copy link
Contributor Author

Referenced issue has been updated for numba.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants