-
-
Notifications
You must be signed in to change notification settings - Fork 62
Copy model-related shared variables in model_fgraph
#218
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
Conversation
model_fgraph
b750f0e
to
13f8644
Compare
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. Great work @ricardoV94
@@ -184,8 +184,7 @@ def fgraph_from_model( | |||
|
|||
# Replace RNG nodes so that seeding does not interfere with old model | |||
for rng in find_rng_nodes(model_vars): | |||
new_rng = rng.clone() | |||
new_rng.set_value(rng.get_value(borrow=False)) | |||
new_rng = shared(rng.get_value(borrow=False)) |
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 don't understand why the old approach didn't work. You were creating a clone, then setting its value to a new generator. Why would wrapping a new shared around a generator work and the old approach not.
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.
SharedVariable.clone
reuses the same container. The only thing that's "cloned" is the Variable
object: https://github.com/pymc-devs/pytensor/blob/673c1accf98659ba0457759431cb36eef4659f63/pytensor/compile/sharedvalue.py#L139-L149
memo[rng] = new_rng | ||
# Replace the following shared variables in the model: | ||
# 1. RNGs | ||
# 2. MutableData (could increase memory usage significantly) |
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.
We'll have to wait and get some feedback. If people complain about this, we can review the memory sharing.
model_fgraph
model_fgraph
In earlier iterations of the do-blogpost it became clear that it's more intuitive for model-related shared variables to be copied, instead of shared across different models. Some of these variables are created by PyMC (dim_lengths) and users would have to know the internals not to be surprised about the behavior.
User defined
MutableData
is also copied, because unlike the underlyingSharedVariable
s, nothing about the name and documentation suggests these variables are supposed to be "shared" across models (just that they can be mutated).I have only allowed user-defined shared variables that are not model variables to be actually shared across model cloning.
This now works as (imo) expected:
This PR also fixes a bug, as RNG shared variables weren't actually being copied and rendered independent with the old
clone
approach. The relevant test was missing anassert
:( (see first commit of this PR)