From d7a1bca21cfcda5f0dc823a39922780712b2becc Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 24 Jan 2024 14:42:41 +0800 Subject: [PATCH 1/4] fix --- test/legacy_test/test_softmax_op.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/legacy_test/test_softmax_op.py b/test/legacy_test/test_softmax_op.py index 74b685333d9252..f7dc238b9b0efc 100644 --- a/test/legacy_test/test_softmax_op.py +++ b/test/legacy_test/test_softmax_op.py @@ -558,6 +558,7 @@ def test_dygraph_check(self): paddle.enable_static() + @test_with_pir_api def test_error(self): with static_guard(): with paddle.static.program_guard(paddle.static.Program()): From 80b7b2d6c365978b448a7bf38933e9bfe931e8e9 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Jan 2024 09:36:41 +0800 Subject: [PATCH 2/4] fix --- test/legacy_test/test_softmax_op.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/legacy_test/test_softmax_op.py b/test/legacy_test/test_softmax_op.py index f7dc238b9b0efc..79e9130bbd9e92 100644 --- a/test/legacy_test/test_softmax_op.py +++ b/test/legacy_test/test_softmax_op.py @@ -560,20 +560,20 @@ def test_dygraph_check(self): @test_with_pir_api def test_error(self): - with static_guard(): - with paddle.static.program_guard(paddle.static.Program()): - # The input type must be Variable. - self.assertRaises(TypeError, self.softmax, 1) - # The input dtype must be float16, float32, float64. - x_int32 = paddle.static.data( - name='x_int32', shape=[2, 3], dtype='int32' - ) - self.assertRaises(TypeError, self.softmax, x_int32) - # support the input dtype is float16 - x_fp16 = paddle.static.data( - name='x_fp16', shape=[2, 3], dtype='float16' - ) - self.softmax(x_fp16) + paddle.enable_static() + with paddle.static.program_guard(paddle.static.Program()): + # The input type must be Variable. + self.assertRaises(TypeError, self.softmax, 1) + # The input dtype must be float16, float32, float64. + x_int32 = paddle.static.data( + name='x_int32', shape=[2, 3], dtype='int32' + ) + self.assertRaises(TypeError, self.softmax, x_int32) + # support the input dtype is float16 + x_fp16 = paddle.static.data( + name='x_fp16', shape=[2, 3], dtype='float16' + ) + self.assertRaises(TypeError, self.softmax, x_fp16) class TestSoftmaxAPI_ZeroDim(unittest.TestCase): From 31337f987222568343be31ab8c0f16447de40276 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Jan 2024 10:24:00 +0800 Subject: [PATCH 3/4] fix --- test/legacy_test/test_softmax_op.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/legacy_test/test_softmax_op.py b/test/legacy_test/test_softmax_op.py index 79e9130bbd9e92..c2a9f4a632f14e 100644 --- a/test/legacy_test/test_softmax_op.py +++ b/test/legacy_test/test_softmax_op.py @@ -547,7 +547,7 @@ def test_dygraph_check(self): for r in [out1, out2]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) - # explicilty use float32 for ROCm, as MIOpen does not yet support float64 + # explicitly use float32 for ROCm, as MIOpen does not yet support float64 if core.is_compiled_with_rocm(): out = self.softmax(x, dtype=np.float32) out_ref = ref_softmax(self.x_np, axis=-1, dtype=np.float32) @@ -569,11 +569,6 @@ def test_error(self): name='x_int32', shape=[2, 3], dtype='int32' ) self.assertRaises(TypeError, self.softmax, x_int32) - # support the input dtype is float16 - x_fp16 = paddle.static.data( - name='x_fp16', shape=[2, 3], dtype='float16' - ) - self.assertRaises(TypeError, self.softmax, x_fp16) class TestSoftmaxAPI_ZeroDim(unittest.TestCase): From 4d064a4897c152452edfd6520011d393d90b4609 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 29 Jan 2024 16:33:56 +0800 Subject: [PATCH 4/4] fix --- test/legacy_test/test_softmax_op.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/legacy_test/test_softmax_op.py b/test/legacy_test/test_softmax_op.py index c2a9f4a632f14e..21d5ca3aedd2f0 100644 --- a/test/legacy_test/test_softmax_op.py +++ b/test/legacy_test/test_softmax_op.py @@ -560,15 +560,21 @@ def test_dygraph_check(self): @test_with_pir_api def test_error(self): - paddle.enable_static() - with paddle.static.program_guard(paddle.static.Program()): - # The input type must be Variable. - self.assertRaises(TypeError, self.softmax, 1) - # The input dtype must be float16, float32, float64. - x_int32 = paddle.static.data( - name='x_int32', shape=[2, 3], dtype='int32' - ) - self.assertRaises(TypeError, self.softmax, x_int32) + with static_guard(): + with paddle.static.program_guard(paddle.static.Program()): + # The input type must be Variable. + self.assertRaises(TypeError, self.softmax, 1) + # The input dtype must be float16, float32, float64. + x_int32 = paddle.static.data( + name='x_int32', shape=[2, 3], dtype='int32' + ) + self.assertRaises(TypeError, self.softmax, x_int32) + + if core.is_compiled_with_cuda(): + x_fp16 = paddle.static.data( + name='x_fp16', shape=[2, 3], dtype='float16' + ) + self.softmax(x_fp16) class TestSoftmaxAPI_ZeroDim(unittest.TestCase):