Skip to content

Commit 5424568

Browse files
committed
static method
1 parent 4277c75 commit 5424568

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/fairseq2/models/wav2vec2/_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ def _sample_distractors(self, targets: Tensor) -> Tensor:
254254

255255
return distractors
256256

257+
@staticmethod
257258
def cosine_similarity(
258-
self, x1: torch.Tensor, x2: torch.Tensor, dim=1, eps=1e-8
259+
x1: torch.Tensor, x2: torch.Tensor, dim=1, eps=1e-8
259260
) -> torch.Tensor:
260261
# Normalize along the specified dimension
261262
x1_norm = x1 / (x1.norm(dim=dim, dtype=x1.dtype).clamp(min=eps).unsqueeze(dim))
@@ -276,7 +277,7 @@ def _compute_logits(
276277

277278
# Perform in fp32.
278279
# (N, S, L + 1, M) -> (N, S, L + 1)
279-
logits = self.cosine_similarity(seqs, candidates, dim=-1)
280+
logits = Wav2Vec2Model.cosine_similarity(seqs, candidates, dim=-1)
280281

281282
if self.logit_temp != 1.0:
282283
logits = logits / self.logit_temp

0 commit comments

Comments
 (0)