Converting facebook-encodec to onnx fails with KeyError: 'encodec'
Author: kalradivyanshu
Pull request: no
Labels: name: Good Second Issue

name: Feature request

### System Info


- `transformers` version: 4.36.0.dev0
- Platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.29
- Python version: 3.8.10
- Huggingface_hub version: 0.19.4
- Safetensors version: 0.4.0
- Accelerate version: 0.24.1
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.0+cu117 (True)
- Tensorflow version (GPU?): 2.12.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

### Who can help?

@sanchit-gandhi 

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

1. Download all files in https://huggingface.co/facebook/encodec_24khz/tree/main to a folder `encodec24khz`
2. run `python -m transformers.onnx --model=encodec24khz onnx/`

### Expected behavior

The encodec model should be exported to ONNX as described here: https://huggingface.co/docs/transformers/v4.17.0/en/serialization#exporting-a-model-to-onnx.

But it fails and gives the following error:
```
❯ python -m transformers.onnx --model=encodec24khz onnx/
Local PyTorch model found.
Framework not requested. Using torch to export to ONNX.
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/user/.local/lib/python3.9/site-packages/transformers/onnx/__main__.py", line 240, in <module>
    main()
  File "/home/user/.local/lib/python3.9/site-packages/transformers/onnx/__main__.py", line 232, in main
    export_with_transformers(args)
  File "/home/user/.local/lib/python3.9/site-packages/transformers/onnx/__main__.py", line 75, in export_with_transformers
    model = FeaturesManager.get_model_from_feature(
  File "/home/user/.local/lib/python3.9/site-packages/transformers/onnx/features.py", line 701, in get_model_from_feature
    model = model_class.from_pretrained(model, cache_dir=cache_dir)
  File "/home/user/.local/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 441, in from_pretrained
    config, kwargs = AutoConfig.from_pretrained(
  File "/home/user/.local/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 937, in from_pretrained
    config_class = CONFIG_MAPPING[config_dict["model_type"]]
  File "/home/user/.local/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 643, in __getitem__
    raise KeyError(key)
KeyError: 'encodec'
```

Comments:
Hey! Thanks for this, I'll add this as a feature request as the error I am getting is the following:
```python 
Framework not requested. Using torch to export to ONNX.
/Users/arthurzucker/.pyenv/versions/py310/lib/python3.10/site-packages/torch/nn/utils/weight_norm.py:30: UserWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.
  warnings.warn("torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.")
Traceback (most recent call last):
  File "/Users/arthurzucker/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/arthurzucker/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/arthurzucker/Work/transformers/src/transformers/onnx/__main__.py", line 242, in <module>
    main()
  File "/Users/arthurzucker/Work/transformers/src/transformers/onnx/__main__.py", line 234, in main
    export_with_transformers(args)
  File "/Users/arthurzucker/Work/transformers/src/transformers/onnx/__main__.py", line 79, in export_with_transformers
    model_kind, model_onnx_config = FeaturesManager.check_supported_model_or_raise(model, feature=args.feature)
  File "/Users/arthurzucker/Work/transformers/src/transformers/onnx/features.py", line 728, in check_supported_model_or_raise
    model_features = FeaturesManager.get_supported_features_for_model_type(model_type, model_name=model_name)
  File "/Users/arthurzucker/Work/transformers/src/transformers/onnx/features.py", line 575, in get_supported_features_for_model_type
    raise KeyError(
KeyError: "encodec is not supported yet. Only ['albert', 'bart', 'beit', 'bert', 'big-bird', 'bigbird-pegasus', 'blenderbot', 'blenderbot-small', 'bloom', 'camembert', 'clip', 'codegen', 'convbert', 'convnext', 'data2vec-text', 'data2vec-vision', 'deberta', 'deberta-v2', 'deit', 'detr', 'distilbert', 'electra', 'flaubert', 'gpt2', 'gptj', 'gpt-neo', 'groupvit', 'ibert', 'imagegpt', 'layoutlm', 'layoutlmv3', 'levit', 'longt5', 'longformer', 'marian', 'mbart', 'mobilebert', 'mobilenet-v1', 'mobilenet-v2', 'mobilevit', 'mt5', 'm2m-100', 'owlvit', 'perceiver', 'poolformer', 'rembert', 'resnet', 'roberta', 'roformer', 'segformer', 'squeezebert', 'swin', 't5', 'vision-encoder-decoder', 'vit', 'whisper', 'xlm', 'xlm-roberta', 'yolos'] are supported. If you want to support encodec please propose a PR or open up an issue."
```
which is expected. 


I can work on this @ArthurZucker, can you guide me on how i can get started?

Hey! 🤗 I think @fxmarty will be of better help than me.

@kalradivyanshu closing as duplicate of https://github.com/huggingface/optimum/issues/1545

transformers.onnx is deprecated in favor of optimum.exporters.onnx, for reference: https://huggingface.co/docs/transformers/serialization

There is an open PR for the ONNX support for encodec: https://github.com/huggingface/optimum/pull/1620