pymc-marketing icon indicating copy to clipboard operation
pymc-marketing copied to clipboard

MMM Example hangs in PyTensor >2.18.1

Open kylejcaron opened this issue 1 year ago • 11 comments

Hey folks, I just got a new macbook and found the pymc-marketing example wont run for me on it. It hangs up when calling mmm.fit(...) and doesnt get past the following message: Initializing NUTS using jitter+adapt_diag...

I'm using the install instructions from the pymc-marketing quickstart guide (installing with mamba).

I've done some troubleshooting and can safely say

  1. Other PyMC models can fit in this environment (and even in the same notebook)
  2. Defining the model manually and removing the geometric_adstock function allows it to atleast fit (but the model no longer makes sense) as shown below
with pm.Model(coords=self.model_coords) as self.model:

        ...

        # channel_adstock = pm.Deterministic(
        #     name="channel_adstock",
        #     var=geometric_adstock(
        #         x=channel_data_,
        #         alpha=alpha,
        #         l_max=mmm.adstock_max_lag,
        #         normalize=True,
        #         axis=0,
        #     ),
        #     dims=("date", "channel"),
        # )
        fake_param = pm.Normal("fake_param", 0, 5)
        channel_adstock = fake_param.dot(channel_data_)
        channel_adstock_saturated = pm.Deterministic(
            name="channel_adstock_saturated",
            var=logistic_saturation(x=channel_adstock, lam=lam),
            dims=("date", "channel"),
        )
       ...

Maybe this is related to pytensor and/or the batched_convolution function? Any ideas on system level things I need to install? I tried reinstalling xcode for instance but that didnt help

versions:

  • pymc-marketing: 0.3.2
  • pytensor: 2.18.4
  • pymc: 5.10.2

kylejcaron avatar Dec 17 '23 22:12 kylejcaron

Same problem for me on a M1 Pro. Everything was working until i got PyMC Marketing 0.3.2 (had 0.3.1) Left the machine over the weekend and it is still at "Initializing NUTS using jitter+adapt_diag..." when I got here on Monday.

geirrlod avatar Dec 18 '23 11:12 geirrlod

@geirrlod try downgrading to pytensor==2.18.1 that fixed it for me!

It seems like this is a pytensor issue, I tried downgrading to 2.18.1 and it worked, but as soon as I upgraded to 2.18.2 or higher I started running into this issue again.

Pytensor 2.18.2 looks like it was a pretty big release so I'm not quite positive what it was, but I'm seeing subtensors were changed and it seems to be like batched_convolution in pymc-marketing is where this fails, which use subtensors. Maybe thats related?

cc @ricardoV94

kylejcaron avatar Dec 18 '23 12:12 kylejcaron

Can you instead try upgrading PyTensor to 2.18.4?

ricardoV94 avatar Dec 18 '23 12:12 ricardoV94

  • pytensor: 2.18.4

I tried pytensor 2.18.1 through 2.18.4 - pytensor 2.18.2, 2.18.3, and 2.18.4 all had this issue for me, while 2.18.1 did not have the issue

kylejcaron avatar Dec 18 '23 14:12 kylejcaron

  • pytensor: 2.18.4

I tried pytensor 2.18.1 through 2.18.4 - pytensor 2.18.2, 2.18.3, and 2.18.4 all had this issue for me, while 2.18.1 did not have the issue

Thank you so much for that, would not even have thought about checking Pytensor, probably saved me days in debugging :-) 2.18.1 worked here as well

geirrlod avatar Dec 18 '23 14:12 geirrlod

Thanks for trying it out, will have a look what the issue is.

ricardoV94 avatar Dec 18 '23 17:12 ricardoV94

Bug should be fixed by https://github.com/pymc-devs/pytensor/pull/566

ricardoV94 avatar Dec 28 '23 17:12 ricardoV94

This should be fixed in https://github.com/pymc-devs/pytensor/releases/tag/rel-2.18.5

ricardoV94 avatar Jan 02 '24 14:01 ricardoV94

This should be fixed in https://github.com/pymc-devs/pytensor/releases/tag/rel-2.18.5

Thank you @ricardoV94! Can confirm it works for me with 2.18.5

kylejcaron avatar Jan 03 '24 13:01 kylejcaron

Shouldn't we cut a new release that pins that pytensor version?

twiecki avatar Jan 04 '24 17:01 twiecki

Shouldn't we cut a new release that pins that pytensor version?

Yeah, we could do that

ricardoV94 avatar Jan 04 '24 17:01 ricardoV94

This seems stale. Current pymc might restrict this now: https://github.com/pymc-labs/pymc-marketing/blob/main/pyproject.toml#L20

wd60622 avatar Jun 17 '24 12:06 wd60622