optimum icon indicating copy to clipboard operation
optimum copied to clipboard

Add support for Speech Encoder Decoder models in `optimum.exporters.onnx`

Open michaelbenayoun opened this issue 3 years ago • 4 comments

Feature request

Add support for Speech Encoder Decoder Models

Your contribution

Me or other members can implement it (cc @mht-sharma @fxmarty )

michaelbenayoun avatar Dec 20 '22 16:12 michaelbenayoun

Adding a dependency on this issue: 367. I am currently working on creating a generic wrapper for such models, hence adding this to avoid rework.

mht-sharma avatar Dec 20 '22 17:12 mht-sharma

Hi, I tried to convert "nguyenvulebinh/wav2vec2-bartpho" to onnx but got bellow error. Could you, please help to check it ? if this relates to this issue ?

(optimum-intel) [root]$ optimum-cli export onnx --model "nguyenvulebinh/wav2vec2-bartpho" wav2vec2-bartpho-onnx
Framework not specified. Using pt to export to ONNX.
Config of the decoder: <class 'transformers.models.mbart.modeling_mbart.MBartForCausalLM'> is overwritten by shared decoder config: MBartConfig {
  "_name_or_path": "vinai/bartpho-syllable-base",
  "activation_dropout": 0.0,
  "activation_function": "gelu",
  "add_cross_attention": true,
  "architectures": [
    "MBartModel"
  ],
  "attention_dropout": 0.0,
  "bos_token_id": 0,
  "classifier_dropout": 0.0,
  "d_model": 768,
  "decoder_attention_heads": 12,
  "decoder_ffn_dim": 3072,
  "decoder_layerdrop": 0.0,
  "decoder_layers": 6,
  "decoder_start_token_id": 2,
  "dropout": 0.1,
  "encoder_attention_heads": 12,
  "encoder_ffn_dim": 3072,
  "encoder_layerdrop": 0.0,
  "encoder_layers": 6,
  "eos_token_id": 2,
  "forced_eos_token_id": 2,
  "gradient_checkpointing": false,
  "init_std": 0.02,
  "is_decoder": true,
  "is_encoder_decoder": true,
  "max_position_embeddings": 1024,
  "model_type": "mbart",
  "num_hidden_layers": 6,
  "pad_token_id": 1,
  "scale_embedding": false,
  "tokenizer_class": "BartphoTokenizer",
  "torch_dtype": "float32",
  "transformers_version": "4.35.0",
  "use_cache": true,
  "vocab_size": 41031
}

Some weights of the model checkpoint at nguyenvulebinh/wav2vec2-bartpho were not used when initializing SpeechEncoderDecoderModel: ['encoder.encoder.pos_conv_embed.conv.weight_v', 'encoder.encoder.pos_conv_embed.conv.weight_g']
- This IS expected if you are initializing SpeechEncoderDecoderModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing SpeechEncoderDecoderModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of SpeechEncoderDecoderModel were not initialized from the model checkpoint at nguyenvulebinh/wav2vec2-bartpho and are newly initialized: ['encoder.encoder.pos_conv_embed.conv.parametrizations.weight.original1', 'encoder.encoder.pos_conv_embed.conv.parametrizations.weight.original0']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Traceback (most recent call last):
  File "/home/coreai/anaconda3/envs/optimum-intel/bin/optimum-cli", line 8, in <module>
    sys.exit(main())
  File "/home/coreai/anaconda3/envs/optimum-intel/lib/python3.9/site-packages/optimum/commands/optimum_cli.py", line 163, in main
    service.run()
  File "/home/coreai/anaconda3/envs/optimum-intel/lib/python3.9/site-packages/optimum/commands/export/onnx.py", line 246, in run
    main_export(
  File "/home/coreai/anaconda3/envs/optimum-intel/lib/python3.9/site-packages/optimum/exporters/onnx/__main__.py", line 408, in main_export
    raise ValueError(
ValueError: Trying to export a speech-encoder-decoder model, that is a custom or unsupported architecture for the task automatic-speech-recognition, but no custom onnx configuration was passed as `custom_onnx_configs`. Please refer to https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model#custom-export-of-transformers-models for an example on how to export custom models. Please open an issue at https://github.com/huggingface/optimum/issues if you would like the model type speech-encoder-decoder to be supported natively in the ONNX export.
(optimum-intel) [root]$

nhha1602 avatar Nov 13 '23 10:11 nhha1602

Hi @mht-sharma

Do we support convert SpeechEncoderDecoderModel to onnx ?

Thanks and regards.

nhha1602 avatar Nov 15 '23 06:11 nhha1602

Hi @nhha1602 currently this model is not supporte, would create a PR for this soon

mht-sharma avatar Nov 15 '23 10:11 mht-sharma