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

Exclude seed handler from the PYRO_STACK #2061

Merged
merged 2 commits into from
Oct 11, 2019
Merged

Exclude seed handler from the PYRO_STACK #2061

merged 2 commits into from
Oct 11, 2019

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented Oct 11, 2019

The seed handler is special in Pyro and Minipyro in that it affects state in the global rng seed, rather than in Pyro. Moreover we would like to use this handler globally, as is done in Numpyro. One thing that makes this difficult is that much of our code tests if not PYRO_STACK: ...do shortcut.... This PR omits the Seed handler from the PYRO_STACK, thus making it possible to use that handler globally while preserving old shortcuts.

This PR also makes the seed handler restore previous state on exit, thereby providing compatibility with the numpyro backend.

For motivation, see https://github.com/pyro-ppl/numpyro/pull/396/files#r334110296

Copy link
Member

@neerajprad neerajprad left a comment

Choose a reason for hiding this comment

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

LGTM.

super(_SeedMessenger, self).__enter__()

def __exit__(self, type, value, traceback):
set_rng_state(self.old_state)
Copy link
Member

Choose a reason for hiding this comment

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

+1 on restoring the previous state - this makes the behavior identical across backends.

@neerajprad neerajprad merged commit 4611aed into dev Oct 11, 2019
@fritzo fritzo deleted the seed-poutine-noop branch October 12, 2019 01:35
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