Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSTM CudaNdarrayType(float32, col)' and 'CudaNdarrayType(float32, matrix) error #3641

Closed
qq775193759 opened this issue Aug 31, 2016 · 7 comments

Comments

@qq775193759
Copy link

qq775193759 commented Aug 31, 2016

I used LSTM to solve my question. When I upgrade my environment I meet some error.
data.shape : (191, 128, 130)
label.shape : (191, 128, 1)
The cause of error is the dimension of label is 1. I have tried to use label.shape =(191, 128, 2), in this case, there is no error.

environment and version:
Ubuntu 14.04.4
Theano (0.9.0dev2)
Keras (1.0.8)

Code:

from keras.models import Sequential
from keras.layers.recurrent import LSTM
import numpy as np


model = Sequential()
model.add(LSTM(128, input_dim=130, return_sequences=True))
model.add(LSTM(1, return_sequences=True))
model.compile(optimizer='rmsprop',loss='mse')

data = np.random.random([191,128,130])
label = np.random.random([191,128,1])

model.fit(data, label, nb_epoch=20, batch_size=32, validation_split=0.25)

Error:

Using Theano backend.
Using gpu device 0: GeForce GTX 970 (CNMeM is enabled with initial size: 80.0% of memory, cuDNN 4007)
(191, 128, 130)
(191, 128, 1)
Traceback (most recent call last):
File "lstm_part.py", line 34, in
model.fit(data, label, nb_epoch=20, batch_size=32, validation_split=0.25)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 620, in fit
sample_weight=sample_weight)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1061, in fit
self._make_test_function()
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 716, in _make_test_function
*_self._function_kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/theano_backend.py", line 682, in function
return Function(inputs, outputs, updates=updates, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/theano_backend.py", line 668, in init
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/function.py", line 326, in function
output_keys=output_keys)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 484, in pfunc
output_keys=output_keys)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 1789, in orig_function
defaults)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 1653, in create
input_storage=input_storage_lists, storage_map=storage_map)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/link.py", line 699, in make_thunk
storage_map=storage_map)[:3]
File "/usr/local/lib/python2.7/dist-packages/theano/gof/vm.py", line 1051, in make_all
no_recycling))
File "/usr/local/lib/python2.7/dist-packages/theano/scan_module/scan_op.py", line 730, in make_thunk
self.validate_inner_graph()
File "/usr/local/lib/python2.7/dist-packages/theano/scan_module/scan_op.py", line 249, in validate_inner_graph
(self.name, type_input, type_output))
TypeError: ('The following error happened while compiling the node', forall_inplace,gpu,scan_fn}(Shape_i{1}.0, GpuSubtensor{int64:int64:int8}.0, GpuIncSubtensor{InplaceSet;:int64:}.0, DeepCopyOp.0, Shape_i{1}.0, lstm_2_U_o, lstm_2_U_f, lstm_2_U_i, lstm_2_U_c), '\n', "Inconsistency in the inner graph of scan 'scan_fn' : an input and an output are associated with the same recurrent state and should have the same type but have type 'CudaNdarrayType(float32, col)' and 'CudaNdarrayType(float32, matrix)' respectively.")

@renzeya
Copy link

renzeya commented Sep 9, 2016

I met the same problem.

@cbdbdd
Copy link

cbdbdd commented Sep 22, 2016

i met the same problem. if i use model.add(LSTM(2, return_sequences=True)) instead of model.add(LSTM(1, return_sequences=True)), it's just fine.
is it a cuda bug or keras bug?

@cbdbdd
Copy link

cbdbdd commented Sep 22, 2016

again,i saw people run in #3086:
from keras.models import Model
import numpy as np
from keras.layers import Masking, Activation, Input, LSTM, merge
a = np.array([[[.3,.1,.2,.2,.1,.1],[.2,.3,.3,.3,.3,.1],[0,0,0,0,0,0]]])

inputs = Input(shape=(3,6))
mask = Masking(mask_value=0.0)(inputs)
fw = LSTM(1,return_sequences=True)(mask)
bw = LSTM(1,return_sequences=True,go_backwards=True)(mask)
merged = merge([fw,bw],mode='sum')
model = Model(input=inputs,output=fw)

model.predict(a)

but for me, it reports the same error:"Inconsistency in the inner graph of scan 'scan_fn' : an input and an output are associated with the same recurrent state and should have the same type but have type 'CudaNdarrayType(float32, col)' and 'CudaNdarrayType(float32, matrix)' respectively.")

@nouiz
Copy link
Contributor

nouiz commented Sep 22, 2016

I'll try to explain. The problem is how Theano is used. We could relax that
restriction, but this would postpone some error and give an error that is
hard to have back to the origin.

The problem is that a recurrent state is defined as being a col, a matrix
with only one column. But the new value for the state is a matrix that have
an undefined number of columns. So this graph could fail at execution. Or
it could be that it is not possible to infer the number of columns or
Theano isn't able to infer it.

So what to do? There is a few options.

1 Make the original state a matrix. This is what happen when the shape is
set to 2. Or you can force the creation as a matrix.

2 you could tell Theano that the output is really a col. Similar to adding
shape information in the middle of the graph. This can be done by calling
patternbroadcast at the right place in keras.

Le 22 sept. 2016 06:24, "cbdbdd" notifications@github.com a écrit :

again,i saw people run in #3086
#3086:
from keras.models import Model
import numpy as np
from keras.layers import Masking, Activation, Input, LSTM, merge
a = np.array([[[.3,.1,.2,.2,.1,.1],[.2,.3,.3,.3,.3,.1],[0,0,0,0,0,0]]])

inputs = Input(shape=(3,6))
mask = Masking(mask_value=0.0)(inputs)
fw = LSTM(1,return_sequences=True)(mask)
bw = LSTM(1,return_sequences=True,go_backwards=True)(mask)
merged = merge([fw,bw],mode='sum')
model = Model(input=inputs,output=fw)

model.predict(a)

but for me, it reports the same error:"Inconsistency in the inner graph of
scan 'scan_fn' : an input and an output are associated with the same
recurrent state and should have the same type but have type
'CudaNdarrayType(float32, col)' and 'CudaNdarrayType(float32, matrix)'
respectively.")


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#3641 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AALC-yBWV5GVdIuGUxAVsTRDAqhQWv-Jks5qsldpgaJpZM4Jxa6C
.

@MaigoAkisame
Copy link

Thanks patyork for the redirection! So there is no solution yet?

@nouiz
Copy link
Contributor

nouiz commented Jan 24, 2017 via email

@stale stale bot added the stale label May 23, 2017
@stale stale bot closed this as completed Jun 22, 2017
@hft7h11
Copy link

hft7h11 commented Jan 1, 2018

@nouiz
Do you know the number of that PR? I am still experiencing this on Keras 2.1.2 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants