-
Notifications
You must be signed in to change notification settings - Fork 74k
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
TF 2.0: Cannot use recurrent_dropout with LSTMs/GRUs #29187
Comments
Have tried with TensorFlow version 2.0.0-alpha and was able to reproduce the issue. |
Thanks for reporting the issue, let me take a look. |
They were missing for the non-defun branch. See tensorflow#29187 for more details. PiperOrigin-RevId: 251442578
Thanks for reporting the issue, it should now be fixed by 180f28a |
Btw, the current colab might not apply the dropout correctly if you only enable the dropout/recurrent_dropout on the GRU layer. Under the hood, the keras layer will check whether the current context is in training or inference, and only apply the dropout during training. If the GRU layer was using by a keras model together with model.fit/eval/predict, then the training context will be applied correctly. However, if the user is writing their own custom training loop, then the training context need to be set manually, eg by tf.keras.backend.set_learning_phase(1) # training
run_train_step()
tf.keras.backend.set_learning_phase(0)
run_eval_step() The other alternative is that make sure the encoder/decoder's call() method is training state aware. eg, the method could take a new kwarg training=None, and set to different value during training and inference. The training value need to be popagated to GRU's call() method as well. |
@qlzh727: Thanks a ton for your help on this! Quick follow-up: has this been fixed in the GPU version as well? I tried the (nightly) version from yesterday and it didn't seem to work. |
They were missing for the non-defun branch. See tensorflow#29187 for more details. PiperOrigin-RevId: 251442578
The issue still persists in the beta release |
I still have this issue in beta 2.0.0b1 |
For any of you that still facing the issue, could u provide a snippet to reproduce the issue? |
Similar error even without GRU.
|
@knobel-dk, I am bit confused about your message, this issue was about the recurrent_dropout for the LSTM/GRU layer, but your code doesn't have any LSTM/GRU layer within it. Could you be more specific about the error you are facing? |
Thanks. Yes I have confused myself too. Those stateful Jupyter notebooks.. I fixed my problem by updating the TF2 version. Thanks. |
System information
Describe the current behavior
The program crashes with a TypeError as below:
TypeError: An op outside of the function building code is being passed a "Graph" tensor. It is possible to have Graph tensors leak out of the function building context by including a tf.init_scope in your function building code. For example, the following function will fail: @tf.function def has_init_scope(): my_constant = tf.constant(1.) with tf.init_scope(): added = my_constant * 2 The graph tensor has name: encoder/unified_gru/ones_like:0
This occurs when trying to backprop the gradients through the LSTM/GRU with
recurrent_dropout
enabled.Describe the expected behavior
No error
Code to reproduce the issue
Since this problem shows up at the time of training, one needs to have the entire training pipeline (dataset, model etc.) setup to demonstrate this bug. As a result, I used the Neural Machine Translation tutorial from TensorFlow and modified their model to include
recurrent_dropout
. The entire code can be found in this Colab notebook; run the code blocks all the way till the block where we're training the model to see the bug.Other info.logs
The text was updated successfully, but these errors were encountered: