pymc-devs / pymc-experimental

https://pymc-experimental.readthedocs.io
Other
72 stars 47 forks source link

Copy the MutableCoords length shared variables in `fgraph_from_model` #205

Closed ricardoV94 closed 10 months ago

ricardoV94 commented 1 year ago

Otherwise the coords stay linked across models (changing them in a cloned or modified model, will change them in the original model as well).

In general, we might want to do this for any MutableData (but perhaps not for unregistered shared variables)? The reason against that is that copying large arrays can increase memory footprint pretty quickly.

This is not a concern for the dim-lengths, which are just scalars. Also they are kind of an implementation detail, so users shouldn't have to know about them, and we should just opt for the least surprising behavior.

We already do something similar for RNGs: https://github.com/pymc-devs/pymc-experimental/blob/dd04eff3e1e1b3de88e8f20ad2ad34ce01402bb4/pymc_experimental/utils/model_fgraph.py#L185-L189

We would do something similar to length variables, just have to identify them

ricardoV94 commented 1 year ago

With the new functionality to mutate PyMC models like clone, do, observe it may also be fruitful to move PyMC models more immutable. This removes some complexity for models (like shared vs mutable dims or shared vs constant data) and allows us to speedup stuff like repeated sampling or sample_posterior_predictive by caching the compiled functions

ricardoV94 commented 10 months ago

I think this was implemented