Skip to content
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

Inference for gaussian_hmm is broken on latest jax version (0.4.30) #1827

Closed
damonbayer opened this issue Jul 2, 2024 · 1 comment · Fixed by #1830
Closed

Inference for gaussian_hmm is broken on latest jax version (0.4.30) #1827

damonbayer opened this issue Jul 2, 2024 · 1 comment · Fixed by #1830

Comments

@damonbayer
Copy link
Contributor

damonbayer commented Jul 2, 2024

The following works with jax/jaxlib 0.4.29, but is broken with jax/jaxlib 0.4.30:

Copying from the current documentation:

import numpy as np
import numpyro
import numpyro.distributions as dist
from numpyro.contrib.control_flow import scan

def gaussian_hmm(y=None, T=10):
    def transition(x_prev, y_curr):
        x_curr = numpyro.sample('x', dist.Normal(x_prev, 1))
        y_curr = numpyro.sample('y', dist.Normal(x_curr, 1), obs=y_curr)
        return x_curr, (x_curr, y_curr)

    x0 = numpyro.sample('x_0', dist.Normal(0, 1))
    _, (x, y) = scan(transition, x0, y, length=T)
    return (x, y)


with numpyro.handlers.seed(rng_seed=0):  # generative
    x, y = gaussian_hmm()

If I then try to perform inference:

from jax import random
from numpyro.infer import MCMC, NUTS
nuts_kernel = NUTS(gaussian_hmm)

mcmc = MCMC(nuts_kernel, num_warmup=500, num_samples=1000)
rng_key = random.PRNGKey(0)

mcmc.run(rng_key, y=y)

I get the error

TypeError: body_fun output and input must have identical types, got
('ShapedArray(int32[], weak_type=True)', ['ShapedArray(float32[10])', 'DIFFERENT ShapedArray(int32[], weak_type=True) vs. ShapedArray(float0[])', 'ShapedArray(float32[])'], []).
@damonbayer damonbayer changed the title Inference for gaussian_hmm broken on latest jax version (0.4.30) Inference for gaussian_hmm is broken on latest jax version (0.4.30) Jul 3, 2024
@fehiepsi
Copy link
Member

fehiepsi commented Jul 3, 2024

Hi @damonbayer, it is fixed in #1817. We will make a patch release this week.

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 a pull request may close this issue.

2 participants