Skip to content

Instantly share code, notes, and snippets.

@cdw
Last active September 21, 2021 23:02
Show Gist options
  • Save cdw/2fca134ef8a78cd82ff8e2673fce14dc to your computer and use it in GitHub Desktop.
Save cdw/2fca134ef8a78cd82ff8e2673fce14dc to your computer and use it in GitHub Desktop.
ONNX Conversion for SQuAD example
torch.onnx.export(model = torch_model,
args = (dummy_input['input_ids'].to(device), dummy_input['attention_mask'].to(device)), #Tuple of inputs for models that take more than one input
f = onnx_path,
export_params = True,
opset_version=11,
do_constant_folding = True,
input_names = ['input_ids', 'attention_mask'],
output_names = ['output'],
dynamic_axes = {'input_ids': {0: 'batch_size'},
'attention_mask': {0: 'batch_size'},
'output': {0: 'batch_size'}}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment