microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.66k stars 2.93k forks source link

UnicodeDecodeError when converting dialogpt to onnx format #9544

Closed qiuxia-alone closed 3 years ago

qiuxia-alone commented 3 years ago

Describe the bug i refer to GPT-2 Model conversion , and try to convert dialogpt to onnx format with following code: python -m onnxruntime.transformers.convert_to_onnx -m DialoGPT-medium/pytorch_model.bin --model_class GPT2LMHeadModel --output dialogpt2.onnx -p fp32 --optimize_onnx but meet error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte how to fix this, thank you in advance.

Urgency none

System information

zhijxu-MS commented 3 years ago

could you try newer version of onnxruntime? also, i think -m only need to path to config.json, so you need "-m DialoGPT-medium/" instead of "-m DialoGPT-medium/pytorch_model.bin". you should download all file in https://huggingface.co/microsoft/DialoGPT-medium/tree/main to DialoGPT-medium first.

qiuxia-alone commented 3 years ago

could you try newer version of onnxruntime? also, i think -m only need to path to config.json, so you need "-m DialoGPT-medium/" instead of "-m DialoGPT-medium/pytorch_model.bin".

that's great helpful, and i convert successfully as you say. But meet another problem when inferencing using dialogpt2.onnx:

import onnxruntime as ort
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("./DialoGPT-medium/")
ort_session = ort.InferenceSession("onnx_19/dialogpt2.onnx")
inputs = tokenizer("hello", return_tensors="np")
outputs = ort_session.run(None,inputs)

the error is: ValueError: Model requires 27 inputs. Input Feed contains 2 why it need 27 inputs, which really make me confused.

yuslepukhin commented 3 years ago

You can either interrogate the loaded model metadata and see the inputs/outputs that the model expects and its types, shapes. Or you use Netron app to visualize it.

qiuxia-alone commented 3 years ago

You can either interrogate the loaded model metadata and see the inputs/outputs that the model expects and its types, shapes. Or you use Netron app to visualize it.

hi, thank you a lot.

qiuxia-alone commented 3 years ago

hi, the onnxruntime.transformers.convert_to_onnx script can get the inputs_ids, position_ids, attention_mask as onnx inputs, and can it get the token_type_ids?