The Wayback Machine - https://web.archive.org/web/20220512235135/https://github.com/huggingface/transformers/issues/16308
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONNXConfig: Add a configuration for all available models #16308

Open
ChainYo opened this issue Mar 21, 2022 · 26 comments · May be fixed by #17027
Open

ONNXConfig: Add a configuration for all available models #16308

ChainYo opened this issue Mar 21, 2022 · 26 comments · May be fixed by #17027

Comments

@ChainYo
Copy link
Contributor

@ChainYo ChainYo commented Mar 21, 2022

This issue is about the working group specially created for this task. If you are interested in helping out, take a look at this organization, or add me on Discord: ChainYo#3610

We are looking for contributing to HuggingFace's ONNX implementation for all available models on the HF's hub. There is already a lot of architectures implemented for converting PyTorch models to ONNX, but we need more! We need them all!

Feel free to join us in this adventure! Join the org by clicking here

Here is a non-exhaustive list of models that all models available:

- ✅ Albert
- ✅ BART
- ✅ BeiT
- ✅ BERT
- ✅ BigBird
- ✅ BigBirdPegasus
- Blenderbot
- BlenderbotSmall
- ✅ CamemBERT
- Canine
- CLIP
- CTRL
- ✅ ConvBert
- ConvNext
- ✅ Data2Vec
- Deberta
- DebertaV2
- ✅ DeiT
- DecisionTransformer
- DETR
- ✅ Distilbert
- DPR
- ✅ Electra
- FNet
- FSMT
- ✅ Flaubert
- Funnel
- GLPN
- ✅ GPT2
- ✅ GPTJ
- ✅ GPT-Neo
- Hubert
- ✅ I-Bert
- ImageGPT
- LED
- ✅ LayoutLM
- 🛠️ LayoutLMv2
- LayoutXLM
- Longformer
- 🛠️ Luke
- Lxmert
- ✅ M2M100
- MaskFormer
- ✅ mBart
- MPNet
- MT5
- ✅ Marian
- MegatronBert
- ✅ MobileBert
- Nystromformer
- OpenAIGPT
- ✅ PLBart
- Pegasus
- 🛠️ Perceiver
- PoolFormer
- ProphetNet
- QDQBERT
- rag
- Realm
- 🛠️ Reformer
- RemBert
- 🛠️ ResNet
- RetriBert
- ✅ RoFormer
- ✅ RoBERTa
- SEW
- SEW-D
- Segformer
- Splinter
- SqueezeBERT
- Swin
- ✅ T5
- TAPAS
- TransfoXL
- TrOCR
- UniSpeech
- UniSpeechSat
- VAN
- ✅ ViT
- Vilt
- VisualBERT
- Wav2Vec2
- WavLM
- XGLM
- XLM
- XLMProphetNet
- ✅ XLM-RoBERTa
- ✅ XLM-Roberta-XL
- 🛠️ XLNet
- Yoso

If there is a next to a model, it means that the model is already supported by ONNX.
🛠️ next to a model means that the PR is in progress and finally if there is nothing next to a model, it means that the model is not yet supported by ONNX and thus we need to add support for it.

If you need some help about implementing an unsupported model, here is a guide from HuggingFace's documentation.

If you want an example of implementation, I did one for CamemBERT some months ago.

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Mar 21, 2022

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Mar 21, 2022

@vumichien
Copy link
Contributor

@vumichien vumichien commented Mar 22, 2022

Let me try with BigBird

@vumichien
Copy link
Contributor

@vumichien vumichien commented Mar 26, 2022

@LysandreJik
Copy link
Member

@LysandreJik LysandreJik commented Mar 28, 2022

Love the initiative here, thanks for opening an issue! Added the Good First Issue label so that it's more visible :)

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Mar 29, 2022

Love the initiative here, thanks for opening an issue! Added the Good First Issue label so that it's more visible :)

Thanks for the label, I don't know if it's easy for beginning but it's cool if more people see this and can contribute!

@aakashb95
Copy link

@aakashb95 aakashb95 commented Mar 31, 2022

I would like to try with Luke. However, Luke doesn't support any features apart from default AutoModel. It's main feature is LukeForEntityPairClassification for relation extraction. Should I convert luke-base to Onnx or LukeForEntityPairClassification which has a classifier head?

@xiadingZ
Copy link

@xiadingZ xiadingZ commented Mar 31, 2022

Data2vecAudio doesn't have ONNXConfig yet. I write its ONNXConfig according to Data2VecTextOnnxConfig but it throws error. Can anyone help me?

from typing import Mapping, OrderedDict
from transformers.onnx import OnnxConfig

from transformers import AutoConfig
from pathlib import Path
from transformers.onnx import export
from transformers import AutoTokenizer, AutoModel

class Data2VecAudioOnnxConfig(OnnxConfig):
    @property
    def inputs(self):
        return OrderedDict(
            [
                ("input_values", {0: "batch", 1: "sequence"}),
                ("attention_mask", {0: "batch", 1: "sequence"}),
            ]
        )
    
config = AutoConfig.from_pretrained("facebook/data2vec-audio-base-960h")
onnx_config = Data2VecAudioOnnxConfig(config)



onnx_path = Path("facebook/data2vec-audio-base-960h")
model_ckpt = "facebook/data2vec-audio-base-960h"
base_model = AutoModel.from_pretrained(model_ckpt)
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)

onnx_inputs, onnx_outputs = export(tokenizer, base_model, onnx_config, onnx_config.default_onnx_opset, onnx_path)

errors

ValueError                                Traceback (most recent call last)
/var/folders/2t/0w65vdjs2m32w5mmzzgtqrhw0000gn/T/ipykernel_59977/667985886.py in <module>
     27 tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
     28 
---> 29 onnx_inputs, onnx_outputs = export(tokenizer, base_model, onnx_config, onnx_config.default_onnx_opset, onnx_path)

~/miniconda3/lib/python3.9/site-packages/transformers/onnx/convert.py in export(tokenizer, model, config, opset, output)
    255 
    256     if is_torch_available() and issubclass(type(model), PreTrainedModel):
--> 257         return export_pytorch(tokenizer, model, config, opset, output)
    258     elif is_tf_available() and issubclass(type(model), TFPreTrainedModel):
    259         return export_tensorflow(tokenizer, model, config, opset, output)

~/miniconda3/lib/python3.9/site-packages/transformers/onnx/convert.py in export_pytorch(tokenizer, model, config, opset, output)
    112 
    113             if not inputs_match:
--> 114                 raise ValueError("Model and config inputs doesn't match")
    115 
    116             config.patch_ops()

ValueError: Model and config inputs doesn't match
@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 1, 2022

I would like to try with Luke. However, Luke doesn't support any features apart from default AutoModel. It's main feature is LukeForEntityPairClassification for relation extraction. Should I convert luke-base to Onnx or LukeForEntityPairClassification which has a classifier head?

When you implement the ONNX Config for a model it's working for all kind of task, because the base model and the ones pre-packaged for fine-tuning have the same inputs.

So you can base your implementation on the base model and other tasks will work too.

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 2, 2022

@jorabara
Copy link

@jorabara jorabara commented Apr 11, 2022

Still learning

@pikaqqqqqq
Copy link

@pikaqqqqqq pikaqqqqqq commented Apr 14, 2022

Issue description

Hello, thank you for supporting GPTJ with ONNX. But when I exported an ONNX checkpoint using transformers-4.18.0, I got the issue like below.

(venv) root@V100:~# python -m transformers.onnx --model=gpt-j-6B/ onnx/
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/data/lvenv/lib/python3.8/site-packages/transformers/onnx/__main__.py", line 99, in <module>
    main()
  File "/data/venv/lib/python3.8/site-packages/transformers/onnx/__main__.py", line 62, in main
    raise ValueError(f"Unsupported model type: {config.model_type}")
ValueError: Unsupported model type: gptj

I found GPTJ with ONNX seems supported when I checked your document transformers-4.18.0 [https://huggingface.co/docs/transformers/serialization#exporting-a-model-for-an-unsupported-architecture] and code [src/transformers/onnx/features.py etc.]. But I still got this issue. And then, I checked the parameter of config.model_type in File "/data/venv/lib/python3.8/site-packages/transformers/onnx/main.py", which is related to two parameters [from ..models.auto.feature_extraction_auto import FEATURE_EXTRACTOR_MAPPING_NAMES, from ..models.auto.tokenization_auto import TOKENIZER_MAPPING_NAMES]. I did not find GPTJ's config in these configs. It seems not sensible.

Environment info

  • Platform: Ubuntu 20.04.2
  • python: 3.8.10
  • PyTorch: 1.10.0+cu113
  • transformers: 4.18.0
  • GPU: V100
@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 14, 2022

Hello, thank you for supporting GPTJ with ONNX. But when I exported an ONNX checkpoint using transformers-4.18.0, I got the issue like below.

Hello @pikaqqqqqq, thanks for reporting the problem. I opened a PR with a quick fix to avoid this problem, check #16780

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 20, 2022

@skrsna
Copy link
Contributor

@skrsna skrsna commented Apr 20, 2022

Hello 👋🏽, I added RoFormer onnx config here #16861, I'm not 100% sure who to ask for review so I'm posting this here. Thanks 🙏🏽

@Tanmay06
Copy link

@Tanmay06 Tanmay06 commented Apr 21, 2022

Hi! I would like try building the ONNX config for Reformer.

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 21, 2022

Hi! I would like try building the ONNX config for Reformer.

Hi @Tanmay06 that would be awesome. Don't hesitate to open a PR with your work when you feel it's quite good. You can ping me anytime if you need help!

@rushic24 rushic24 mentioned this issue Apr 22, 2022
5 tasks
@chamidullinr
Copy link

@chamidullinr chamidullinr commented Apr 26, 2022

Hello! I would like to work on ONNX config for ResNet.

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 26, 2022

Hello! I would like to work on ONNX config for ResNet.

Nice, don't hesitate to ping me if help is needed 🤗

@nandwalritik
Copy link
Contributor

@nandwalritik nandwalritik commented Apr 28, 2022

Hi! I would like to work on ONNX config for BigBirdPegasus.

@ChainYo
Copy link
Contributor Author

@ChainYo ChainYo commented Apr 28, 2022

Hi! I would like to work on ONNX config for BigBirdPegasus.

Hi, nice! If you need help you can tag me.

@sijunhe sijunhe linked a pull request Apr 30, 2022 that will close this issue
5 tasks
@sijunhe
Copy link

@sijunhe sijunhe commented Apr 30, 2022

#17027 Here is one for XLNet!

@manandey
Copy link
Contributor

@manandey manandey commented May 1, 2022

#17029 PR for MobileBert.

@nandwalritik
Copy link
Contributor

@nandwalritik nandwalritik commented May 1, 2022

#17030 Here is the PR for XLM

@nandwalritik
Copy link
Contributor

@nandwalritik nandwalritik commented May 4, 2022

#17078 PR for BigBirdPegasus

@deutschmn
Copy link
Contributor

@deutschmn deutschmn commented May 12, 2022

#17213 for Perceiver
#17176 for Longformer (work in progress 🚧 help appreciated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment