From 1bf79e90cafd6d46fe0a7131c7698f24ff812f68 Mon Sep 17 00:00:00 2001 From: caoyang Date: Thu, 16 May 2024 19:51:33 +0800 Subject: [PATCH 1/2] fixed test_dynamic_api_different_type in test_compare_op_npu.py --- backends/npu/tests/unittests/test_compare_op_npu.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backends/npu/tests/unittests/test_compare_op_npu.py b/backends/npu/tests/unittests/test_compare_op_npu.py index 877e0533a..9062b3eca 100755 --- a/backends/npu/tests/unittests/test_compare_op_npu.py +++ b/backends/npu/tests/unittests/test_compare_op_npu.py @@ -115,14 +115,19 @@ def test_dynamic_api_different_type(self): return paddle.disable_static() paddle.set_device("npu:0") - y = np.random.random(size=(10, 7)).astype("int32") + # y = np.random.random(size=(10, 7)).astype("int32") + y = np.random.random(size=(10, 7)).astype("float32") if typename == "bfloat16": x = np.random.random(size=(10, 7)).astype(np.float32) else: x = np.random.random(size=(10, 7)).astype(typename) real_result = callback(x, y) - x = paddle.to_tensor(x, dtype=typename) - y = paddle.to_tensor(y, dtype="float32") + if typename in {"float16", "float32", "bool", "int32"}: + x = paddle.to_tensor(x, dtype="float32") + elif typename == "int64": + x = paddle.to_tensor(x, dtype="float64") + # x = paddle.to_tensor(x, dtype=typename) + y = paddle.to_tensor(y, dtype=x.dtype) op = eval("paddle.%s" % (self.op_type)) out = op(x, y) self.assertEqual((out.numpy() == real_result).all(), True) From 7c3c25a660cd3cfb0500aff786fcb754cfc45519 Mon Sep 17 00:00:00 2001 From: caoyang Date: Thu, 16 May 2024 20:50:49 +0800 Subject: [PATCH 2/2] fixed some bugs in test_dynamic_api_different_type --- backends/npu/tests/unittests/test_compare_op_npu.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/backends/npu/tests/unittests/test_compare_op_npu.py b/backends/npu/tests/unittests/test_compare_op_npu.py index 9062b3eca..874470462 100755 --- a/backends/npu/tests/unittests/test_compare_op_npu.py +++ b/backends/npu/tests/unittests/test_compare_op_npu.py @@ -115,18 +115,16 @@ def test_dynamic_api_different_type(self): return paddle.disable_static() paddle.set_device("npu:0") - # y = np.random.random(size=(10, 7)).astype("int32") y = np.random.random(size=(10, 7)).astype("float32") if typename == "bfloat16": x = np.random.random(size=(10, 7)).astype(np.float32) else: x = np.random.random(size=(10, 7)).astype(typename) real_result = callback(x, y) - if typename in {"float16", "float32", "bool", "int32"}: + if typename in {"bool", "int32", "int64"}: x = paddle.to_tensor(x, dtype="float32") - elif typename == "int64": - x = paddle.to_tensor(x, dtype="float64") - # x = paddle.to_tensor(x, dtype=typename) + else: + x = paddle.to_tensor(x, dtype=typename) y = paddle.to_tensor(y, dtype=x.dtype) op = eval("paddle.%s" % (self.op_type)) out = op(x, y)