-
Notifications
You must be signed in to change notification settings - Fork 20
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
Refactor MonteCarlo to be a StatefulInterpretation #369
Conversation
def __call__(self, cls, *args): | ||
return self.dispatch(cls, *args)(self, *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default implementation of __call__()
is a partial function, and relies on InterpreterStack
to fall back to the previous interpretation, which is by assumption complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, MonteCarlo
is much cleaner.
@@ -324,13 +333,54 @@ def dispatched_interpretation(fn): | |||
return fn | |||
|
|||
|
|||
class StatefulInterpretationMeta(type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is required for Python 3.5? Once we drop Python 3.5 support, we should remove this and other metaclasses where possible in favor of __init_subclass__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I was almost tempted to drop support for Python 3.5 in this PR, but that seemed like overkill.
Pair coded with @eb8680
@eb8680 I have adapted
StatefuleInterpretation
from https://github.com/pyro-ppl/funsor/tree/adam-interpreter, making it anamedtuple
as you had originally suggested, and turning on fallback logic by default as you suggested.This PR:
StatefulInterpretation
base class for interpretations that need to pass instance-specific data such as num_samples and rng_key.InterpreterStack
and makes theMonteCarlo
interpretation fall back not toeager
but the previous interpretation when it was installed.monte_carlo
to a statefulMonteCarlo
.MonteCarlo
by trackingrng_key
@fehiepsi can you help me out with this?