Slowdown in latest pymc?

I’m trying to run the Austin Rochfords MRPyMC3 notebook (http://austinrochford.com/posts/2017-07-09-mrpymc3.html) but I find that the sampling takes a really long time, doing the initialization with advi took 23 minutes (about 27 it/s), and after 50 minutes it has managed to draw 270 samples from the posterior.

Now I’m not using the most powerful machine in the world, but on a MacBook Pro with an Core i5 and 8 gb of ram I would have expected a bit better performance. I haven’t used pymc3 in a while and this is a quite complicated model, but from what I remember I’ve fitted models of the similar complexity much faster before.

I installed the latest PyMC3 from github this morning, and I’m running python 3.6.

Any tips of what I can do to improve the performance? / Look for issues in my set up that might cause it to be so slow?

Or is there an issue in the PyMC code somewhere?

This seems to be a regression in PyMC3. I haven’t tracked down the change that caused this yet, but the type of n in pm.Binomial seems to be a problem. Theano doesn’t have a C implementation of gammaln for integers, so it defaults to a python function. You can work around the issue by casting n to float:

with model:
    p = pm.math.sigmoid(η)
    obs = pm.Binomial('obs', n_.astype('float64'), p, observed=yes_of_all)
2 Likes

I can not reproduce the slowdown on my MacBook Pro (mid 2014, 2.6 GHz Core i5, 8GB RAM). Maybe try clearing the Theano cache?

Auto-assigning NUTS sampler...
Initializing NUTS using advi+adapt_diag...
Average Loss = 2,800.1:  19%|█▉        | 37898/200000 [00:45<03:44, 723.26it/s]
Convergence archived at 37900
Interrupted at 37,900 [18%]: Average Loss = 3,804.3
100%|██████████| 1500/1500 [33:34<00:00,  1.59s/it]

n_.astype(‘float64’) seems to have done the trick, thanks!

First I tried to clear the theano cache but that didn’t do anything to the speed…