Skip to content

Access to model.logp changes the free random variables inplace #5007

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
aseyboldt opened this issue Sep 21, 2021 · 2 comments
Closed

Access to model.logp changes the free random variables inplace #5007

aseyboldt opened this issue Sep 21, 2021 · 2 comments
Labels

Comments

@aseyboldt
Copy link
Member

with pm.Model() as model:
    a = pm.HalfNormal("a")
    c = pm.Uniform("c", lower=a - 1, upper=1)

print("before")
print("------")
aesara.dprint(c)

print()
model.logpt

print("after")
print("-----")
aesara.dprint(c)
before
------
uniform_rv{0, (0, 0), floatX, False}.1 [id A] 'c'   
 |RandomStateSharedVariable(<RandomState(MT19937) at 0x7F649E351540>) [id B]
 |TensorConstant{[]} [id C]
 |TensorConstant{11} [id D]
 |Elemwise{sub,no_inplace} [id E] ''   
 | |halfnormal_rv{0, (0, 0), floatX, False}.1 [id F] 'a'   
 | | |RandomStateSharedVariable(<RandomState(MT19937) at 0x7F649D753040>) [id G]
 | | |TensorConstant{[]} [id H]
 | | |TensorConstant{11} [id I]
 | | |TensorConstant{0.0} [id J]
 | | |TensorConstant{1.0} [id K]
 | |TensorConstant{1} [id L]
 |TensorConstant{1.0} [id M]

after
-----
uniform_rv{0, (0, 0), floatX, False}.1 [id A] 'c'   
 |RandomStateSharedVariable(<RandomState(MT19937) at 0x7F649E351540>) [id B]
 |TensorConstant{[]} [id C]
 |TensorConstant{11} [id D]
 |Elemwise{sub,no_inplace} [id E] ''   
 | |Elemwise{exp,no_inplace} [id F] ''   
 | | |a_log__ [id G]
 | |TensorConstant{1} [id H]
 |TensorConstant{1.0} [id I]

Maybe some graph.replace_all is changing the variables inplace when it should have made a copy first?

CC @brandonwillard

@aseyboldt
Copy link
Member Author

This does not seem to be an issue in the aeppl implementation, so maybe we can just close this when #4887 is merged.

This does not seem to change the original variables:

import aeppl

with pm.Model() as model:
    a = pm.Normal("a", sigma=1)
    b = pm.Normal("y", mu=a, sigma=1, observed=2)
    c = pm.Normal("z", mu=a + b)

aesara.dprint(b)
print()
aeppl.joint_logprob(model.rvs_to_values)
print()
aesara.dprint(b)

@ricardoV94 ricardoV94 added this to the v4.0.0-beta1 (vNext) milestone Oct 14, 2021
ricardoV94 pushed a commit to michaelosthege/pymc that referenced this issue Oct 14, 2021
To unblock this PR/branch from the aeppl integration.
twiecki pushed a commit that referenced this issue Oct 14, 2021
To unblock this PR/branch from the aeppl integration.
@ricardoV94
Copy link
Member

Closed via #4887

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

No branches or pull requests

2 participants