From b9a773955cd15c1db55e08e3e7ddd3816684bd55 Mon Sep 17 00:00:00 2001 From: hedongdong Date: Thu, 18 Mar 2021 15:54:45 +0800 Subject: [PATCH] fix occasional precision failure of CosineEmbeddingLoss --- mindspore/nn/loss/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindspore/nn/loss/loss.py b/mindspore/nn/loss/loss.py index 836a4224226..7e5a4ed91a7 100644 --- a/mindspore/nn/loss/loss.py +++ b/mindspore/nn/loss/loss.py @@ -909,7 +909,7 @@ class CosineEmbeddingLoss(_Loss): prod_sum = self.reduce_sum(x1 * x2, (1,)) square1 = self.reduce_sum(F.square(x1), (1,)) square2 = self.reduce_sum(F.square(x2), (1,)) - denom = F.sqrt(square1 * square2) + denom = F.sqrt(square1) * F.sqrt(square2) cosine = prod_sum / denom pos_value = 1.0 - cosine