fairseq icon indicating copy to clipboard operation
fairseq copied to clipboard

How to convert a fairseq transformer model into ONNX format?

Open wolfshow opened this issue 5 years ago • 10 comments

Any documentation or tools? Thanks!

wolfshow avatar Jul 23 '19 08:07 wolfshow

I would like to contribute if someone can guide me

adikshit avatar Aug 08 '19 03:08 adikshit

Also interested in being able to do this..

echan00 avatar Nov 07 '19 07:11 echan00

i need it too!tks! i write code to convert onnx but it is not work! `import torch import onnx

en2de = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-de.single_model') output = en2de.translate('Hello world', beam=5) #print("This is output:", output) model = en2de.eval() # disable dropout #print(model)

dummy_input1 = torch.ones(1, 4, device='cpu', dtype=torch.long) dummy_input2 = torch.ones(1, device='cpu', dtype=torch.long) dummy_input3 = torch.ones(5, 5, device='cpu', dtype=torch.long) inputs = (dummy_input1, dummy_input2, dummy_input3)

input_names = ["src_tokens", "src_lengths", "prev_output_tokens"] #output_names = ["start_logits","end_logits"] torch.onnx.export(model, inputs, "fairseq_transformer.onnx", verbose=True, input_names=input_names, output_names=["output"], export_params=True, opset_version=13, do_constant_folding = True, )#operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK #checker onnx_file = onnx.load("fairseq_transformer.onnx") onnx.checker.check_model(onnx_file)`

The error sheetshot is : image

rGitcy avatar Jan 27 '22 06:01 rGitcy

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] avatar Apr 27 '22 22:04 stale[bot]

@rGitcy any comment?

WilliamTambellini avatar Apr 27 '22 22:04 WilliamTambellini

@rGitcy 请问您解决这个问题了吗,我遇到了很您相似的问题。Have you solved this issue?

pkuwudi avatar May 18 '22 11:05 pkuwudi

@rGitcy 请问您解决这个问题了吗,我遇到了很您相似的问题。Have you solved this issue?

没有,感觉官方repo有些问题

rGitcy avatar Jul 20 '22 05:07 rGitcy

any progress?

logicvv avatar Nov 27 '23 05:11 logicvv

This is much needed! Any progress?

kabyanil avatar Feb 08 '24 15:02 kabyanil