I’m trying to convert lstm-decoder with beam search to onnx, but I got some TracerWarnings. Is it possible to operate with int-number item from 1-size input tensor in my future code like this?
def forward(self, img_features, beam_size):
    '''
    Arguments:
        img_features (tensor): Extracted features from the encoder module. (batch_size, feature_pixels = 7x7, encoder_dim = 2048)
        beam_size (tensor): Number of top candidates to consider for beam search. (int, = 3 or =6 or =9)
    '''
    item = beam_size.item()
    #some code...
    output = torch.tensor([item])
    return output

Now I have this warnings and constant output of Onnx-model:
TracerWarning: Converting a tensor to a Python number might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  item = beam_size.item()

TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  output = torch.tensor([item])

I tried using @torch.jit.script but it didn’t help too