Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR]Migrate gather into pir #58498

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions paddle/phi/infermeta/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,8 @@ void GatherInferMeta(const MetaTensor& x,
if (input_dim.size() == 1) {
// the index is a 0D tensor and the x is a 1D tensor
out->set_dims(phi::DDim(phi::Dim<0>()));
out->set_dtype(x.dtype());
out->share_lod(x);
} else {
if (axis.FromTensor() || axis_v == 0) {
// decrease the output dimension
Expand Down
22 changes: 13 additions & 9 deletions test/legacy_test/test_gather_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def setUp(self):
self.if_enable_cinn()

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(['X'], 'Out', check_prim=True)
self.check_grad(['X'], 'Out', check_prim=True, check_pir=True)

def config(self):
"""
Expand Down Expand Up @@ -115,11 +115,11 @@ def if_enable_cinn(self):
self.enable_cinn = False

def test_check_output(self):
self.check_output_with_place(place=paddle.CUDAPlace(0))
self.check_output_with_place(place=paddle.CUDAPlace(0), check_pir=True)

def test_check_grad(self):
self.check_grad_with_place(
paddle.CUDAPlace(0), ['X'], 'Out', check_prim=True
paddle.CUDAPlace(0), ['X'], 'Out', check_prim=True, check_pir=True
)


Expand Down Expand Up @@ -300,10 +300,10 @@ def setUp(self):
self.outputs = {'Out': out}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(['X'], 'Out', numeric_grad_delta=0.5)
self.check_grad(['X'], 'Out', numeric_grad_delta=0.5, check_pir=True)

def config(self):
"""
Expand All @@ -329,10 +329,10 @@ def setUp(self):
self.outputs = {'Out': out}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(['X'], 'Out')
self.check_grad(['X'], 'Out', check_pir=True)

def config(self):
"""
Expand Down Expand Up @@ -603,11 +603,15 @@ def test_axis_maxsize():


class TestCheckOutType(unittest.TestCase):
@test_with_pir_api
def test_out_type(self):
data = paddle.static.data(shape=[16, 10], dtype='int64', name='x')
index = paddle.static.data(shape=[4], dtype='int64', name='index')
out = paddle.gather(data, index)
self.assertTrue(out.dtype == core.VarDesc.VarType.INT64)
self.assertTrue(
out.dtype == core.VarDesc.VarType.INT64
or out.dtype == core.DataType.INT64
)

def test_pir_out_type(self):
with paddle.pir_utils.IrGuard():
Expand Down