I found that TVM Keras frontend does not support return_sequences
parameter. TVM Keras LSTM Impl and LSTM Tests
return_sequences=True
changes output shape of the LSTM layer e.g.
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
:
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)