# PyMC3 with GPU support on Google Colab

**URL:** https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649
**Category:** Development
**Created:** [August 5, 2018, 10:27am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649 "2018-08-05T10:27:07Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Jack\_Caster](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jack_caster/32/644_2.png) [@Jack\_Caster](https://discourse.pymc.io/u/Jack_Caster)
#### Post date: [August 5, 2018, 10:27am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/1 "2018-08-05T10:27:08Z")

</div>

Google [Colab](https://colab.research.google.com/) is a Jupyter Notebook-based cloud service which gives free GPU use. I am wondering if anyone of you managed to get a working PyMC3 environment with GPU support. I struggle to get all the dependencies right (CUDA, pyGPU, etc.). I have a tricky model, and I would like to see if the GPU speeds things up a bit.

---

<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: [August 5, 2018, 11:50am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/2 "2018-08-05T11:50:04Z")

</div>

+1  
Do you have a colab to show the things you had already tried?

---

<div class="post-metadata">

### Author: ![Jack\_Caster](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jack_caster/32/644_2.png) [@Jack\_Caster](https://discourse.pymc.io/u/Jack_Caster)
#### Post date: [August 5, 2018, 8:55pm UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/3 "2018-08-05T20:55:59Z")

</div>

Here’s the ipynb notebook [Theano\_with\_GPU.txt](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/8/8d0b5b95b817615a9dbc1633bab0c5be6cb8669a.txt) (401.0 KB) (please, change the extension to .ipynb, otherwise I could not upload the file).  
It is sort of working now. The Theano test shows that the GPU is in use, but the sampling is much slower compared to using the CPU only (we are talking about 1297 draws/sec with CPU compared to 270 draws/sec with GPU). PyGPU still complains that the CUDNN is not setup correctly, so maybe that’s why it is so slow. Maybe you can start from this example. I also noticed that the PyMC3 works only with 1 chain when the GPU is in use.

I started with the assumption that Colab fullfilled all the CUDA requirements. At first, I tried to patch all the errors that PyGPU was raising, trying to find the missing files in the system directories. But then more errors were raised. Therefore, I ended up reinstalling CUDA from scratch. The thing that is missing is a cudnn.h file that I cannot find.

---

<div class="post-metadata">

### Author: ![JWarmenhoven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jwarmenhoven/32/51_2.png) [@JWarmenhoven](https://discourse.pymc.io/u/JWarmenhoven)
#### Post date: [August 6, 2018, 8:57am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/4 "2018-08-06T08:57:34Z")

</div>

Regardless of the colab setup: as far as I know/have read most PyMC3 models generally do not see an increase in (sampling) speed when using a GPU instead of CPU.

My experience is that, when using the GPU, I need to set `cores=1` when sampling.  
See also:

> [@PyMC3 Pickle Issue with GPU](https://discourse.pymc.io/t/pymc3-pickle-issue-with-gpu/1559):
>
> I have recently installed PyMC3 under a Python 2.7 environment on my GPU-enhanced desktop PC. The installation was successful and I have been able to run the following sample code: import numpy as np import matplotlib.pyplot as plt import pymc3 as pm import seaborn as sns import time #print('Running on PyMC3 v{}'.format(pm.\_\_version\_\_)) plt.style.use('seaborn-darkgrid') # Initialize random number generator np.random.seed(123) # True parameter values alpha, sigma = 1, 1 beta = [1, 2.5] # Size…

---

<div class="post-metadata">

### Author: ![ded](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@ded](https://discourse.pymc.io/u/ded)
#### Post date: [September 20, 2018, 2:44pm UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/5 "2018-09-20T14:44:57Z")

</div>

I also tried colab unsuccessfully. It seems that it doesn’t support theano! Potentially because we can’t setup the theano flags.

---

<div class="post-metadata">

### Author: ![Amin\_Shn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/amin_shn/32/4976_2.png) [@Amin\_Shn](https://discourse.pymc.io/u/Amin_Shn)
#### Post date: [March 29, 2022, 4:05pm UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/6 "2022-03-29T16:05:53Z")

</div>

Is there any update on this topic since 2018? Does anyone know if it’s possible to use PyMC3 with GPU on Google Colab?

---

<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: [March 30, 2022, 6:34am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/7 "2022-03-30T06:34:43Z")

</div>

Have you try PyMC v4 with the Jax backend? should work out of the box.

---

<div class="post-metadata">

### Author: ![Amin\_Shn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/amin_shn/32/4976_2.png) [@Amin\_Shn](https://discourse.pymc.io/u/Amin_Shn)
#### Post date: [March 30, 2022, 7:13am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/8 "2022-03-30T07:13:40Z")

</div>

No I haven’t, do you have any example code? I struggle to find these things clearly explained somewhere. A vignette or an actual applied example could be very helpful.

---

<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: [March 30, 2022, 7:54am UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/9 "2022-03-30T07:54:53Z")

</div>

We are in the process of updating the doc, meanwhile this blog post ([MCMC for big datasets: faster sampling with JAX and the GPU - PyMC Labs](https://www.pymc-labs.io/blog-posts/pymc-stan-benchmark/)) should help ([code here](https://github.com/martiningram/mcmc_runtime_comparison))

cc @Martin_Ingram in case there is additional question.

---

<div class="post-metadata">

### Author: ![Amin\_Shn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/amin_shn/32/4976_2.png) [@Amin\_Shn](https://discourse.pymc.io/u/Amin_Shn)
#### Post date: [March 31, 2022, 5:35pm UTC](https://discourse.pymc.io/t/pymc3-with-gpu-support-on-google-colab/1649/10 "2022-03-31T17:35:31Z")

</div>

Thanks. Also I am not sure how to install PyMC v4 on Google Colab. Is it straightforward?
