Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add trust remote code to cross encoders #2595

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

bwanglzu
Copy link
Contributor

@bwanglzu bwanglzu commented Apr 16, 2024

A tiny PR to allow trust_remote_code in CrossEncoder to align with SentenceTransformer signature.

Also a bit cleaning of the code, remove duplicate variables and re-order the docstring.

:param trust_remote_code: Whether or not to allow for custom models defined on the Hub in their own modeling files.
This option should only be set to True for repositories you trust and in which you have read the code, as it
will execute code present on the Hub on your local machine.
:param revision: The specific model version to use. It can be a branch name, a tag name, or a commit id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well spotted!

Copy link
Collaborator

@tomaarsen tomaarsen left a comment

Choose a reason for hiding this comment

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

Looks quite clean. Are you sure that it's not necessary to add trust_remote_code to the AutoModel.from_pretrained once you've added it in the AutoConfig.from_pretrained already?

@bwanglzu
Copy link
Contributor Author

@tomaarsen my colleague did some test let me try again :)

@bwanglzu
Copy link
Contributor Author

you're right, i tested again, even through the results are identical, without adding trust_remote_code to from_pretrained keeps asking me to enter yes with a pop-up message in CLI:

tensor([0.2811, 0.3452, 0.8731])
The repository for jinaai/jina-reranker-v1-tiny-en contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/jinaai/jina-reranker-v1-tiny-en.
You can avoid this prompt in future by passing the argument `trust_remote_code=True`.

Do you wish to run the custom code? [y/N] y
[0.28105804 0.34524447 0.87314653]

after adding it:

tensor([0.2811, 0.3452, 0.8731])
[0.28105804 0.34524447 0.87314653]

I updated the PR :) thanks!

Bo

@bwanglzu bwanglzu marked this pull request as ready for review April 16, 2024 13:35
@tomaarsen
Copy link
Collaborator

Thanks a bunch for this PR! It should be ready. I'll get this released tomorrow or Thursday as v2.7.0.
Perhaps I can add a tiny model to the CI once there is a good option in a little while.

  • Tom Aarsen

@tomaarsen tomaarsen merged commit efa3ed1 into UKPLab:master Apr 16, 2024
9 checks passed
@bwanglzu bwanglzu deleted the feat-trust-remote-code-reranker branch April 17, 2024 08:55
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.

2 participants