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

Fix sentence-similarity model URL #2596

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hanouticelina
Copy link
Contributor

@hanouticelina hanouticelina commented Oct 9, 2024

Fixes #2494.

This small PR fixes an issue when calling InferenceClient.sentence_similarity() with a model URL.

Issue

Calling InferenceClient.sentence_similarity() using a deployed Inference Endpoint or a localhost URL results in HfHubHTTPError: 422 Client Error.
In general, this is a result of a discrepancy between Inference API and a (local or deployed) inference endpoint.

Fix

adding a /similarity suffix to the model URL. See also TEI OpenAPI doc.

@HuggingFaceDocBuilderDev

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.

Comment on lines +3008 to +3009
if task == "sentence-similarity":
model += "/similarity"
Copy link
Contributor

@Wauplin Wauplin Oct 10, 2024

Choose a reason for hiding this comment

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

Unfortunately, this issue is not as straightforward to fix as that. Given an Inference Endpoint url, we can't be sure that the model is powered by Text-Embedding-Inference and therefore that we should use the /similarity route. For example, if you go to https://huggingface.co/sentence-transformers/all-mpnet-base-v2 > "Inference Endpoints (dedicated)", the default framework won't be TEI but transformers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could check the Inference Endpoint info to get this information (e.g. send a call to model + "/info") but it feels clunky. Ping @osanseviero if you have a better idea on this.

@osanseviero
Copy link
Contributor

cc @tomaarsen for vis

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.

client.sentence_similarity() does not use correct route by default
4 participants