Skip to content

Ignore constant shape dependencies in MarginalModel #226

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

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Aug 3, 2023

CI started to fail in latest version of PyTensor due to pymc-devs/pytensor@0cb5fdb

Fix by ignoring dependecies when Shape ought to be constant (all static type shape of entries of input are fixed).
Changes should be backwards compatible

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just asked a couple questions to check that I understand how it works.

@@ -251,9 +253,24 @@ class FiniteDiscreteMarginalRV(MarginalRV):
"""Base class for Finite Discrete Marginalized RVs"""


def static_shape_ancestors(vars):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So before pymc-devs/pytensor@0cb5fdb, these Shape Ops would have been caught by a the simple isinstance(var, Constant) check on line 276?

Now a "constant" shape is one which 1) has no Nones, and 2) has only Shape Op ancestors?

Copy link
Member Author

@ricardoV94 ricardoV94 Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before there wouldn't be any dependency between x -> shape(x) -> y(shape(x)), because shape(x) would just be a constant (so no further edges to x)

"""Test that we don't consider dependencies through "constant" shape Ops"""
x1 = pt.matrix("x1", shape=(None, 5))
y1 = pt.random.normal(size=pt.shape(x1))
assert is_conditional_dependent(y1, x1, [x1, y1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have guessed this case would fail, because there is a None in the shape (line 256)?

Copy link
Member Author

@ricardoV94 ricardoV94 Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There being a None is what makes the dependency. We need to see x1 to know what y1 looks like. For the x2/y2 we already know everything there is to know, so there's no dependency

@ricardoV94 ricardoV94 merged commit 7bcb2bf into pymc-devs:main Aug 3, 2023
@ricardoV94 ricardoV94 deleted the fix_pymc_dep branch August 7, 2023 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants