diff --git a/verify.py b/verify.py index c4c7a86..9aee3a7 100644 --- a/verify.py +++ b/verify.py @@ -166,18 +166,17 @@ class EmbeddingModel: with torch.no_grad(): out = self.model(**inputs) - # Mean pooling, then dense projection (matches SentenceTransformers / mlx-embeddings ≥0.1.0) + # Mean pooling in float32 (matches mlx_embeddings mean_pooling which casts mask to float32) h = out.last_hidden_state - mask = inputs["attention_mask"].unsqueeze(-1).to(h.dtype) - emb = (h * mask).sum(dim=1) / mask.sum(dim=1) + mask = inputs["attention_mask"].unsqueeze(-1).float() + emb = (h.float() * mask).sum(dim=1) / mask.sum(dim=1) emb = emb.squeeze() # Dense projection (identity activation, no bias) - emb = emb @ self.dense0.T - emb = emb @ self.dense1.T + emb = emb @ self.dense0.float().T + emb = emb @ self.dense1.float().T # L2 normalize - emb = emb.float() emb = emb / emb.norm() return emb.numpy().astype(np.float32)