kmkurn / pytorch-crf

(Linear-chain) Conditional random field in PyTorch.
https://pytorch-crf.readthedocs.io
MIT License
935 stars 151 forks source link

pytorch-crf model to onnx conversion #80

Closed 9lan9 closed 2 years ago

9lan9 commented 3 years ago

Actually, it is the same issue in https://github.com/pytorch/pytorch/issues/39245, any solution for this one?

kmkurn commented 3 years ago

I personally never used ONNX, so I don't think I can help, sorry! I'll keep the issue open in case anyone else can help.

9lan9 commented 3 years ago

I personally never used ONNX, so I don't think I can help, sorry! I'll keep the issue open in case anyone else can help.

ok, thanks.

sralvins commented 3 years ago

output of _viterbi_decode is a list of int lists with variable lengths which is invalid for onnx output. just convert it to a tensor. for example: image

9lan9 commented 3 years ago

output of _viterbi_decode is a list of int lists with variable lengths which is invalid for onnx output. just convert it to a tensor. for example: image

convert list to tensor would cause problems, that's the problem

SeanLiaoy commented 2 years ago

Cannot convert the CRF layer to ONNX even using the latest version of PyTorch. I guess the combination of some operators may cause issues in PyTorch converter. And it also cannot be converted to torchscript. Here is the version of CRF that can be converted torchscript: https://github.com/facebookresearch/pytext/blob/master/pytext/models/crf.py . Unfortunately, CRF code provided by pytext also cannot be converted to ONNX

etern commented 2 years ago

pytorch model is converted to ONNX via torchscript, this issue is related #79

Ulitochka commented 4 months ago

https://github.com/taishan1994/pytorch_bert_bilstm_crf_ner/tree/16ee44df462dfa9fde13597d724ea9f6477ef935/convert_onnx