python-machine-learning-book icon indicating copy to clipboard operation
python-machine-learning-book copied to clipboard

python crushes when running theano code

Open BingKong1988 opened this issue 9 years ago • 7 comments

Hi

I am trying to run the following code from the book in jupyter notebook with everything updated. However, every time python crushes and the kernel restarts. Everything is fine before this point. Any thought? ps. using 32bit and gpu, tried dmatrix, no luck chapter 13

import numpy as np x = T.dmatrix(name='x') x_sum = T.sum(x, axis=0) calc_sum = theano.function(inputs=[x],outputs=x_sum) ary = [[1,2,3],[1,2,3]] print('column sum:',calc_sum(ary))

BingKong1988 avatar Jun 30 '17 19:06 BingKong1988

Hi, there,

Does the problem only occur when you are running the code/notebook via GPU (i.e., does it work okay on CPU?).

Maybe try to run this snippet as a .py script instead of the notebook for further debugging of the issue. However, based on my experience, a restarting kernel is often related to memory issues, so maybe this wouldn't help.

However, I would maybe try it

THEANO_FLAGS=device=gpu,floatX=float32 python your_script.py

and

THEANO_FLAGS=device=cpu,floatX=float64 python your_script.py

to find out more

rasbt avatar Jul 01 '17 20:07 rasbt

THEANO_FLAGS=device=gpu,floatX=float32 this setting does solve the problem. I was using THEANO_FLAGS=device=cuda,floatX=float32, which allows the gpu test code here http://deeplearning.net/software/theano/tutorial/using_gpu.html to run. I am wondering if there is any difference between those two settings. Also it seems like there is no show_accuracy in keras.models.Sequential

Thanks

BingKong1988 avatar Jul 03 '17 17:07 BingKong1988

Thanks for the note about Keras; that's been the old syntax that has been deprecated. I changed it to make it Keras 2 compatible (see notebook here: https://github.com/rasbt/python-machine-learning-book/blob/master/code/ch13/ch13.ipynb)

As for Theano, not sure what causes this issue. From their website

Using the GPU in Theano is as simple as setting the device configuration flag to device=cuda (or device=gpu for the old backend (http://deeplearning.net/software/theano/tutorial/using_gpu.html)

Have you seen any meaningful error messages in the command line when you ran

THEANO_FLAGS=device=cuda,floatX=float32 python your_script.py

?

rasbt avatar Jul 05 '17 03:07 rasbt

fatal error: cudnn.h: No such file or directory\r\ncompilation terminated.\r\n' Mapped name None to device cuda: GeForce GTX 660 (0000:01:00.0) Using Theano backend.

I do get this error before python crushed.

BingKong1988 avatar Jul 05 '17 16:07 BingKong1988

And I just noticed that using this setting: THEANO_FLAGS=device=gpu,floatX=float32 python your_script.py can make the code up and running, but it is actually still using cpu

BingKong1988 avatar Jul 05 '17 22:07 BingKong1988

Hm, sounds like it's having issues with recognizing the cuda/cudnn installation? This might be a general theano setup problem. Maybe, you can find some useful information in their guide at http://deeplearning.net/software/theano/install.html

rasbt avatar Jul 05 '17 23:07 rasbt

Thank you!

BingKong1988 avatar Jul 06 '17 16:07 BingKong1988