alexa / dialoglue

DialoGLUE: A Natural Language Understanding Benchmark for Task-Oriented Dialogue
https://evalai.cloudcv.org/web/challenges/challenge-page/708/overview
Apache License 2.0
279 stars 25 forks source link

ONNX conversion issue #12

Closed RaviMa-Kore closed 3 years ago

RaviMa-Kore commented 3 years ago

@mihail-amazon

Following this thread, I tried to convert convbert-dg model to ONNX format with the following snippet,

model = IntentBertModel('bert-base-uncased', dropout=0.1, num_intent_labels=len(intent_label_to_idx))
model.load_state_dict(torch.load(os.path.join(model_path, "model.pt"), map_location=torch.device('cpu')))
model.eval()

model_onnx_path = "model.onnx"
max_seq_length = 100
input_ids = torch.LongTensor(1, max_seq_length).to(device)
token_type_ids = torch.LongTensor(1, max_seq_length).to(device)
attention_mask = torch.LongTensor(1, max_seq_length).to(device)

dummy_input = (input_ids, attention_mask, token_type_ids)
input_names = ["input_ids", "attention_mask", "token_type_ids"]
output_names = ["output"]
torch.onnx.export(model, dummy_input, model_onnx_path, \
    input_names=input_names, output_names=output_names, \
    verbose=True)

and this throws,

RuntimeError: index out of range: Tried to access index -1457520640 out of table with 30521 rows.

Can you please correct me if there is anything wrong in the snippet I am using.