keras: Invalid value ("cpu") for configuration variable "gpu". Valid options start with one of "device", "opencl", "cuda"
When I try to run this command “import keras” I got this error:
Invalid value (“cpu”) for configuration variable “gpu”. Valid options start with one of “device”, “opencl”, “cuda”
Both Keras and Theano are updated to the latest version.
Here is THEANO_FlAGS env variable: “floatX=float32,device=gpu,nvcc.fastmath=True,lib.cnmem=0.6,nvcc.flags=-D_FORCE_INLINES”
I also tried “device=cuda” and “device=cuda0” now I’m getting this error:
C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\configdefaults.py:1711: UserWarning: Theano does not recognise this flag: lib.cnmem warnings.warn(‘Theano does not recognise this flag: {0}’.format(key)) C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\configdefaults.py:1711: UserWarning: Theano does not recognise this flag: nvcc.fastmath warnings.warn(‘Theano does not recognise this flag: {0}’.format(key)) C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\configdefaults.py:1711: UserWarning: Theano does not recognise this flag: nvcc.flags warnings.warn(‘Theano does not recognise this flag: {0}’.format(key)) ERROR (theano.gpuarray): Could not initialize pygpu, support disabled Traceback (most recent call last): File “C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\gpuarray_init _.py”, line 175, in <module> use(config.device) File “C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\gpuarray_init _.py”, line 162, in use init_dev(device, preallocate=preallocate) File “C:\Users\Ibrahim Amer\Anaconda\lib\site-packages\theano\gpuarray_init _.py”, line 65, in init_dev sched=config.gpuarray.sched) File “pygpu\gpuarray.pyx”, line 614, in pygpu.gpuarray.init (pygpu/gpuarray.c: 9415) File “pygpu\gpuarray.pyx”, line 566, in pygpu.gpuarray.pygpu_init (pygpu/gpuar ray.c:9106) File “pygpu\gpuarray.pyx”, line 1021, in pygpu.gpuarray.GpuContext.cinit ( pygpu/gpuarray.c:13468) GpuArrayException: Error loading library: 0
When I try to run this code I get “used the cpu”:
`vlen = 10 * 30 * 768 # 10 x #cores x # threads per core iters = 1000
rng = numpy.random.RandomState(22) x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) f = function([], tensor.exp(x)) print(f.maker.fgraph.toposort()) t0 = time.time() for i in range(iters): r = f() t1 = time.time() print(“Looping %d times took %f seconds” % (iters, t1 - t0)) print(“Result is %s” % (r,)) if numpy.any([isinstance(x.op, tensor.Elemwise) and (‘Gpu’ not in type(x.op).name) for x in f.maker.fgraph.toposort()]): print(‘Used the cpu’) else: print(‘Used the gpu’)`
Windows 7, NVIDIA 1060 6GB CUDA 7.5 Graphics Driver: 378.92
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (1 by maintainers)
Best solution is to install the new backend for Theano: http://deeplearning.net/software/libgpuarray/installation.html#step-by-step-install
and then have
device = cuda0
(or whatever appropriate number) in the .theanorcI resolved my issue on Windows. I had THEANO_FLAGS set as a system environment variable with the line device=gpu, which was overriding my .theanorc file settings. I’m guessing the stable 0.9.0 version allowed for either gpu or cuda0, but the latest branch does not. Anyway, deleting the environment variable allowed my theanorc settings to go through and it works fine now.
No need to reinstall theano, just install the new backend, see the link above by the-moliver