# Can i export a VisionEncoderDecoder checkpoint to onnx

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%3E%5C
**Category:** Beginners\
**Created:** [December 16, 2021, 6:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885 "2021-12-16T06:40:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kforcode](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Kforcode](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKforcode)%5C
**Post date:** [December 16, 2021, 6:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F1 "2021-12-16T06:40:35Z")

</div>

Can I export any hugging face checkpoint to onnx? If not, how do I go about it  
@nielsr I want to export trocr checkpoint to onnx, is it possible.  
I tried doing the same with a fine-tuned checkpoint of mine, it gives a KEY ERROR

```auto
KeyError: <class 'transformers.models.vision_encoder_decoder.configuration_vision_encoder_decoder.VisionEncoderDecoderConfig'>

```

When I do the same using “microsoft/trocr-large-printed” checkpoint, I get an exception saying

 ![onnx_export_fail](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/dd9d576d3b5fe93d8173a5c8dc481cba712274a1.png)

Do you know what might I be missing? Is it possible, if not , how do I go about it.

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [December 16, 2021, 9:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F2 "2021-12-16T09:50:42Z")

</div>

Pinging @lewtun here, to let him know people are also interested in exporting EncoderDecoder model classes to ONNX.

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [December 17, 2021, 12:02pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F4 "2021-12-17T12:02:24Z")

</div>

You can track the issue [here](https://github.com/huggingface/transformers/issues/14812) @Kforcode

---

<div class="post-metadata">

**Author:** ![frytoli](https://avatars.discourse-cdn.com/v4/letter/f/c5a1d2/32.png) [@frytoli](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffrytoli)%5C
**Post date:** [May 25, 2022, 4:53pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F5 "2022-05-25T16:53:29Z")

</div>

Hey there! Any updates on this?

I’ve read through [this documentation](https://huggingface.co/docs/transformers/serialization#exporting-a-model-for-an-unsupported-architecture) about implementing a custom ONNX configuration for unsupported architectures. The walk-through described here doesn’t look too difficult. But, I decided that before I attempted this I’d ask: is this possible with TrOCR in its current state, or is this irrelevant until the code is refactored (which I know you smart people are working on currently, and I thank you for it)?

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [May 27, 2022, 3:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F6 "2022-05-27T15:11:11Z")

</div>

We’re currently refactoring the internals of the ONNX exporter to handle multimodal models better [here](https://github.com/huggingface/transformers/pull/17213/files). Once that’s done, it should be relatively straightforward to export TrOCR and I’d be happy to guide you on that 🙂

---

<div class="post-metadata">

**Author:** ![frytoli](https://avatars.discourse-cdn.com/v4/letter/f/c5a1d2/32.png) [@frytoli](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffrytoli)%5C
**Post date:** [May 27, 2022, 5:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F7 "2022-05-27T17:41:52Z")

</div>

Oh wonderful! Thanks!

---

<div class="post-metadata">

**Author:** ![tanmayjain](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tanmayjain](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftanmayjain)%5C
**Post date:** [June 14, 2022, 7:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F8 "2022-06-14T19:31:41Z")

</div>

Hi there,  
I am unable to export a fine-tuned TrOCR checkpoint as per the [documentation](https://huggingface.co/docs/transformers/serialization#exporting-a-model-for-an-unsupported-architecture) for custom architectures. Is there a way to go about it?

---

<div class="post-metadata">

**Author:** ![HarryPotHead](https://avatars.discourse-cdn.com/v4/letter/h/ba8739/32.png) [@HarryPotHead](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHarryPotHead)%5C
**Post date:** [August 13, 2022, 1:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F9 "2022-08-13T01:06:35Z")

</div>

I don’t know if anyone still needs it, but I cobbled together a rough script to convert some TrOCR models to ONNX.

[Here it is. Hopefully it can help someone out.](https://github.com/OvercookedOmelette/trocr-to-onnx/blob/main/trocr-small-printed-converter.ipynb)

---

<div class="post-metadata">

**Author:** ![WaterKnight](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/waterknight/32/33976_2.png) [@WaterKnight](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FWaterKnight)%5C
**Post date:** [October 5, 2022, 10:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F10 "2022-10-05T10:23:47Z")

</div>

Hi there @lewtun @nielsr , it would be cool if we can do the same for [Donut](https://huggingface.co/docs/transformers/model_doc/donut) model.

In addition, it would be cool to have also the posibility for optimum-intel.

I would be glad to help as it is Hacktoberfest 🙂

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [October 31, 2022, 8:03am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-export-a-visionencoderdecoder-checkpoint-to-onnx%2F12885%2F11 "2022-10-31T08:03:40Z")

</div>

VisionEncoderDecoderModel now has ONNX support, thanks to this PR: [https://github.com/huggingface/transformers/pull/19254](https://github.com/huggingface/transformers/pull/19254).
