# Paligemma2 onnx export KeyError: "Unknown task: image-text-to-text

**URL:** <https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726>\
**Category:** 🤗Optimum\
**Created:** [February 8, 2025, 4:29pm UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726 "2025-02-08T16:29:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![biswajitdevsarma](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@biswajitdevsarma](https://discuss.huggingface.co/u/biswajitdevsarma)\
**Post date:** [February 8, 2025, 4:29pm UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726/1 "2025-02-08T16:29:26Z")

</div>

Hi ,  
I tried to convert the paligemma2 3B parameter model with 224 image resolution to onnx using optimum and got this error:

$optimum-cli export onnx --model google/paligemma-3b-pt-224 paligemma-3b-pt-224\_onnx/

KeyError: “Unknown task: image-text-to-text. Possible values are: `audio-classification` for AutoModelForAudioClassification, `audio-frame-classification` for AutoModelForAudioFrameClassification, `audio-xvector` for AutoModelForAudioXVector, `automatic-speech-recognition` for (‘AutoModelForSpeechSeq2Seq’, ‘AutoModelForCTC’), `depth-estimation` for AutoModelForDepthEstimation, `feature-extraction` for AutoModel, `fill-mask` for AutoModelForMaskedLM, `image-classification` for AutoModelForImageClassification, `image-segmentation` for (‘AutoModelForImageSegmentation’, ‘AutoModelForSemanticSegmentation’, ‘AutoModelForInstanceSegmentation’, ‘AutoModelForUniversalSegmentation’), `image-to-image` for AutoModelForImageToImage, `image-to-text` for (‘AutoModelForVision2Seq’, ‘AutoModel’), `mask-generation` for AutoModel, `masked-im` for AutoModelForMaskedImageModeling, `multiple-choice` for AutoModelForMultipleChoice, `object-detection` for AutoModelForObjectDetection, `question-answering` for AutoModelForQuestionAnswering, `reinforcement-learning` for AutoModel, `semantic-segmentation` for AutoModelForSemanticSegmentation, `text-to-audio` for (‘AutoModelForTextToSpectrogram’, ‘AutoModelForTextToWaveform’), `text-generation` for AutoModelForCausalLM, `text2text-generation` for AutoModelForSeq2SeqLM, `text-classification` for AutoModelForSequenceClassification, `token-classification` for AutoModelForTokenClassification, `visual-question-answering` for AutoModelForVisualQuestionAnswering, `zero-shot-image-classification` for AutoModelForZeroShotImageClassification, `zero-shot-object-detection` for AutoModelForZeroShotObjectDetection”

Please help if you have any solution. Is “image-text-to-text” task is available in optimum? If yes, how to use it?  
Or is there any alternative method to convert the model to onnx?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 9, 2025, 4:36am UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726/2 "2025-02-09T04:36:34Z")

</div>

It seems that this can be avoided by explicitly specifying a task (to one of the supported tasks).

> <https://github.com/huggingface/optimum/issues/1955>
>
> \### Feature request
> 
> I wonder if the task text-classification can to be supporte…d in the ONNX export for clip? Ich want to use the openai/clip-vit-large-path14 model for zero-shot image classification (classification of images without pretraining based on given candidate labels) but I get the following error: 
> ValueError Traceback (most recent call last)
> File /home/danne00a/ZablageBlazeG/ZeroShotClassification/zeroshotclassifier.py:2
> \[1\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/zeroshotclassifier.py:1) #%%
> \----\> \[2\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/zeroshotclassifier.py:2) ort\_model = ORTModelForSequenceClassification.from\_pretrained(model\_checkpoint, export=True)
> 
> File ~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:669, in ORTModel.from\_pretrained(cls, model\_id, export, force\_download, use\_auth\_token, cache\_dir, subfolder, config, local\_files\_only, provider, session\_options, provider\_options, use\_io\_binding, \*\*kwargs)
> \[620\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:620) @classmethod
> \[621\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:621) @add\_start\_docstrings(FROM\_PRETRAINED\_START\_DOCSTRING)
> \[622\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:622) def from\_pretrained(
> (...)
> \[636\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:636) \*\*kwargs,
> \[637\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:637) ):
> \[638\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:638) """
> \[639\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:639) provider (\`str\`, defaults to \`"CPUExecutionProvider"\`):
> \[640\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:640) ONNX Runtime provider to use for loading the model. See https://onnxruntime.ai/docs/execution-providers/ for
> (...)
> \[667\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:667) \`ORTModel\`: The loaded ORTModel model.
> \[668\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:668) """
> \--\> \[669\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:669) return super().from\_pretrained(
> \[670\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:670) model\_id,
> \[671\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:671) export=export,
> \[672\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:672) force\_download=force\_download,
> \[673\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:673) use\_auth\_token=use\_auth\_token,
> \[674\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/onnxruntime/modeling\_ort.py:674) cache\_dir=cache\_dir,
> ...
> \[274\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/exporters/onnx/\_\_main\_\_.py:274) )
> \[276\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/exporters/onnx/\_\_main\_\_.py:276) # TODO: Fix in Transformers so that SdpaAttention class can be exported to ONNX. \`attn\_implementation\` is introduced in Transformers 4.36.
> \[277\](https://vscode-remote+ssh-002dremote-002bdemlhr7sw119x.vscode-resource.vscode-cdn.net/home/danne00a/ZablageBlazeG/ZeroShotClassification/~/mambaforge/envs/ZeroShot\_Mamba\_env/lib/python3.11/site-packages/optimum/exporters/onnx/\_\_main\_\_.py:277) if model\_type in SDPA\_ARCHS\_ONNX\_EXPORT\_NOT\_SUPPORTED and \_transformers\_version \>= version.parse("4.35.99"):
> 
> ValueError: Asked to export a clip model for the task text-classification, but the Optimum ONNX exporter only supports the tasks feature-extraction, zero-shot-image-classification for clip. Please use a supported task. Please open an issue at https://github.com/huggingface/optimum/issues if you would like the task text-classification to be supported in the ONNX export for clip.
> 
> \### Motivation
> 
> I'm struggling with the sioze of the openai/clip-vit-large-patch14 model, thus I want to convert it to OPTIMUM onnx!
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> \### Your contribution
> 
> no ideas so far..

---

<div class="post-metadata">

**Author:** ![biswajitdevsarma](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@biswajitdevsarma](https://discuss.huggingface.co/u/biswajitdevsarma)\
**Post date:** [February 10, 2025, 3:29am UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726/3 "2025-02-10T03:29:31Z")

</div>

I tried specifying one of the existing task image-to-text. But that throws another error

$optimum-cli export onnx --model google/paligemma-3b-pt-224 --task image-to-text paligemma-3b-pt-224\_onnx/

ValueError: Trying to export a paligemma model, that is a custom or unsupported architecture, but no custom onnx configuration was passed as `custom_onnx_configs`. Please refer to [Export a model to ONNX with optimum.exporters.onnx](https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model#custom-export-of-transformers-models) for an example on how to export custom models. Please open an issue at [GitHub · Where software is built](https://github.com/huggingface/optimum/issues) if you would like the model type paligemma to be supported natively in the ONNX export.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 10, 2025, 5:45am UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726/4 "2025-02-10T05:45:15Z")

</div>

Of course, some of the newer models are not supported, but I found a converted version of Paligemma2. Maybe the github version of ONNX supports it.

The best way to find out is to ask the ONNX Community, who distribute it…

> **[onnx-community/paligemma2-3b-pt-224 · Hugging Face](https://huggingface.co/onnx-community/paligemma2-3b-pt-224)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![biswajitdevsarma](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@biswajitdevsarma](https://discuss.huggingface.co/u/biswajitdevsarma)\
**Post date:** [February 11, 2025, 4:19pm UTC](https://discuss.huggingface.co/t/paligemma2-onnx-export-keyerror-unknown-task-image-text-to-text/139726/5 "2025-02-11T16:19:03Z")

</div>

@John6666 Thanks
