Hello, I am trying to export in onnx a Module using a simple Gru and some linear layers on top of it. The module is trained using packed sequences so there is no fixed length sequence at training time.
I can export the model my_model using onnx
input_names = [ "time series" ] + [ f"learned_{i}" for i, p in enumerate(my_model.parameters()) ]
output_names = [ "log probability" ]
dummy_input = torch.randn(100, device='cuda').view(-1, 1, 1)
dummy_output = torch.randn(100, 3, device='cuda').view(-1, 1, 3)
my_model_jit= torch.jit.script(my_model)
torch.onnx.export(my_model_jit, dummy_input, "my_model.onnx", verbose=True, input_names=input_names, output_names=output_names, example_outputs=dummy_output)
The issue issue is that when I load my exported model then I can only do inference for fixed length series of length 100 (which is the size I randomly picked for the example)
import onnxruntime as rt
sess = rt.InferenceSession(r"my_model.onnx")
input_name = sess.get_inputs()[0].name
# this is working fine with length = 100
ts = np.random.randn(100).cumsum().astype(np.float32).reshape( -1, 1, 1)
pred_onx = sess.run(None, {input_name: ts})
# this is failing with length != 100
ts = np.random.randn(110).cumsum().astype(np.float32).reshape( -1, 1, 1)
pred_onx = sess.run(None, {input_name: ts})
ouput :
---------------------------------------------------------------------------
InvalidArgument Traceback (most recent call last)
<ipython-input-162-da0f71c171b2> in <module>()
1 ts = np.random.randn(110).cumsum().astype(np.float32).reshape( -1, 1, 1)
----> 2 pred_onx = sess.run(None, {input_name: ts})
c:\homeware\lib\site-packages\onnxruntime\capi\session.py in run(self, output_names, input_feed, run_options)
134 output_names = [output.name for output in self._outputs_meta]
135 try:
--> 136 return self._sess.run(output_names, input_feed, run_options)
137 except C.EPFail as err:
138 if self._enable_fallback:
InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: time series for the following indices
index: 0 Got: 110 Expected: 100
Please fix either the inputs or the model.
Is there a way to have a model without this limitation ie working like in pytorch ?
Thanks a lot