From ad5860ddd0fccc69ffc6a1c583d1962f3e09fad9 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <46243324+zrr1999@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:48:59 +0800 Subject: [PATCH] [PIR] No.28 Migrate paddle.gather_nd into pir (#57562) * support gather_nd in pir * update test * add false * fix bug --- python/paddle/tensor/manipulation.py | 2 +- test/legacy_test/test_gather_nd_op.py | 85 ++++++++++++++++++--------- 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 62de7b884275b7..2e366150d36325 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -3798,7 +3798,7 @@ def gather_nd(x, index, name=None): output = paddle.gather_nd(x, index) #[[3, 4]] """ - if in_dynamic_mode(): + if in_dynamic_or_pir_mode(): return _C_ops.gather_nd(x, index) else: check_variable_and_dtype( diff --git a/test/legacy_test/test_gather_nd_op.py b/test/legacy_test/test_gather_nd_op.py index 193a9856c9e674..dd1d996715eefd 100644 --- a/test/legacy_test/test_gather_nd_op.py +++ b/test/legacy_test/test_gather_nd_op.py @@ -53,10 +53,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithEmptyIndexFP16(TestGatherNdOpWithEmptyIndex): @@ -75,11 +75,13 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) - self.check_grad_with_place(place, ['X'], 'Out', check_prim=True) + self.check_grad_with_place( + place, ['X'], 'Out', check_prim=True, check_new_ir=False + ) class TestGatherNdOpWithIndex1(OpTest): @@ -112,10 +114,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithIndex1_ZeroDim(TestGatherNdOpWithIndex1): @@ -161,11 +163,13 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) - self.check_grad_with_place(place, ['X'], 'Out', check_prim=True) + self.check_grad_with_place( + place, ['X'], 'Out', check_prim=True, check_new_ir=False + ) class TestGatherNdOpWithLowIndex(OpTest): @@ -198,10 +202,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithLowIndexFP16(TestGatherNdOpWithLowIndex): @@ -220,12 +224,17 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) self.check_grad_with_place( - place, ['X'], 'Out', check_prim=True, numeric_grad_delta=0.5 + place, + ['X'], + 'Out', + check_prim=True, + check_new_ir=False, + numeric_grad_delta=0.5, ) @@ -264,10 +273,16 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True, numeric_grad_delta=0.05) + self.check_grad( + ['X'], + 'Out', + check_prim=True, + check_new_ir=False, + numeric_grad_delta=0.05, + ) class TestGatherNdOpIndex1FP16(TestGatherNdOpIndex1): @@ -286,12 +301,17 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) self.check_grad_with_place( - place, ['X'], 'Out', check_prim=True, numeric_grad_delta=0.5 + place, + ['X'], + 'Out', + check_prim=True, + check_new_ir=False, + numeric_grad_delta=0.5, ) @@ -322,10 +342,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithSameIndexAsXFP16(TestGatherNdOpWithSameIndexAsX): @@ -344,12 +364,17 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) self.check_grad_with_place( - place, ['X'], 'Out', check_prim=True, numeric_grad_delta=0.5 + place, + ['X'], + 'Out', + check_prim=True, + check_new_ir=False, + numeric_grad_delta=0.5, ) @@ -382,10 +407,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithHighRankSameFP16(TestGatherNdOpWithHighRankSame): @@ -404,11 +429,13 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) - self.check_grad_with_place(place, ['X'], 'Out', check_prim=True) + self.check_grad_with_place( + place, ['X'], 'Out', check_prim=True, check_new_ir=False + ) class TestGatherNdOpWithHighRankDiff(OpTest): @@ -441,10 +468,10 @@ def config_dtype(self): self.dtype = np.float64 def test_check_output(self): - self.check_output() + self.check_output(check_new_ir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_prim=True) + self.check_grad(['X'], 'Out', check_prim=True, check_new_ir=False) class TestGatherNdOpWithHighRankDiffFP16(TestGatherNdOpWithHighRankDiff): @@ -463,11 +490,13 @@ def config_dtype(self): def test_check_output(self): place = core.CUDAPlace(0) - self.check_output_with_place(place) + self.check_output_with_place(place, check_new_ir=True) def test_check_grad(self): place = core.CUDAPlace(0) - self.check_grad_with_place(place, ['X'], 'Out', check_prim=True) + self.check_grad_with_place( + place, ['X'], 'Out', check_prim=True, check_new_ir=False + ) # Test Python API