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

Substituting a plate takes range? #1951

Closed
OlaRonning opened this issue Jan 17, 2025 · 2 comments
Closed

Substituting a plate takes range? #1951

OlaRonning opened this issue Jan 17, 2025 · 2 comments
Labels
question Further information is requested

Comments

@OlaRonning
Copy link
Member

Using the handler.substitute with a plate is counter-intuitive. Given that plate takes an int for the size parameter, I would expect the substitute value to also have type int. However, the substitution need a range [0,n). Below is a small example that illustrates this behavior:

from jax import numpy as jnp
from numpyro import plate, sample, prng_key
from numpyro.handlers import seed, substitute
from numpyro.distributions import Normal

def model(y):
    n = y.shape[0] if y is not None else 1
    with plate('n', n):
        y = sample('y', Normal(), obs=y)
    return y

with seed(rng_seed=0), substitute(data={'n': jnp.arange(10)}):  # Wrong type
    y = model(None)

assert jnp.unique(y).shape == (10,)

with seed(rng_seed=0), substitute(data={'n': 10}):
    y = model(None)  # <-- **AttributeError: 'int' object has no attribute 'shape'**
@fehiepsi
Copy link
Member

The plate value is an index array. Similar for subsample. If you want to change size, you can provide it as an argument or a global configuration.

@fehiepsi fehiepsi added the question Further information is requested label Jan 17, 2025
@OlaRonning
Copy link
Member Author

I see. Thanks for clarifying the rational.

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

No branches or pull requests

2 participants