Can not use the convert_graph_to_onnx.py to convert the pytorch model to onnx model
Author: KellyZhang2020
Pull request: no

When I convert the pytorch model to onnx as follow:

```
import os
import torch
from pytorch_pretrained_bert import BertModel 

model = BertModel.from_pretrained('bert-base-uncased')
base_path = os.path.dirname(__file__)
pt_path = os.path.join(base_path, 'bert.pt')
torch.save(model, pt_path)
```

Then I use the convert_graph_to_onnx.py to convert the pytorch model to onnx model, as follow:
`python src/transformers/convert_graph_to_onnx.py --framework pt --model bert.pt bert.onnx`

**Error:**
`Error while converting the model: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte`

I don't know what caused this


- `transformers` version:3.0.1
- Platform: pycharm
- Python version: 3.7.2
- PyTorch version (GPU?): 1.6.0 
- Tensorflow version (GPU?): 2.0.0
- Using GPU in script?: NO
- Using distributed or parallel set-up in script?: NO

Thank you for the help :)

Comments:
same issues here. please help!

same issue

Same issue with Camembert torch model

python transformers/convert_graph_to_onnx.py --model camembert-base --framework pt /tmp/camembert-base.onnx

====== Converting model to ONNX ======
ONNX opset version set to: 11
Loading pipeline (model: camembert-base, tokenizer: camembert-base)
Using framework PyTorch: 1.4.0
Found input input_ids with shape: {0: 'batch', 1: 'sequence'}
Found input attention_mask with shape: {0: 'batch', 1: 'sequence'}
Found output output_0 with shape: {0: 'batch', 1: 'sequence'}
Found output output_1 with shape: {0: 'batch'}
Ensuring inputs are in correct order
token_type_ids is not present in the generated input list.
Generated inputs order: ['input_ids', 'attention_mask']
Error while converting the model: export() got an unexpected keyword argument 'use_external_data_format'


My issue was due to an older version of pytorch v1.4 where export function arguments are not the same as in version v1.6

Any Solutions for this issue ?

Hello @junkgear, we're doing a rework of the ONNX implementation, you can take a look at the proposal here: https://github.com/huggingface/transformers/pull/11786

Let me know if that works for you!

I dumped the vocab and config file in model folder and was able to convert
Gave model folder as input instead of bin file to convert_graph_to_onnx.py script

```
from transformers import (WEIGHTS_NAME, AdamW, get_linear_schedule_with_warmup,
                          RobertaConfig, RobertaModel, RobertaTokenizer)

MODEL_CLASSES = {'roberta': (RobertaConfig, RobertaModel, RobertaTokenizer)}

config_class, model_class, tokenizer_class = MODEL_CLASSES['roberta']

config = config_class.from_pretrained('microsoft/codebert-base')

tokenizer = tokenizer_class.from_pretrained('microsoft/codebert-base')

#convert config file to json and save in model folder
config.to_json_file('model/config.json')

#save the vocabulary
tokenizer.save_vocabulary('model/')
```

> I dumped the vocab and config file in model folder and was able to convert
> Gave model folder as input instead of bin file to convert_graph_to_onnx.py script
> 
> ```
> from transformers import (WEIGHTS_NAME, AdamW, get_linear_schedule_with_warmup,
>                           RobertaConfig, RobertaModel, RobertaTokenizer)
> 
> MODEL_CLASSES = {'roberta': (RobertaConfig, RobertaModel, RobertaTokenizer)}
> 
> config_class, model_class, tokenizer_class = MODEL_CLASSES['roberta']
> 
> config = config_class.from_pretrained('microsoft/codebert-base')
> 
> tokenizer = tokenizer_class.from_pretrained('microsoft/codebert-base')
> 
> #convert config file to json and save in model folder
> config.to_json_file('model/config.json')
> 
> #save the vocabulary
> tokenizer.save_vocabulary('model/')
> ```
This reply saved me an hour or two. If you look into convert_graph_to_onnx.py, --model parameter can only be HuggingFace's model id or a path. So anything like my_model.ckpt won't work. It should be a path containing vocab.txt, config.json, and pytorch_model.bin. Also the tokenizer should be either a tokenizer/model id or a folder containing the tokenizer files. Thanks a lot @junkgear !