# \[KERAS\] LSTM return\_sequences parameter not supported

**URL:** <https://discuss.tvm.apache.org/t/keras-lstm-return-sequences-parameter-not-supported/11239>\
**Category:** Uncategorized\
**Created:** [October 13, 2021, 9:35pm UTC](https://discuss.tvm.apache.org/t/keras-lstm-return-sequences-parameter-not-supported/11239 "2021-10-13T21:35:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apivovarov](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/apivovarov/32/206_2.png) [@apivovarov](https://discuss.tvm.apache.org/u/apivovarov)\
**Post date:** [October 13, 2021, 9:35pm UTC](https://discuss.tvm.apache.org/t/keras-lstm-return-sequences-parameter-not-supported/11239/1 "2021-10-13T21:35:38Z")

</div>

I found that TVM Keras frontend does not support `return_sequences` parameter. [TVM Keras LSTM Impl](https://github.com/apache/tvm/blob/main/python/tvm/relay/frontend/keras.py#L879) and [LSTM Tests](https://github.com/apache/tvm/blob/main/tests/python/frontend/keras/test_forward.py#L423)

`return_sequences=True` changes output shape of the LSTM layer e.g.

```auto
Input(1,30,25) -> LSTM(100) -> 1,100
Input(1,30,25) -> LSTM(100, return_sequences=True) -> 1,30,100

```

Because `return_sequences` param is not supported `relay.build` fails with error ` Check failed: oshape_sum == data_shape_sum (3000 vs. 100) : Input tensor shape and reshaped shape are not compatible`:

```auto
import keras
import tvm
from tvm import relay

m = keras.Sequential()
m.add(keras.layers.LSTM(100, input_shape=(30,25), return_sequences=True))
m.compile()
m.summary()

shape_dict={"lstm_1_input":[1,30,25]}
mod, params = relay.frontend.from_keras(m, shape_dict)

target = "llvm"
ctx = tvm.cpu(0)

with tvm.transform.PassContext(opt_level=3):
    graph, lib, params = relay.build(mod, target=target, params=params)

```

@Huyuwei

---

<div class="post-metadata">

**Author:** ![apivovarov](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/apivovarov/32/206_2.png) [@apivovarov](https://discuss.tvm.apache.org/u/apivovarov)\
**Post date:** [October 15, 2021, 8:37pm UTC](https://discuss.tvm.apache.org/t/keras-lstm-return-sequences-parameter-not-supported/11239/2 "2021-10-15T20:37:00Z")

</div>

The Fix - [https://github.com/apache/tvm/pull/9303](https://github.com/apache/tvm/pull/9303)
