rasbt / python-machine-learning-book

The "Python Machine Learning (1st edition)" book code repository and info resource

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python crushes when running theano code

BingKong1988 opened this issue · 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))

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

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

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

?

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.

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

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

Thank you!