Repository: huggingface/optimum

Issue:
Add marian model type support for ORTOptimizer
### Feature request

The recent Optimum library enable to export marian model type to ONNX format. However, the optimization via ORTOptimizer seems not to support this model type.

Please find below, the code used:
```
from optimum.onnxruntime import ORTModelForSeq2SeqLM, ORTOptimizer
from optimum.onnxruntime.configuration import OptimizationConfig

model_id="Helsinki-NLP/opus-mt-fr-en"

# load vanilla transformers and convert to onnx
model = ORTModelForSeq2SeqLM.from_pretrained(model_id, from_transformers=True)

# Create ORTOptimizer
optimizer = ORTOptimizer.from_pretrained(model)

# Define the optimization strategy by creating the appropriate configuration
optimization_config = OptimizationConfig(optimization_level=1,
                                        optimize_for_gpu=True,
                                        fp16=True
                                        )

# Optimize the model
optimizer.optimize(save_dir=onnx_path, optimization_config=optimization_config)
```
And the error code on feedback:
```
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-8-0c22ffd4b88a> in <module>
     12 
     13 # Optimize the model
---> 14 optimizer.optimize(save_dir=onnx_path, optimization_config=optimization_config)

~/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/optimum/onnxruntime/optimization.py in optimize(self, optimization_config, save_dir, file_suffix, use_external_data_format)
    113         save_dir.mkdir(parents=True, exist_ok=True)
    114         model_type = self.config.model_type
--> 115         ORTConfigManager.check_supported_model_or_raise(model_type)
    116 
    117         # Save the model configuration

~/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/optimum/onnxruntime/utils.py in check_supported_model_or_raise(cls, model_type)
    110     def check_supported_model_or_raise(cls, model_type: str) -> bool:
    111         if model_type not in cls._conf:
--> 112             raise KeyError(
    113                 f"{model_type} model type is not supported yet. Only {list(cls._conf.keys())} are supported. "
    114                 f"If you want to support {model_type} please propose a PR or open up an issue."

KeyError: "marian model type is not supported yet. Only ['bert', 'albert', 'big_bird', 'camembert', 'codegen', 'distilbert', 'deberta', 'deberta-v2', 'electra', 'roberta', 'bart', 'gpt2', 'gpt_neo', 'xlm-roberta'] are supported. If you want to support marian please propose a PR or open up an issue."
```

### Motivation

It would be greatly beneficial to be able to optimize the onnx models regarding the low inference speed of this kind of model.

### Your contribution

I could be a test user if the library is updated with this new feature.


Discussion:

Resolving patch:
diff --git a/optimum/onnxruntime/utils.py b/optimum/onnxruntime/utils.py
--- a/optimum/onnxruntime/utils.py
+++ b/optimum/onnxruntime/utils.py
@@ -55,20 +55,22 @@ class ORTConfigManager:
             and the hidden size model config attribute names as well as the corresponding ONNX Runtime model type.
     """
 
+    # Contribution note: Please add new models in alphabetical order
     _conf = {
-        "bert": ("num_attention_heads", "hidden_size", "bert"),
         "albert": ("num_attention_heads", "hidden_size", "bert"),
+        "bart": ("encoder_attention_heads", "d_model", "bart"),
+        "bert": ("num_attention_heads", "hidden_size", "bert"),
         "big_bird": ("num_attention_heads", "hidden_size", "bert"),
         "camembert": ("num_attention_heads", "hidden_size", "bert"),
         "codegen": ("n_head", "n_embd", "gpt2"),
-        "distilbert": ("n_heads", "dim", "bert"),
         "deberta": ("num_attention_heads", "hidden_size", "bert"),
         "deberta-v2": ("num_attention_heads", "hidden_size", "bert"),
+        "distilbert": ("n_heads", "dim", "bert"),
         "electra": ("num_attention_heads", "hidden_size", "bert"),
-        "roberta": ("num_attention_heads", "hidden_size", "bert"),
-        "bart": ("encoder_attention_heads", "d_model", "bart"),
         "gpt2": ("n_head", "n_embd", "gpt2"),
         "gpt_neo": ("num_heads", "hidden_size", "gpt2"),
+        "marian": ("encoder_attention_heads", "d_model", "bart"),
+        "roberta": ("num_attention_heads", "hidden_size", "bert"),
         "xlm-roberta": ("num_attention_heads", "hidden_size", "bert"),
     }
 


Test patch:
diff --git a/tests/onnxruntime/test_optimization.py b/tests/onnxruntime/test_optimization.py
--- a/tests/onnxruntime/test_optimization.py
+++ b/tests/onnxruntime/test_optimization.py
@@ -33,15 +33,16 @@
 
 class ORTOptimizerTest(unittest.TestCase):
 
+    # Contribution note: Please add test models in alphabetical order. Find test models here: https://huggingface.co/hf-internal-testing.
     SUPPORTED_ARCHITECTURES_WITH_MODEL_ID = (
         (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-bert"),
-        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-distilbert"),
         (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-bart"),
+        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-big_bird"),
+        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-distilbert"),
+        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-electra"),
         (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-gpt2"),
         (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-roberta"),
-        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-electra"),
         (ORTModelForSequenceClassification, "hf-internal-testing/tiny-xlm-roberta"),
-        (ORTModelForSequenceClassification, "hf-internal-testing/tiny-random-big_bird"),
     )
 
     @parameterized.expand(SUPPORTED_ARCHITECTURES_WITH_MODEL_ID)
@@ -70,9 +71,12 @@ def test_compare_original_model_with_optimized_model(self, model_cls, model_name
             self.assertTrue(torch.allclose(model_outputs.logits, optimized_model_outputs.logits, atol=1e-4))
             gc.collect()
 
+    # Contribution note: Please add test models in alphabetical order. Find test models here: https://huggingface.co/hf-internal-testing.
     SUPPORTED_SEQ2SEQ_ARCHITECTURES_WITH_MODEL_ID = (
         (ORTModelForSeq2SeqLM, "hf-internal-testing/tiny-random-bart", False),
         (ORTModelForSeq2SeqLM, "hf-internal-testing/tiny-random-bart", True),
+        (ORTModelForSeq2SeqLM, "hf-internal-testing/tiny-random-marian", False),
+        (ORTModelForSeq2SeqLM, "hf-internal-testing/tiny-random-marian", True),
     )
 
     @parameterized.expand(SUPPORTED_SEQ2SEQ_ARCHITECTURES_WITH_MODEL_ID)