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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,10 @@ def _resolve_url(self, model: Optional[str] = None, task: Optional[str] = None)

# If model is already a URL, ignore `task` and return directly
if model is not None and (model.startswith("http://") or model.startswith("https://")):
# special case for sentence-similarity with TEI endpoints for which we need to add the `/similarity` suffix.
# see: https://huggingface.github.io/text-embeddings-inference/openapi.json.
if task == "sentence-similarity":
model += "/similarity"
Comment on lines +3008 to +3009
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.

return model

# # If no model but task is set => fetch the recommended one for this task
Expand Down
4 changes: 4 additions & 0 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,10 @@ def _resolve_url(self, model: Optional[str] = None, task: Optional[str] = None)

# If model is already a URL, ignore `task` and return directly
if model is not None and (model.startswith("http://") or model.startswith("https://")):
# special case for sentence-similarity with TEI endpoints for which we need to add the `/similarity` suffix.
# see: https://huggingface.github.io/text-embeddings-inference/openapi.json.
if task == "sentence-similarity":
model += "/similarity"
return model

# # If no model but task is set => fetch the recommended one for this task
Expand Down
Loading