Skip to content

Slice stalls during sampling for some hierarchical models #5891

Closed
@covertg

Description

@covertg

When trying to use Slice sampler on certain models, it never finishes sampling. Although sampling starts off quickly, it gradually gets slower. Ultimately it seems to just grind to a halt.

This first happened on a weird model with non-differentiable likelihood, but in trying to debug, I found that this occurs in simpler models as well. I haven't been able to identify specifically what it is about the models that freeze up; but I've noticed it happening in hierarchical models where the variance is estimated as well. For example, a model very similar to that in the using shared variables notebook but with a global sigma parameter added freezes up when slice sampling. A naive "8-schools" model, however, does not seem to slow down.

Example model that freezes:

# generate data_df as in example notebook
coords = {"date": df_data.index, "city": df_data.columns}
with pm.Model(coords=coords) as model:
    europe_mean = pm.Normal("europe_mean_temp", mu=15.0, sigma=3.0)
    europe_sigma = pm.HalfNormal("europe_sigma", 2.0)
    city_offset = pm.Normal("city_offset", mu=0.0, sigma=europe_sigma, dims="city")
    city_temperature = pm.Deterministic("city_temperature", europe_mean + city_offset, dims="city")

    data = pm.ConstantData("data", df_data, dims=("date", "city"))
    pm.Normal("likelihood", mu=city_temperature, sigma=0.5, observed=data)

It stalls out on my system and times out on a Google colab instance. Here's the full notebook in colab for data, sampling, and also the simple 8 schools model.

This is all the investigation I've been able to do so far, but let me know if there's anything more that'd be helpful for me to do.

  • PyMC/PyMC3 Version: 4.0.0
  • Aesara/Theano Version: 2.6.6
  • Python Version: 3.10, 3.7 (in Colab)
  • Operating system: Linux
  • How did you install PyMC/PyMC3: pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions