rasbt / python-machine-learning-book

The "Python Machine Learning (1st edition)" book code repository and info resource
MIT License
12.24k stars 4.4k forks source link

python crushes when running theano code #51

Closed BingKong1988 closed 7 years ago

BingKong1988 commented 7 years ago

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))

rasbt commented 7 years ago

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

BingKong1988 commented 7 years ago

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

rasbt commented 7 years ago

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

?

BingKong1988 commented 7 years ago

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 commented 7 years ago

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

rasbt commented 7 years ago

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

BingKong1988 commented 7 years ago

Thank you!