Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select GPU during execution in Theano

I am training neural nets with theano and lasagne on a 4 GPU machine. My .theanorc contains the following lines:

[global]
device = gpu0

So when in python I execute import theano, I get Using gpu device 0: GRID K520

What if, after importing theano, I chose to use say gpu1? I'd like to do this dynamically, that is, without editing .theanorc is it possible? Or even to choose it at runtime?

like image 255
P. Camilleri Avatar asked Aug 13 '15 09:08

P. Camilleri


1 Answers

EDIT: Theano is now based on the GPU array backend and the following API is no longer available.

As @EelkeSpaak mentioned, you can't change the GPU device after theano was imported. But if you want to choose it programmatically before that's possible without changing environment variables.

  1. Make sure you're not choosing a device in your .theanorc file. So nothing like:

    device=gpu

  2. before calling import theano choose the GPU device as follows:

    import theano.sandbox.cuda
    theano.sandbox.cuda.use('gpu1')
    
    #Results in Using gpu device 1: Tesla K80
    
like image 96
gidim Avatar answered Oct 21 '22 00:10

gidim