Sandipan Bhattacharyya
Sandipan Bhattacharyya

Reputation: 137

Keras with Theano on GPU

While trying to run my Keras code on GPU (CUDA installed), I am not able to execute the following statement, as has been suggested on many online references.

set THEANO_FLAGS="mode=FAST_RUN,device=gpu,floatX=float32" & python theanogpu_example.py

I am getting the following error.

ValueError: Invalid value ("FAST_RUN,device=gpu,floatX=float32") for configurati
on variable "mode". Valid options are ('Mode', 'DebugMode', 'FAST_RUN', 'NanGuar
dMode', 'FAST_COMPILE', 'DEBUG_MODE')

I have tried the other mode suggested as well from inside the code.

import theano
theano.config.device = 'gpu'
theano.config.floatX = 'float32'

I get the following error.

Exception: Can't change the value of this config parameter after initialization!

Apart from knowing how to make it run, I would also take this opportunity to ask a simpler question. How to know in Windows what is my device i.e. whether 'gpu' or 'gpu1' or 'gpu0'? I have tried all 3 for my case but it hasn't yielded result.

Any suggestions will be appreciated.

Upvotes: 0

Views: 3299

Answers (1)

Pedro Henrique
Pedro Henrique

Reputation: 19

The best way is using THEANO_FLAGS before run code, because the config variables cannot be changed after importing Theano, try this:

import os
os.environ['THEANO_FLAGS'] = "device=cuda,force_device=True,floatX=float32"
import theano

Upvotes: 1

Related Questions