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

trace fn does not respect random seed for stochastic "Deterministics" #7588

Open
ricardoV94 opened this issue Nov 25, 2024 · 0 comments · May be fixed by #7629
Open

trace fn does not respect random seed for stochastic "Deterministics" #7588

ricardoV94 opened this issue Nov 25, 2024 · 0 comments · May be fixed by #7629

Comments

@ricardoV94
Copy link
Member

Description

import pymc as pm

with pm.Model() as m:
    x = pm.Bernoulli("x", p=0.5) * 0 # Force it to be zero
    pm.Deterministic("y", x + pm.Normal.dist())

    idata1 = pm.sample(tune=0, draws=1, random_seed=1)
    idata2 = pm.sample(tune=0, draws=1, random_seed=1)
    
print(
    idata1.posterior["y"].sel(draw=0).values,
    idata2.posterior["y"].sel(draw=0).values,
    sep="\n"
)
# [-0.39110838 -0.10602868 -0.64066713  0.59270806]
# [ 1.30907711 -0.1391542   0.52679751  0.47189673]

We could pass the rng to the inner compile_pymc. But it's still a bit silly to compile the same function per chain. We could compile the function once and pass it to the trace. After #7578 this should be allowed. We just need to make sure we copy the function with new shared RNGs.

Alternatively, we could defer to compute_deterministics, and move the deterministics computations out of the sampling loop? This would come at a higher memory cost when users choose not to store certain free variables in the trace.

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.

1 participant