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

Fix bug when freezing_rv_and_dims after a model transformation #7296

Merged
merged 2 commits into from
May 6, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented May 1, 2024

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 2x

Related Issue

  • Closes #
  • Related to #

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7296.org.readthedocs.build/en/7296/

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.
@ricardoV94 ricardoV94 requested review from twiecki and removed request for twiecki May 3, 2024 07:45
@ricardoV94 ricardoV94 marked this pull request as draft May 3, 2024 11:06
@ricardoV94
Copy link
Member Author

I think I broke something in the fgraph stuff, need to investigate

@ricardoV94 ricardoV94 marked this pull request as ready for review May 3, 2024 15:36
@ricardoV94
Copy link
Member Author

Nope this was good, it's #7265 that was broken

@ricardoV94 ricardoV94 requested a review from twiecki May 3, 2024 15:37
Copy link
Member

@jessegrabowski jessegrabowski left a 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:
Copy link
Member

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)

Copy link
Member Author

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

@ricardoV94
Copy link
Member Author

Looks good. The bug was just related to the shapes of transformed models not being correctly frozen?

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

@ricardoV94 ricardoV94 merged commit ba60b79 into pymc-devs:main May 6, 2024
20 checks passed
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.

None yet

2 participants