-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix bug when freezing_rv_and_dims
after a model transformation
#7296
Conversation
In most function transforms the caller is both creating the fgraph representation and discarding it, so it's safe to mutate the fgraph in place.
466910a
to
0c13baf
Compare
I think I broke something in the fgraph stuff, need to investigate |
Nope this was good, it's #7265 that was broken |
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.
Looks good. The bug was just related to the shapes of transformed models not being correctly frozen?
@@ -278,12 +278,18 @@ def fgraph_from_model( | |||
return fgraph, memo | |||
|
|||
|
|||
def model_from_fgraph(fgraph: FunctionGraph) -> Model: | |||
def model_from_fgraph(fgraph: FunctionGraph, mutate_fgraph: bool = False) -> Model: |
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.
Every time you call the function you use mutate_fgraph = True
, should that be the default instead? Or are the instances in this PR special cases (and there are many others)
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 prefer to ask for consent
Yes, because the shared dim length was not the exact same variable used in the size of the RVs due to an extra cloning of the later. They would still be resized correctly if you updated the dim length but not frozen when you called the associated utility |
Description
Also adds optimization to avoid cloning the fgraph when it will be discarded anyway.
Benchmarked with long models and can cut
clone_model
(the simplest workflow) by 2xRelated Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7296.org.readthedocs.build/en/7296/