I'm trying to exporting a roberta model from PyTorch to ONNX and running it using ONNX Runtime.
When I run the export
torch.onnx.export(roberta_model,
(input_ids),
ONNX_path,
input_names=['input'],
output_names=['output'],
dynamic_axes={'input' :{0 : 'batch_size',
1: 'sentence_length'},
'output': {0: 'batch_size'}})
input_ids is:
input_ids = torch.tensor(profiles_input).squeeze(0)
It gives me the runtime error:
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got torch.FloatTensor instead (while checking arguments for embedding)
I have searched this error and most answers say to convert to long.
I tried the following ways to convert to long
input_ids = input_ids.type(torch.LongTensor)
and
c_input_ids = input_ids.long()
But it just gives me an out of index error:
IndexError: index out of range in self
Also tried matching the vocab size according to this StackOverflow answer While training BERT variant, getting IndexError: index out of range in self
tokenizer = RobertaTokenizer.from_pretrained(model_name)
config = transformers.RobertaConfig()
config.vocab_size = RobertaTokenizer.vocab_size
But I still see the same runtime error.
Can I get some guidance on how to fix this?
This export was working before but now that I have loaded a model that I trained on my data it stopped working. There's no errors when loading the model_state_dict from my trained model.