# Slowdown in latest pymc?

**URL:** <https://discourse.pymc.io/t/slowdown-in-latest-pymc/173>\
**Category:** Questions\
**Created:** [July 18, 2017, 11:09am UTC](https://discourse.pymc.io/t/slowdown-in-latest-pymc/173 "2017-07-18T11:09:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonsjoberg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jonsjoberg/32/24_2.png) [@jonsjoberg](https://discourse.pymc.io/u/jonsjoberg)\
**Post date:** [July 18, 2017, 11:10am UTC](https://discourse.pymc.io/t/slowdown-in-latest-pymc/173/1 "2017-07-18T11:10:00Z")

</div>

I’m trying to run the Austin Rochfords MRPyMC3 notebook ([http://austinrochford.com/posts/2017-07-09-mrpymc3.html](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?

---

<div class="post-metadata">

**Author:** ![aseyboldt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aseyboldt/32/5795_2.png) [@aseyboldt](https://discourse.pymc.io/u/aseyboldt)\
**Post date:** [July 18, 2017, 12:06pm UTC](https://discourse.pymc.io/t/slowdown-in-latest-pymc/173/2 "2017-07-18T12:06:57Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [July 18, 2017, 12:25pm UTC](https://discourse.pymc.io/t/slowdown-in-latest-pymc/173/3 "2017-07-18T12:25:10Z")

</div>

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?

```python
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]

```

---

<div class="post-metadata">

**Author:** ![jonsjoberg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jonsjoberg/32/24_2.png) [@jonsjoberg](https://discourse.pymc.io/u/jonsjoberg)\
**Post date:** [July 18, 2017, 2:39pm UTC](https://discourse.pymc.io/t/slowdown-in-latest-pymc/173/4 "2017-07-18T14:39:53Z")

</div>

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…
