pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.64k stars 1.99k forks source link

BUG: Kernel crash when running linear regression #7494

Open khider opened 2 weeks ago

khider commented 2 weeks ago

Describe the issue:

Following this example, the kernel restarts within a few seconds:

image

Reproduceable code example:

import arviz as az
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pymc as pm

from pymc import HalfCauchy, Model, Normal, sample, Uniform

RANDOM_SEED = 8927
rng = np.random.default_rng(RANDOM_SEED)

size = 200
true_intercept = 1
true_slope = 2

x = np.linspace(0, 1, size)
# y = a + b*x
true_regression_line = true_intercept + true_slope * x
# add noise
y = true_regression_line + rng.normal(scale=0.5, size=size)

data = pd.DataFrame(dict(x=x, y=y))

with Model() as model:  # model specifications in PyMC are wrapped in a with-statement
    # Define priors
    sigma = HalfCauchy("sigma", beta=10)
    intercept = Normal("Intercept", 0, sigma=20)
    slope = Normal("slope", 0, sigma=20)

    # Define likelihood
    likelihood = Normal("y", mu=intercept + slope * x, sigma=sigma, observed=y)

    # Inference!
    # draw 3000 posterior samples using NUTS sampling
    idata = sample(3000)

Error message:

Kernel restarting

PyMC version information:

pymc 5.16.1 pytensor 2.23.0

Installed through conda (pip was giving me a very old version)

Operating system: image

Context for the issue:

I was trying to reproduce the example to adapt it to my problem.

welcome[bot] commented 2 weeks ago

Welcome Banner] :tada: Welcome to PyMC! :tada: We're really excited to have your input into the project! :sparkling_heart:
If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.

khider commented 2 weeks ago

Was able to go around the problem by using the Numba backend.