38

I'm new to Theano. Trying to set up a config file.

First of all, I notice that I have no .theanorc file:

  1. locate .theanorc - returns nothing
  2. echo $THEANORC - returns nothing
  3. theano.test() - passes ok

I'm guessing some default configuration was created wen i installed theano. Where is it?

eran
  • 14,496
  • 34
  • 98
  • 144

5 Answers5

46

Theano does not create any configuration file by itself, but has default values for all its configuration flags. You only need such a file if you want to modify the default values.

This can be done by creating a .theanorc file in your home directory. For example, if you want floatX to be always float32, you can do this:

echo -e "\n[global]\nfloatX=float32\n" >> ~/.theanorc

under Linux and Mac. Under windows, this can also be done. See this page for more details:

http://deeplearning.net/software/theano/library/config.html

Chiffa
  • 1,486
  • 2
  • 19
  • 38
nouiz
  • 5,071
  • 25
  • 21
  • What is the `$home` they say in the theano config link? How can I find it on Windows? – Daniel Möller Aug 16 '17 at 14:13
  • You can also set environment variables using `export THEANO_FLAGS="floatX=float32,device=opencl0:1,openmp=True"` in your `.bashrc` or equivalent. The environment variable format can be useful if you want to temporarily alter Theano's config for a single command. – BallpointBen May 07 '18 at 18:54
10

In Linux in terminal Home directory write:

nano .theanorc

In the file copy the following lines

[global]
floatX = float32
device = gpu0

[lib]
cnmem = 1   

Save it.

When I import theano in python I was having cnmem memory problems. Seems that is because the monitor is connected to the gpu. To resolve it change cnmem to 0.8. This number below 1 is the percentage of gpu reserved for theano

Farrael15
  • 196
  • 1
  • 8
  • when I followed your instructions, I started to get `ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.` I think [nvcc] needs to be defined in the .theanorc file as well. – Zhubarb Dec 18 '16 at 14:08
  • This worked for me on Ubuntu 14.04 with 1080 ti gpu. I did not include cnmem = 1 and device = cuda – scottlittle Jun 08 '17 at 22:27
3

I had a similar question and this is what helped me:

import theano
//...
theano.config.floatX = 'float32' //or 'float64' whatever you want
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
Jorge
  • 47
  • 2
  • 1
    Please explain what each line does. – Ali Bdeir Sep 14 '16 at 07:07
  • 6
    you cannot set device = 'gpu' (after initialization) in this manner though, you need to create a .theanorc file under /HOME for this – Zhubarb Dec 18 '16 at 14:03
  • Also, if you use float64 with Theano, you can't use the the GPU version. See here: https://stackoverflow.com/questions/35998515/why-does-the-floatxs-flag-impact-whether-gpu-is-used-in-theano?rq=1 – StatsSorceress May 25 '17 at 20:07
  • 1
    @Rhubarb in windows, where to create the `.theanorc.txt` file and how to make theano able to see it? – A_Matar Aug 05 '17 at 16:17
1

This worked for me:

nano ~/.theanorc

Then I entered:

[global]
floatX = float32
device = cuda

Code to check if Theano is using the GPU is on the Theano doc page.

(I am using Ubuntu 14.04, Theano 0.9.0 (conda), NVIDIA 1080 Ti GPU).

scottlittle
  • 18,866
  • 8
  • 51
  • 70
1

I have been having similar problems. I have NVIDIA 1070 GPU on a desktop machine with Asus Z270E motherboard and was able to import theano after setting up the .theanorc file as below. (And rebooting afterwards)

[global]
floatX = float32
device = gpu

[cuda]
root = /usr/local/cuda
[lib]
cnmem = 1   
Tahir
  • 31
  • 2