Skip to content

Add support to export ColPali Model to ONNX#2074

Closed
akshayballal95 wants to merge 6 commits into
huggingface:mainfrom
akshayballal95:main
Closed

Add support to export ColPali Model to ONNX#2074
akshayballal95 wants to merge 6 commits into
huggingface:mainfrom
akshayballal95:main

Conversation

@akshayballal95

Copy link
Copy Markdown

What does this PR do?

This PR adds support for exporting the ColPali merged model to ONNX format. The model is based on the "pali gemma" model type, and thus, I have added it under the "feature-extraction" task. Do suggest if there is a better way to integrate this. If this looks fine with a few modifications, I can add support for the Paligemma text-generation task as well.

Before submitting

Who can review?

@fxmarty, @echarlaix, @JingyaHuang, @michaelbenayoun

@akshayballal95

Copy link
Copy Markdown
Author

@fxmarty, @echarlaix, @JingyaHuang, @michaelbenayoun

Are you open to merging this?

@echarlaix

echarlaix commented Dec 6, 2024

Copy link
Copy Markdown
Collaborator

Comment on lines +512 to +527
class ColPaliModelPatcher(ModelPatcher):
def __init__(
self,
config: "OnnxConfig",
model: Union["PreTrainedModel", "TFPreTrainedModel"],
model_kwargs: Optional[Dict[str, Any]] = None,
):
super().__init__(config, model, model_kwargs)

def patched_forward(input_ids=None, pixel_values=None, attention_mask=None, **kwargs):
outputs = self.orig_forward(
input_ids=input_ids, pixel_values=pixel_values, attention_mask=attention_mask, **kwargs
)
return outputs

self.patched_forward = patched_forward

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its needed because the original ColPali Model only takes **kwargs and no named arguments. This resulted in an error. This fixes that error

Comment thread optimum/exporters/onnx/model_patcher.py Outdated
Comment thread optimum/exporters/onnx/model_configs.py Outdated
@akshayballal95

Copy link
Copy Markdown
Author

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

github-actions Bot commented Apr 7, 2025

Copy link
Copy Markdown

This PR has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants