-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Seeding not working for single chains #5378
Comments
So the random state of the 2nd sampling is not identical. Maybe the import numpy as np
import pymc as pm
class BlablaSampler(pm.Metropolis):
def step(self, *args, **kwargs):
_, rstate, pos, has_gauss, cached_gaussian = np.random.get_state()
draw, stats = super().step(*args, **kwargs)
print(f"""
args {args}
kwargs {kwargs}
rstate {hash(rstate.tobytes())}
pos {pos}
has_gauss {has_gauss}
cached_gaussian {cached_gaussian}
↓↓↓↓↓
draw {draw}
stats {stats}
""")
return draw, stats
with pm.Model(rng_seeder=3) as pmodel:
x = pm.Normal("x", initval="prior")
common = dict(
chains=1,
cores=1,
random_seed=1,
tune=0,
draws=3,
return_inferencedata=False,
compute_convergence_checks=False,
)
tr1 = pm.sample(
**common,
step=BlablaSampler(),
)
tr2 = pm.sample(
**common,
step=BlablaSampler(),
)
assert np.allclose(tr1["x"], tr2["x"]) # Fails Output
|
I don't think the random seeding is taking any effect |
Well it's working for multiple chains, but maybe that's because of a process forking or a difference between different control flows that "protects" the mother-seed. I looked at that control flow yesterday and with this discussion in mind we might want to solve this as part of a bigger refactor. |
I don't know how seeding works, doesn't work nor is expected to work on v4. Just sharing this as a potential test to make sure seeding is reproducible yet constrained to pymc: https://discourse.pymc.io/t/weired-random-number-generation-pattern-after-training-a-pymc3-model/8875 |
Seeding seems to not be respected when using a single chain:
There is also a similar failure when passing multiple seeds, but working with a single core (i.e., sequential sampling)
#5377 Includes a test which covers the failing cases
The text was updated successfully, but these errors were encountered: