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

update to pymc 5 and pytensor #29

Merged
merged 4 commits into from
Dec 22, 2022
Merged

update to pymc 5 and pytensor #29

merged 4 commits into from
Dec 22, 2022

Conversation

aloctavodia
Copy link
Member

@aloctavodia aloctavodia commented Dec 21, 2022

This is the failing test:

def test_shared_variable():
    X = np.random.normal(0, 1, size=(50, 2))
    Y = np.random.normal(0, 1, size=50)

    with pm.Model() as model:
        data_X = pm.MutableData("data_X", X)
        mu = pmb.BART("mu", data_X, Y, m=2)
        sigma = pm.HalfNormal("sigma", 1)
        y = pm.Normal("y", mu, sigma, observed=Y, shape=mu.shape)
        idata = pm.sample(tune=100, draws=100, chains=2, random_seed=3415)
        ppc = pm.sample_posterior_predictive(idata)
        new_X = pm.set_data({"data_X": X[:3]})
        ppc2 = pm.sample_posterior_predictive(idata)

fails with

<<!! BUG IN FGRAPH.REPLACE OR A LISTENER !!>> <class 'TypeError'> The type of the replacement (TensorType(float64, (3,))) must be compatible with the type of the original Variable (TensorType(float64, (50,))). random_make_inplace
ValueError: shape mismatch: objects cannot be broadcast to a single shape.
Mismatch is between arg 0 with shape (50,) and arg 1 with shape (3,).

EDIT by Michael: I copied the failing test code here for reference.

@aloctavodia
Copy link
Member Author

@ricardoV94 @michaelosthege Do you have a quick idea of why the shape test is failing?

@michaelosthege
Copy link
Member

So the <<!! BUG IN FGRAPH.REPLACE OR A LISTENER !!>> sounds like the rewrite self-diagnosed that there's a bug.

Good thing it happened with such a simple MRE !

Something about the BART_rv or a rewrite that is related to it must have choked on the resizing of the data_X SharedVariable from (50,) to (3,).

My best guess is this line:

shape = self.X.shape[0].eval()

This results in a static shape and the rewrites that happened later might have relied on this incorrect static shape assumption.

@aloctavodia aloctavodia merged commit 833790f into main Dec 22, 2022
@aloctavodia aloctavodia deleted the pytensor branch December 22, 2022 13:13
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