How to convert Speech Encoder Decoder to onnx

Hi all,

I tried to convert “nguyenvulebinh/wav2vec2-bartpho” to onnx by ontimum but it not worked and got bellow error.

Could we do this convert or not ? If yes, please help to instruction how to convert a model_type: “speech-encoder-decoder” to onnx?

The config.json of this model: [config.json · nguyenvulebinh/wav2vec2-bartpho at main]

(optimum-intel) []$ 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 Export a model to ONNX with optimum.exporters.onnx  for an example on how to export custom models. Please open an issue at Issues · huggingface/optimum  if you would like the model type speech-encoder-decoder to be supported natively in the ONNX export.
(optimum-intel) []$

Hi @nhha1602! The architecture you tried to export is not supported by Optimum. Here is how to export it as a custom model: Export a model to ONNX with optimum.exporters.onnx