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
EOFError
#700
Comments
There is a similar issue open in the PyMC repo (pymc-devs/pymc#6415) but I'm fairly certain that this is a Bambi issue, because I can create a fairly minimal reprex that fails in Bambi but works just fine if I write it out in PyMC: import numpy as np
import pandas as pd
import pymc as pm
import bambi as bmb
# 3 columns of 100k random-normal numbers
df = pd.DataFrame(np.random.randn(300000).reshape((-1, 3)), columns=['x1', 'x2', 'y'])
# this PyMC model samples just fine
with pm.Model():
a = pm.Normal('a', mu=0, sigma=1)
b1 = pm.Normal('b1', mu=0, sigma=1)
b2 = pm.Normal('b2', mu=0, sigma=1)
e = pm.HalfStudentT('e', sigma=1, nu=3)
yhat = a + b1 * df.x1 + b2 * df.x2
likelihood = pm.Normal('likelihood', mu=yhat, sigma=e, observed=df.y)
pm.sample()
# this very similar Bambi model also samples just fine with mp_ctx='forkserver'
bmb.Model('y ~ 1 + x1 + x2', df).fit(mp_ctx='forkserver')
# but this identical Bambi model fails before sampling starts, raising an EOFError
bmb.Model('y ~ 1 + x1 + x2', df).fit() I've worked out that changing the multiprocessing context from Having Bambi always pass (@tomicapretto, FYI) |
As @drbenvincent notes, reducing the dataset size also fixes the problem, so it seems to have something to do with memory allocation for forked processes on M1 chipsets. There also seems to be a general consensus that using |
Thanks for the in depth research! Bambi creates models in a slightly different way, first computing a design matrix, then a vector of coefficients, and finally the dot product between those. Maybe, these operations are incurring in some extra consumption or memory or whatever that causes this problem on M1 chipsets. Are you aware of drawbacks associated with the |
What's weird is that I can make the pure PyMC model much, much larger (more data, more random variables, etc.) and it will still work with RE: |
Narrowed it down further: import numpy as np
import pandas as pd
import pymc as pm
from formulae import design_matrices
# 3 columns of 100k random-normal numbers
df = pd.DataFrame(np.random.randn(300000).reshape((-1, 3)), columns=['x1', 'x2', 'y'])
# create design matrix
dm = design_matrices('y ~ 1 + x1 + x2', df)
# fit model with multiplication + summation (this works!)
with pm.Model():
b = pm.Normal('b', mu=0, sigma=1, shape=3)
e = pm.HalfStudentT('e', sigma=1, nu=3)
yhat = (dm.common.design_matrix * b).sum(axis=1)
likelihood = pm.Normal('likelihood', mu=yhat, sigma=e, observed=df.y)
trace = pm.sample()
# fit model with pm.math.dot (this does not work!)
with pm.Model():
b = pm.Normal('b', mu=0, sigma=1, shape=3)
e = pm.HalfStudentT('e', sigma=1, nu=3)
yhat = pm.math.dot(dm.common.design_matrix, b)
likelihood = pm.Normal('likelihood', mu=yhat, sigma=e, observed=df.y)
trace = pm.sample() Creating a design matrix with I can still get the model to sample by reducing the size of the dataset, so it's not like Edited to add: The dot-product that |
Thanks for the detailed report! I just shared this with the PyTensor people. |
I came across a strange bug. Here's a minimum (not) working example to replicate the problem.
This is with Bambi 0.12.0 and pandas 2.0.3. At first I thought it might be a pandas 2 problem, but the same error occurs under pandas 1.5.3.
Couldn't find anything about
EOFError
in any open or closed issues, so thought I'd submit this possible bug report.EDIT: Error occurs when
N=10_000
, but not whenN=1_000
.I get the following error:
The text was updated successfully, but these errors were encountered: