I have some pickle files of deep learning models built on gpu. I'm trying to use them in production. But when i try to unpickle them on the server, i'm getting the following error.
Traceback (most recent call last):
File "score.py", line 30, in
model = (cPickle.load(file))
File "/usr/local/python2.7/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/sandbox/cuda/type.py", line 485, in CudaNdarray_unpickler
return cuda.CudaNdarray(npa)
AttributeError: ("'NoneType' object has no attribute 'CudaNdarray'", , (array([[ 0.011515 , 0.01171047, 0.10408644, ..., -0.0343636 ,
0.04944979, -0.06583775],
[-0.03771918, 0.080524 , -0.10609912, ..., 0.11019105,
-0.0570752 , 0.02100536],
[-0.03628891, -0.07109226, -0.00932018, ..., 0.04316209,
0.02817888, 0.05785328],
...,
[ 0.0703947 , -0.00172865, -0.05942701, ..., -0.00999349,
0.01624184, 0.09832744],
[-0.09029484, -0.11509365, -0.07193922, ..., 0.10658887,
0.17730837, 0.01104965],
[ 0.06659461, -0.02492988, 0.02271739, ..., -0.0646857 ,
0.03879852, 0.08779807]], dtype=float32),))
I checked for that cudaNdarray package in my local machine and it is not installed, but still i am able to unpickle them. But in the server, i am unable to. How do i make them to run on a server which doesnt have a GPU?
There is a script in pylearn2 which may do what you need:
pylearn2/scripts/gpu_pkl_to_cpu_pkl.py
I solved this problem by just saving the parameters W & b, but not the whole model. You can save the parameters use this:http://deeplearning.net/software/theano/tutorial/loading_and_saving.html?highlight=saving%20load#robust-serialization This can save the CudaNdarray to numpy array. Then you need to read the params by numpy.load(), and finally convert the numpy array to tensorSharedVariable use theano.shared().
This works for me. Note: this doesn't work unless the following environment variable is set:
export THEANO_FLAGS='device=cpu'
The related Theano code is here.
From there, it looks like there is an option
config.experimental.unpickle_gpu_on_cpu
which you could set and which would makeCudaNdarray_unpickler
return the underlying raw Numpy array.