transformers icon indicating copy to clipboard operation
transformers copied to clipboard

pretrained model(s) in onnx format

Open WilliamTambellini opened this issue 7 years ago • 10 comments

hi, would you assist/help in order to export/convert at least 1 model into the onnx format ? https://onnx.ai kind

WilliamTambellini avatar Feb 07 '19 00:02 WilliamTambellini

Hi @WilliamTambellini, have you tried to follow the standard ONNX procedure for converting a PyTorch model? The model in this repo are just regular PyTorch models.

thomwolf avatar Feb 11 '19 15:02 thomwolf

Hello Thomas, I ve not yet tried, just seen : https://github.com/onnx/models/issues/130 https://stackoverflow.com/questions/54220042/how-do-you-generate-an-onnx-representation-of-a-pytorch-bert-pretrained-neural-n Will try, tks.

WilliamTambellini avatar Feb 22 '19 21:02 WilliamTambellini

Hi, when I try to export a TokenClassification model to a ONNX model, I encounter RuntimeError: ONNX export failed: Couldn't export operator aten::erf, does that mean some part of BERT model layers not supported by ONNX? I think that problem comes from the definition of GELU function, which is x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))). Should I try to use other way to calculate this function or wait for ONNX to support this opertator?

geekboood avatar Apr 26 '19 04:04 geekboood

@geekboood update your pytorch version to latest and the problem will most likely go away.

maeotaku avatar May 23 '19 03:05 maeotaku

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 22 '19 03:07 stale[bot]

for anyone who is looking for the answer: torch=1.1.0 python=3.6

torch.onnx.export(model, (input_ids, segment_ids, input_mask), "bert.onnx", verbose=False)

works well for me

leerumor avatar Aug 14 '19 05:08 leerumor

for anyone who is looking for the answer: torch=1.1.0 python=3.6

torch.onnx.export(model, (input_ids, segment_ids, input_mask), "bert.onnx", verbose=False)

works well for me

Hi, thanks for the answer. Do you get good results when using the exported model for inference in another framework? I exported a BertForQuestionAnswering model to ONNX without errors, but I'm getting wrong predictions when using onnxruntime or a second export to TF Serving and I can't figure out why!

paulachocron avatar Aug 21 '19 08:08 paulachocron

Not sure if this is still an issue for you but in the BertForSequenceClassification model the parameters are in a different order

torch.onnx.export(model, (input_ids, input_mask, segment_ids), "bert.onnx", verbose=False)

works as intended

chessgecko avatar Sep 18 '19 01:09 chessgecko

@chessgecko wow you're right, thanks! working now

paulachocron avatar Oct 09 '19 10:10 paulachocron

cc @mfuntowicz :)

julien-c avatar Oct 09 '19 14:10 julien-c