I am new to PyTorch, and I built a custom BiLSTM model for sentiment analysis that uses pretrained Word2Vec embeddings. As the text I am passing in is variable in length, my forward method needs to pass in both the text and its length to use pad_packed_sequence:
 def forward(self, x, text_len):

The problem is trying to convert this model to ONNX.
My understanding is that the code should be something like this:
dummy_input_1 = torch.randn(1, seq_length, requires_grad=True).long()
dummy_input_2 = torch.randn(seq_length, requires_grad=True).long()

dynamic_axes = {'input_1' : {1 : 'len'}, 'input_2' : {0 : 'len'}, 
                'output1': {0: 'label'}} 

torch.onnx.export(model,
        args=(dummy_input_1, dummy_input_2),
        f='model.onnx',
        input_names=['input_1', 'input_2'],
        output_names=['output1'],
        dynamic_axes=dynamic_axes)

However, wouldn’t I need to define seq_length first? How do I do this? And is this even the correct approach?
And even if seq_length is fixed, I get an error:
IndexError: index out of range in self


Any help please?