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

Can't load MMM with vector parameter prior #333

Closed
ricardoV94 opened this issue Aug 2, 2023 · 5 comments · Fixed by #351
Closed

Can't load MMM with vector parameter prior #333

ricardoV94 opened this issue Aug 2, 2023 · 5 comments · Fixed by #351
Labels
bug Something isn't working MMM

Comments

@ricardoV94
Copy link
Contributor

ricardoV94 commented Aug 2, 2023

Grabbing the current example in #324 , and changing the beta prior to:

custom_beta_channel_prior = {'beta_channel': {'sigma': [1, 2], 'dims': ('channel',)}}
my_model_config = dummy_model.default_model_config | custom_beta_channel_prior

I then fail to load the model after saving with:

ValueError                                Traceback (most recent call last)
Cell In[63], line 1
----> 1 loaded_model = DelayedSaturatedMMM.load('my_saved_model')

File ~/Documents/Work/Labs/pymmmc/pymc_marketing/mmm/delayed_saturated_mmm.py:416, in BaseDelayedSaturatedMMM.load(cls, fname)
    414 # All previously used data is in idata.
    415 if model.id != idata.attrs["id"]:
--> 416     raise ValueError(
    417         f"The file '{fname}' does not contain an inference data of the same model or configuration as '{cls._model_type}'"
    418     )
    420 return model

ValueError: The file 'my_saved_model' does not contain an inference data of the same model or configuration as 'DelayedSaturatedMMM'

The error doesn't happen if I use a scalar sigma.

CC @michaelraczycki

@ricardoV94 ricardoV94 added bug Something isn't working MMM labels Aug 2, 2023
@michaelraczycki
Copy link
Contributor

michaelraczycki commented Aug 2, 2023

It's something that comes from json encoding. It's impossible to determine if json list was encoded from np.array, or from list. Because of that load automatically creates np.array in place of each json list found in the model_config. I see that I need to create full documentation of the model builder module and it's retirements/limitations.
Hashlib.sha256 encodes differently python list and numpy array, and because of that Id of the model doesn't match after loading. In my opinion we should just require passing that on form of np.array format always (then it won't cause the error

@ricardoV94
Copy link
Contributor Author

ricardoV94 commented Aug 2, 2023

What about sanitizing the config (after making a copy) so the user doesn't have to worry about that? In this case convert lists to numpy arrays.

@michaelraczycki
Copy link
Contributor

that can also be done, although I think I'd suggest to first release the intro notebook, and then start patching up those topics as the jsonification looks like a bottomless pit, probably every once in a while we'll get a bug report about that.

@michaelraczycki
Copy link
Contributor

I'll open another issue in pymc-experimental to keep track of that

@michaelraczycki
Copy link
Contributor

I've opened a PR that now will convert any lists or arrays found inside the model_config into np.array format before assigning model_config inside the DelayedSaturatedMMM, probably merging #351 should solve your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working MMM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants