From 6296c3eb89d89f9c8e989dad0c983d53eeef33b1 Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Wed, 18 Jun 2025 16:12:44 +0800 Subject: [PATCH 1/2] fix focal_loss accuracy --- tester/paddle_to_torch/rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 749d05bf..db257506 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -5190,7 +5190,7 @@ def apply(self, paddle_api: str) -> ConvertResult: normalizer = locals().get('normalizer', None) alpha = locals().get('alpha', 0.25) gamma = locals().get('gamma', 2.0) -reduction = locals().get('reduction', 'mean') +reduction = locals().get('reduction', 'sum') prob = torch.sigmoid(logit) pos_loss = -label * alpha * ((1 - prob) ** gamma) * torch.log(prob) From 2c2d388eda51ae050ee33426de9f4f54442a50ce Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Thu, 19 Jun 2025 14:17:32 +0800 Subject: [PATCH 2/2] update --- tester/accuracy.py | 1 + .../accuracy_gpu_error_grads_diff.txt | 61 +++++++++++++++++++ tester/api_config/config_analyzer.py | 4 ++ 3 files changed, 66 insertions(+) diff --git a/tester/accuracy.py b/tester/accuracy.py index 361daf7a..41f0c9ca 100644 --- a/tester/accuracy.py +++ b/tester/accuracy.py @@ -404,6 +404,7 @@ def test(self): "paddle.diagonal_scatter", "paddle.nn.functional.binary_cross_entropy", "paddle.nn.functional.binary_cross_entropy_with_logits", + "paddle.nn.functional.sigmoid_focal_loss", "paddle.nn.functional.gaussian_nll_loss", "paddle.nn.functional.kl_div", "paddle.scale", diff --git a/tester/api_config/5_accuracy/accuracy_gpu_error_grads_diff.txt b/tester/api_config/5_accuracy/accuracy_gpu_error_grads_diff.txt index 26b281a0..2c9d10ee 100644 --- a/tester/api_config/5_accuracy/accuracy_gpu_error_grads_diff.txt +++ b/tester/api_config/5_accuracy/accuracy_gpu_error_grads_diff.txt @@ -15963,3 +15963,64 @@ paddle.cdist(Tensor([8550, 0],"float32"), Tensor([1, 0],"float32"), p=1, ) paddle.cdist(Tensor([8550, 4],"float32"), Tensor([0, 4],"float32"), p=1, ) paddle.cdist(Tensor([900, 0],"float32"), Tensor([1, 0],"float32"), p=1, ) paddle.cdist(Tensor([900, 4],"float32"), Tensor([0, 4],"float32"), p=1, ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([108, 4],"float32"), Tensor([108, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([11, 4],"float32"), Tensor([11, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([110484, 4],"float32"), Tensor([110484, 4],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([117, 4],"float32"), Tensor([117, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([1200, 4],"float32"), Tensor([1200, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([122760, 4],"float32"), Tensor([122760, 4],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([135036, 4],"float32"), Tensor([135036, 4],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([15488, 80],"float32"), label=Tensor([15488, 80],"float32"), normalizer=Tensor([],"float32"), gamma=2.0, alpha=0.25, ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([1620, 4],"float32"), Tensor([1620, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([1728, 4],"float32"), Tensor([1728, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([1800, 4],"float32"), Tensor([1800, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([190960, 80],"float32"), Tensor([190960, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.25, gamma=0.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.25, gamma=0.0, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.25, gamma=3, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.25, gamma=3, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.5, gamma=0.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.5, gamma=0.0, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.5, gamma=3, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), None, alpha=0.5, gamma=3, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.25, gamma=0.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.25, gamma=0.0, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.25, gamma=3, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.25, gamma=3, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.5, gamma=0.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.5, gamma=3, reduction="mean", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.5, gamma=3, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.5, gamma=3, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3],"float32"), Tensor([2, 3],"float32"), normalizer=Tensor([1],"float32"), reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3],"float32"), Tensor([2, 3],"float32"), normalizer=Tensor([],"float32"), reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([20, 4],"float32"), Tensor([20, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([210056, 80],"float32"), Tensor([210056, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([218240, 80],"float32"), Tensor([218240, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([240064, 80],"float32"), Tensor([240064, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([245520, 80],"float32"), Tensor([245520, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([270072, 80],"float32"), Tensor([270072, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([272800, 80],"float32"), Tensor([272800, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([27648, 4],"float32"), Tensor([27648, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([28800, 4],"float32"), Tensor([28800, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([30, 4],"float32"), Tensor([30, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([300, 4],"float32"), Tensor([300, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([300080, 80],"float32"), Tensor([300080, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([330088, 80],"float32"), Tensor([330088, 80],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([35, 4],"float32"), Tensor([35, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([3872, 2],"float32"), label=Tensor([3872, 2],"float32"), normalizer=Tensor([],"float32"), gamma=2.0, alpha=0.25, ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([414, 4],"float32"), Tensor([414, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([432, 4],"float32"), Tensor([432, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([450, 4],"float32"), Tensor([450, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([4800, 4],"float32"), Tensor([4800, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([5, 2],"float32"), label=Tensor([5, 2],"float32"), normalizer=Tensor([1],"float32"), alpha=0.25, gamma=2.0, reduction="sum", name=None, ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([6380, 4],"float32"), Tensor([6380, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([6408, 4],"float32"), Tensor([6408, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([6912, 4],"float32"), Tensor([6912, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([7200, 4],"float32"), Tensor([7200, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([80, 4],"float32"), Tensor([80, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([8550, 4],"float32"), Tensor([8550, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([85932, 4],"float32"), Tensor([85932, 4],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([9, 4],"float32"), Tensor([9, 4],"float32"), alpha=0.25, gamma=2.0, reduction="none", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([95480, 4],"float32"), Tensor([95480, 4],"float32"), ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.5, gamma=0.0, reduction="sum", ) +paddle.nn.functional.sigmoid_focal_loss(Tensor([2, 3, 4, 10],"float64"), Tensor([2, 3, 4, 10],"float64"), Tensor([1],"float64"), alpha=0.25, gamma=3, reduction="mean", ) diff --git a/tester/api_config/config_analyzer.py b/tester/api_config/config_analyzer.py index df1a3650..123330c2 100644 --- a/tester/api_config/config_analyzer.py +++ b/tester/api_config/config_analyzer.py @@ -1801,6 +1801,10 @@ def get_padding_offset(bsz, max_seq_len, seq_lens_this_time): # self.check_arg(api_config, 1, "other"): self.numpy_tensor = self.get_random_numpy_tensor(self.shape, self.dtype, min=-10, max=10) + elif api_config.api_name == "paddle.nn.functional.sigmoid_focal_loss": + if self.check_arg(api_config, 1, "label"): + self.numpy_tensor = numpy.random.randint(low=0, high=2, size=self.shape).astype(self.dtype) + if self.numpy_tensor is None: if USE_CACHED_NUMPY and self.dtype not in ["int64", "float64"]: self.numpy_tensor = self.get_cached_numpy(self.dtype, self.shape)