OCR CNN with RNN model can't torch.jit.script with dynamic batch size inputs?

I’m creating a Pytorch OCR model with a Resnet based feature extractor with both ctc classifier and attention based classifer outputs.
It includes a BiLSTM layer that input from the resnet so I can recognize the text image. I’m trying to use the torchserve which the model need to be torch.jit.trace or torch.jit.script. I’m able to use the torch.jit.trace to create a traced model, however it shows the following errors when the input’s batch size not matching the batch size that being traced.

RuntimeError: self dim 0 must match batch2 dim 0

Then I try to use the torch.jit.script it shows the following error.

    276         method = getattr(self, 'build_' + node.__class__.__name__, None)
    277         if method is None:
--> 278             raise UnsupportedNodeError(ctx, node)
    279         return method(ctx, node)

UnsupportedNodeError: GeneratorExp aren't supported:
  File "/home/usr/venv/lib/python3.7/site-packages/torch/nn/modules/rnn.py", line 158
        # alias would break the assumptions of the uniqueness check in
        # Module.named_parameters().
        unique_data_ptrs = set(p.data_ptr() for p in self._flat_weights)
                               ~ <--- HERE
        if len(unique_data_ptrs) != len(self._flat_weights):

How can I solve this problem?

This might be due to an unsupported operand in torchserve. There is an open PR that might be related to your problem.

Dynamic Programming in Hidden Markov Models.11.5 Minibatch Stochastic Gradient Descent . In this book, we will teach most concepts just in time. 3.x you would download the bash script with strings “Miniconda3” and other considerations) the type, size, and the number of inputs and outputs.

Thanks for the information