# Export pretrained MT5 model to ONNX

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%3E%5C
**Category:** 🤗Optimum\
**Created:** [May 2, 2024, 11:36am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825 "2024-05-02T11:36:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesXanda](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JamesXanda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJamesXanda)%5C
**Post date:** [May 2, 2024, 11:36am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F1 "2024-05-02T11:36:30Z")

</div>

Hi, I saw that someone was able to convert the speecht5-tts model to onnx format.

> **[Xenova/speecht5\_tts · Hugging Face](https://huggingface.co/Xenova/speecht5_tts)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

In the discussion they claimed they used optimum but the unstable version at the time. However, they didn’t elaborate more on that ad when I looked though the code I couldn’t find a pipeline that would support it anywhere.

Does anyone know how this could be done?

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [May 2, 2024, 2:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F2 "2024-05-02T14:11:42Z")

</div>

Hi @JamesXanda, you can export it with the CLI as follows:

```auto
optimum-cli export onnx --model microsoft/speecht5_tts test_onnx --model-kwargs '{"vocoder": "microsoft/speecht5_hifigan"}'

```

Let me know if that works on your side.  
Note that you can use the latest stable release of Optimum for exporting this model, no need to install it from source.

---

<div class="post-metadata">

**Author:** ![JamesXanda](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JamesXanda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJamesXanda)%5C
**Post date:** [May 2, 2024, 4:23pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F3 "2024-05-02T16:23:45Z")

</div>

Ah yes, this worked. Are there any ORT pipelines for running it in python?

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [May 2, 2024, 5:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F4 "2024-05-02T17:12:29Z")

</div>

For doing text to speech no. However, it should probably be similar to the speech-to-text pipeline: [optimum/optimum/onnxruntime/modeling\_seq2seq.py at e3fd2776a318a3a7b9d33315cc42c04c181f6d2f · huggingface/optimum · GitHub](https://github.com/huggingface/optimum/blob/e3fd2776a318a3a7b9d33315cc42c04c181f6d2f/optimum/onnxruntime/modeling_seq2seq.py#L1262)

---

<div class="post-metadata">

**Author:** ![JamesXanda](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JamesXanda](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJamesXanda)%5C
**Post date:** [May 2, 2024, 5:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F5 "2024-05-02T17:31:55Z")

</div>

Interesting, I would have though it would be pretty similar to the Transformer.js text-to-speech pipeline since that loads from the optimum exported ONNX weights.

Anyway, thank you for your help.

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [May 3, 2024, 9:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-pretrained-mt5-model-to-onnx%2F84825%2F6 "2024-05-03T09:05:49Z")

</div>

Here is an example snippet to make it work in Python: [SpeechT5 ONNX support by fxmarty · Pull Request #1404 · huggingface/optimum · GitHub](https://github.com/huggingface/optimum/pull/1404#issuecomment-1735963247)  
It can probably be improved though.
