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 missing normalize_embeddings argument #3201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions sentence_transformers/SentenceTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def encode(
print(embeddings.shape)
# (3, 768)
"""
kwargs["normalize_embeddings"] = normalize_embeddings
if self.device.type == "hpu" and not self.is_hpu_graph_enabled:
import habana_frameworks.torch as ht

Expand Down Expand Up @@ -685,6 +686,8 @@ def forward(self, input: dict[str, Tensor], **kwargs) -> dict[str, Tensor]:
return super().forward(input)

for module_name, module in self.named_children():
if not kwargs.get("normalize_embeddings", False) and isinstance(module, Normalize):
return input
module_kwarg_keys = self.module_kwargs.get(module_name, [])
module_kwargs = {key: value for key, value in kwargs.items() if key in module_kwarg_keys}
input = module(input, **module_kwargs)
Expand Down