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

BUG: sample returning a different size in pymc 5.7.0 #6840

Closed
oscarbenjamin opened this issue Jul 31, 2023 · 3 comments · Fixed by #6843
Closed

BUG: sample returning a different size in pymc 5.7.0 #6840

oscarbenjamin opened this issue Jul 31, 2023 · 3 comments · Fixed by #6843
Labels

Comments

@oscarbenjamin
Copy link

Describe the issue:

With pymc == 5.6.1 I get:

In [2]: import pymc
WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

In [3]: with pymc.Model():
   ...:     pymc.Bernoulli('X', p=0.2)
   ...:     samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
   ...: 
Only 3 samples in chain.
Sequential sampling (1 chains in 1 job)
BinaryGibbsMetropolis: [X]
Sampling 1 chain for 1_000 tune and 3 draw iterations (1_000 + 3 draws total) took 0 seconds.rgences]
The number of samples is too small to check convergence reliably.

In [4]: samps[:]['X'].shape
Out[4]: (3,)

However with pymc==5.7.0 I get:

In [1]: import pymc
WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

In [2]: with pymc.Model():
   ...:     pymc.Bernoulli('X', p=0.2)
   ...:     samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
   ...: 
Only 3 samples in chain.
Sequential sampling (1 chains in 1 job)
BinaryGibbsMetropolis: [X]
Sampling 1 chain for 0 tune and 1_003 draw iterations (0 + 1_003 draws total) took 0 seconds.rgences]
Only one chain was sampled, this makes it impossible to run some convergence checks

In [3]: samps[:]['X'].shape
Out[3]: (1003,)

So the shape of the generated output has changed.

Reproduceable code example:

import pymc
with pymc.Model():
    pymc.Bernoulli('X', p=0.2)
    samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
print(samps[:]['X'].shape)

Error message:

No response

PyMC version information:

5.7.0

Context for the issue:

This is just coming up in SymPy CI. From a SymPy VCS checkout this is reproduced with:

$ pytest sympy/stats/sampling/tests/test_sample_finite_rv.py -k test_sample_pymc
...
            with pymc.Model():
                if do_sample_pymc(self):
                    samps = pymc.sample(draws=prod(size), chains=1, compute_convergence_checks=False,
                            progressbar=False, random_seed=seed, return_inferencedata=False)[:]['X']
>                   samps = samps.reshape(size)
E                   ValueError: cannot reshape array of size 1003 into shape (1,3)

sympy/stats/rv.py:1639: ValueError

The code in question is here:
https://github.com/sympy/sympy/blob/e8ffcf40a6148235667ed75b811bdc1f953466e9/sympy/stats/rv.py#L1635-L1639

@welcome
Copy link

welcome bot commented Jul 31, 2023

Welcome Banner
🎉 Welcome to PyMC! 🎉 We're really excited to have your input into the project! 💖

If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.

@twiecki
Copy link
Member

twiecki commented Jul 31, 2023

Related to #6835 CC @michaelosthege

@michaelosthege
Copy link
Member

Huh strange. From looking at the changes & MRE I'd say the .reset_tuning() method of the stepper is not getting called during sampling, which must be a bug that silently existed before #6835 already.

I'll try to take a look later today.

michaelosthege added a commit to michaelosthege/pymc that referenced this issue Aug 1, 2023
The `tune` attribute is reset by the sampling iterator.

Closes pymc-devs#6840
ricardoV94 pushed a commit that referenced this issue Aug 2, 2023
The `tune` attribute is reset by the sampling iterator.

Closes #6840
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants