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 matryoshka norm loss #9774

Merged
merged 6 commits into from
Jan 14, 2025
Merged
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: 2 additions & 2 deletions paddlenlp/transformers/contrastive_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
if len(self.embedding_matryoshka_dims) > 0:
loss = 0.0
for dim in self.embedding_matryoshka_dims:
reduced_q_reps = q_reps[:, :dim]
reduced_q_reps = q_reps[:, :dim].astype("float32")

Check warning on line 55 in paddlenlp/transformers/contrastive_loss.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/contrastive_loss.py#L55

Added line #L55 was not covered by tests
reduced_q_reps = nn.functional.normalize(reduced_q_reps, axis=-1)

reduced_p_reps = p_reps[:, :dim]
reduced_p_reps = p_reps[:, :dim].astype("float32")

Check warning on line 58 in paddlenlp/transformers/contrastive_loss.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/contrastive_loss.py#L58

Added line #L58 was not covered by tests
reduced_p_reps = nn.functional.normalize(reduced_p_reps, axis=-1)

dim_loss = self.loss_fn(reduced_q_reps, reduced_p_reps)
Expand Down