This is an automated email from the ASF dual-hosted git repository.
syfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 24ae0d5b05 [bugfix][frontend][keras] Fix go_backwards attribute of
LSTM in keras frontend (#15261)
24ae0d5b05 is described below
commit 24ae0d5b05c8cb6ec7c9ad3847bf5f4eb9fd1242
Author: Qingchao Shen <[email protected]>
AuthorDate: Sat Jul 8 16:33:11 2023 +0800
[bugfix][frontend][keras] Fix go_backwards attribute of LSTM in keras
frontend (#15261)
---
python/tvm/relay/frontend/keras.py | 2 ++
tests/python/frontend/keras/test_forward.py | 2 ++
2 files changed, 4 insertions(+)
diff --git a/python/tvm/relay/frontend/keras.py
b/python/tvm/relay/frontend/keras.py
index 3dc0551084..0d932cadcc 100644
--- a/python/tvm/relay/frontend/keras.py
+++ b/python/tvm/relay/frontend/keras.py
@@ -1005,6 +1005,8 @@ def _convert_lstm(
recurrent_weight = etab.new_const(weightList[1].transpose([1, 0]))
if keras_layer.use_bias:
in_bias = etab.new_const(weightList[2])
+ if keras_layer.go_backwards:
+ in_data = _op.reverse(in_data, axis=1)
units = list(weightList[0].shape)[1]
time_steps = in_shape[1]
in_data = _op.squeeze(in_data, axis=[0])
diff --git a/tests/python/frontend/keras/test_forward.py
b/tests/python/frontend/keras/test_forward.py
index 2584a36e32..50a0e98505 100644
--- a/tests/python/frontend/keras/test_forward.py
+++ b/tests/python/frontend/keras/test_forward.py
@@ -525,6 +525,8 @@ class TestKeras:
rnn_funcs = [
keras_mod.layers.LSTM(16),
keras_mod.layers.LSTM(16, return_sequences=True),
+ keras_mod.layers.LSTM(16, go_backwards=True),
+ keras_mod.layers.LSTM(16, return_sequences=True,
go_backwards=True),
keras_mod.layers.LSTM(16, return_sequences=True, use_bias=False),
]
for rnn_func in rnn_funcs: