I am unable to run the NUTS sampler in PyMC3. The case I am running is a straigh…tforward transcription of the basis Normal distribution case in the regression example at http://docs.pymc.io/notebooks/getting_started#Installation:
import numpy as np
import matplotlib.pyplot as plt
import pymc3 as pm
#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 of dataset
size = 100
# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2
# Simulate outcome variable
Y = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma
fig, axes = plt.subplots(1, 2, sharex=True, figsize=(10,4))
axes[0].scatter(X1, Y)
axes[1].scatter(X2, Y)
axes[0].set_ylabel('Y'); axes[0].set_xlabel('X1'); axes[1].set_xlabel('X2');
plt.show()
basic_model = pm.Model()
with basic_model:
# Priors for unknown model parameters
alpha = pm.Normal('alpha', mu=0, sd=10)
beta = pm.Normal('beta', mu=0, sd=10, shape=2)
sigma = pm.HalfNormal('sigma', sd=1)
# Expected value of outcome
mu = alpha + beta[0]*X1 + beta[1]*X2
# Likelihood (sampling distribution) of observations
Y_obs = pm.Normal('Y_obs', mu=mu, sd=sigma, observed=Y)
map_estimate = pm.find_MAP(model=basic_model, method='powell')
print(map_estimate)
with basic_model:
# draw 500 posterior samples
trace = pm.sample(500)
This code appears to work properly up to the point where the pm.sample line is encountered. At that point I receive a pygpu.gpuarray.GpuArrayException invalid value error. The following is the complete response from the run including traceback:
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Using cuDNN version 5105 on context None
Mapped name None to device cuda: GeForce GTX 950 (0000:03:00.0)
0%| | 0/5000 [00:00<?, ?it/s]D
:\Programs\Anaconda3\Lib\site-packages\scipy\optimize\_minimize.py:502: RuntimeWarning: Method powell does not use gradi
ent information (jac).
RuntimeWarning)
logp = -148.98, ||grad|| = 0.73744: 100%|███████████████████████████████████████████| 183/183 [00:00<00:00, 185.38it/s]
{'alpha': array(0.9090931, dtype=float32), 'beta': array([0.9514547, 2.6145666], dtype=float32), 'sigma_log__': array(-0
.03494539, dtype=float32), 'sigma': array(0.9656581, dtype=float32)}
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma_log__, beta, alpha]
joblib.externals.loky.process_executor._RemoteTraceback:
"""
Traceback (most recent call last):
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\backend\queues.py", line 151, in _feed
obj, reducers=reducers)
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\backend\reduction.py", line 145, in dumps
p.dump(obj)
File "D:\Programs\Anaconda3\Lib\site-packages\theano\gpuarray\type.py", line 909, in GpuArray_pickler
return (GpuArray_unpickler, (np.asarray(cnda), ctx_name))
File "D:\Programs\Anaconda3\Lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
File "pygpu\gpuarray.pyx", line 1735, in pygpu.gpuarray.GpuArray.__array__
File "pygpu\gpuarray.pyx", line 1405, in pygpu.gpuarray._pygpu_as_ndarray
File "pygpu\gpuarray.pyx", line 394, in pygpu.gpuarray.array_read
pygpu.gpuarray.GpuArrayException: b'cuMemcpyDtoHAsync(dst, src->ptr + srcoff, sz, ctx->mem_s): CUDA_ERROR_INVALID_VALUE:
invalid argument'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ".\Regression_Case.py", line 50, in <module>
trace = pm.sample(500)
File "D:\Programs\Anaconda3\Lib\site-packages\pymc3\sampling.py", line 442, in sample
trace = _mp_sample(**sample_args)
File "D:\Programs\Anaconda3\Lib\site-packages\pymc3\sampling.py", line 982, in _mp_sample
traces = Parallel(n_jobs=cores, mmap_mode=None)(jobs)
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\parallel.py", line 962, in __call__
self.retrieve()
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\parallel.py", line 865, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\_parallel_backends.py", line 515, in wrap_future_result
return future.result(timeout=timeout)
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\_base.py", line 431, in result
return self.__get_result()
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\_base.py", line 382, in __get_result
raise self._exception
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\backend\queues.py", line 151, in _feed
obj, reducers=reducers)
File "D:\Programs\Anaconda3\Lib\site-packages\joblib\externals\loky\backend\reduction.py", line 145, in dumps
p.dump(obj)
File "D:\Programs\Anaconda3\Lib\site-packages\theano\gpuarray\type.py", line 909, in GpuArray_pickler
return (GpuArray_unpickler, (np.asarray(cnda), ctx_name))
File "D:\Programs\Anaconda3\Lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
File "pygpu\gpuarray.pyx", line 1735, in pygpu.gpuarray.GpuArray.__array__
File "pygpu\gpuarray.pyx", line 1405, in pygpu.gpuarray._pygpu_as_ndarray
File "pygpu\gpuarray.pyx", line 394, in pygpu.gpuarray.array_read
pygpu.gpuarray.GpuArrayException: b'cuMemcpyDtoHAsync(dst, src->ptr + srcoff, sz, ctx->mem_s): CUDA_ERROR_INVALID_VALUE:
invalid argument'
The following are my versions and main components
* PyMC3 Version: 3.4.1
* Theano Version: 1.0.2
* Python Version: 3.6.5
* Operating system: Windows 10
* How did you install PyMC3: (conda/pip): conda
I was hoping to use PyMC3 in an upcoming project, so any assistance you might provide would be much appreciated.