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

Theano crash when LSTM layer's hidden size is 1 using Keras backend #6781

Open
maybeLee opened this issue Sep 3, 2021 · 0 comments
Open

Comments

@maybeLee
Copy link

maybeLee commented Sep 3, 2021

When I use Keras to construct a one LSTM layer DL model with hidden size=0 and further conduct model inference, theano will directly crash with the following traceback:

Traceback (most recent call last):
  File "/exp1/job1/scripts/generation/script_prediction.py", line 123, in <module>
    _get_prediction(bk=bk, x=x[:1500], model_path=flags.model_path, batch_size=batch_size)
  File "/exp1/job1/scripts/generation/script_prediction.py", line 42, in _get_prediction
    pred = model.predict(x,batch_size=batch_size)
  File "lib/python3.6/site-packages/keras/engine/training.py", line 1164, in predict
    self._make_predict_function()
  File "lib/python3.6/site-packages/keras/engine/training.py", line 554, in _make_predict_function
    **kwargs)
  File "lib/python3.6/site-packages/keras/backend/theano_backend.py", line 1397, in function
    return Function(inputs, outputs, updates=updates, **kwargs)
  File "lib/python3.6/site-packages/keras/backend/theano_backend.py", line 1383, in __init__
    **kwargs)
  File "lib/python3.6/site-packages/theano/compile/function.py", line 317, in function
    output_keys=output_keys)
  File "lib/python3.6/site-packages/theano/compile/pfunc.py", line 486, in pfunc
    output_keys=output_keys)
  File "lib/python3.6/site-packages/theano/compile/function_module.py", line 1841, in orig_function
    fn = m.create(defaults)
  File "lib/python3.6/site-packages/theano/compile/function_module.py", line 1715, in create
    input_storage=input_storage_lists, storage_map=storage_map)
  File "lib/python3.6/site-packages/theano/gof/link.py", line 699, in make_thunk
    storage_map=storage_map)[:3]
  File "lib/python3.6/site-packages/theano/gof/vm.py", line 1091, in make_all
    impl=impl))
  File "lib/python3.6/site-packages/theano/scan_module/scan_op.py", line 741, in make_thunk
    self.validate_inner_graph()
  File "lib/python3.6/site-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, Rebroadcast{?,?,0}.0, GpuIncSubtensor{InplaceSet;:int64:}.0, Shape_i{1}.0, GpuSubtensor{::, int64:int64:}.0, InplaceGpuDimShuffle{x,0}.0, GpuSubtensor{::, int64:int64:}.0, GpuSubtensor{::, :int64:}.0, InplaceGpuDimShuffle{x,0}.0, GpuSubtensor{::, :int64:}.0, GpuSubtensor{::, int64:int64:}.0, InplaceGpuDimShuffle{x,0}.0, GpuSubtensor{::, int64:int64:}.0, GpuSubtensor{::, int64::}.0, InplaceGpuDimShuffle{x,0}.0, GpuSubtensor{::, int64::}.0), '\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 'GpuArrayType<None>(float32, col)' and 'GpuArrayType<None>(float32, matrix)' respectively.")

However, when using other backend such as tensorflow or cntk, this model can be successfully loaded and run.
Please use the following script to reproduce this bug.

import os
import argparse
import sys
import warnings
parse = argparse.ArgumentParser()
parse.add_argument("--backend", type=str,default="theano", help="the name of backend")
flags, _ = parse.parse_known_args(sys.argv[1:])
os.environ["KERAS_BACKEND"]=flags.backend
import keras
from keras import initializers, layers
import numpy as np
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=UserWarning)
model = keras.models.Sequential()
model.add(layers.LSTM(1))
model.build((None, 49,1))
x = np.random.rand(10,49,1)
pred = model.predict(x)

The tested version of Theano is 1.0.4

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

1 participant