Skip to content

Add ONNX export support for ModernBERT#2131

Merged
xenova merged 7 commits intomainfrom
add-modernbert-onnx
Jan 7, 2025
Merged

Add ONNX export support for ModernBERT#2131
xenova merged 7 commits intomainfrom
add-modernbert-onnx

Conversation

@xenova
Copy link
Copy Markdown
Contributor

@xenova xenova commented Dec 19, 2024

What does this PR do?

This PR adds ONNX export support for ModernBERT, added to transformers in huggingface/transformers#35158. It uses torch.compile decorators for certain functions, which is not supported in torch.onnx.export (with dynamo=False), so I introduced a model loader context manager to disable this when the model is being loaded. Note that this cannot happen in a model patcher since by then, the model class has already been created.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@xenova xenova marked this pull request as ready for review December 20, 2024 15:17
@xenova
Copy link
Copy Markdown
Contributor Author

xenova commented Dec 20, 2024

Now works with sentence-transformers & transformers models 👍

@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.

Copy link
Copy Markdown
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot @xenova

@xenova xenova merged commit 72498dd into main Jan 7, 2025
@xenova xenova deleted the add-modernbert-onnx branch January 7, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants