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 API adaptor No.41、138、153】 Migrate paddle.complex, paddle.logspace, paddle.meshgrid into pir #58491

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def logspace(start, stop, num, base=10.0, dtype=None, name=None):
if not isinstance(base, Variable):
with device_guard("cpu"):
tensor_base = fill_constant([1], dtype, base)
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.logspace(
tensor_start,
tensor_stop,
Expand Down Expand Up @@ -1643,7 +1643,7 @@ def meshgrid(*args, **kwargs):

if len(args) == 1 and isinstance(args[0], (list, tuple)):
args = args[0]
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.meshgrid(list(args))
else:
name = kwargs.get("name", None)
Expand Down Expand Up @@ -2603,7 +2603,7 @@ def complex(real, imag, name=None):
[[0j , 1j , 2j ],
[(1+0j), (1+1j), (1+2j)]])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.complex(real, imag)
else:
check_variable_and_dtype(
Expand Down
7 changes: 6 additions & 1 deletion test/legacy_test/test_complex_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import paddle
from paddle import static
from paddle.base import dygraph
from paddle.pir_utils import test_with_pir_api

paddle.enable_static()

Expand All @@ -45,26 +46,29 @@ def setUp(self):
self.outputs = {'Out': out_ref}

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

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

def test_check_grad_ignore_x(self):
self.check_grad(
['Y'],
'Out',
no_grad_set=set('X'),
check_pir=True,
)

def test_check_grad_ignore_y(self):
self.check_grad(
['X'],
'Out',
no_grad_set=set('Y'),
check_pir=True,
)


Expand Down Expand Up @@ -102,6 +106,7 @@ def test_dygraph(self):
out_np = paddle.complex(x, y).numpy()
np.testing.assert_allclose(self.out, out_np, rtol=1e-05)

@test_with_pir_api
def test_static(self):
mp, sp = static.Program(), static.Program()
with static.program_guard(mp, sp):
Expand Down
7 changes: 5 additions & 2 deletions test/legacy_test/test_logspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import paddle
from paddle.base import core
from paddle.pir_utils import test_with_pir_api


class TestLogspaceOpCommonCase(OpTest):
Expand All @@ -39,7 +40,7 @@ def init_data(self):
self.outputs = {'Out': np.power(2, np.arange(0, 11)).astype(dtype)}

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


class TestLogspaceFP16Op(TestLogspaceOpCommonCase):
Expand Down Expand Up @@ -87,7 +88,7 @@ def init_data(self):
self.place = core.CUDAPlace(0)

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


class TestLogspaceOpReverseCase(TestLogspaceOpCommonCase):
Expand Down Expand Up @@ -143,6 +144,7 @@ def init_data(self):


class TestLogspaceAPI(unittest.TestCase):
@test_with_pir_api
def test_variable_input1(self):
paddle.enable_static()
prog = paddle.static.Program()
Expand Down Expand Up @@ -170,6 +172,7 @@ def test_variable_input2(self):
self.assertEqual((out.numpy() == np_res).all(), True)
paddle.enable_static()

@test_with_pir_api
def test_dtype(self):
paddle.enable_static()
prog = paddle.static.Program()
Expand Down
18 changes: 14 additions & 4 deletions test/legacy_test/test_meshgrid_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import paddle
from paddle import base
from paddle.base import core
from paddle.pir_utils import test_with_pir_api


def meshgrid_wrapper(x):
Expand All @@ -41,10 +42,12 @@ def init_data_type(self):
self.dtype = np.float64

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

def test_check_grad(self):
self.check_grad(['x0'], ['out0', 'out1'], check_prim=True)
self.check_grad(
['x0'], ['out0', 'out1'], check_prim=True, check_pir=True
)

def init_inputs_and_outputs(self):
self.shape = self.get_x_shape()
Expand Down Expand Up @@ -122,15 +125,20 @@ 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), ['x0'], ['out0', 'out1'], check_prim=True
paddle.CUDAPlace(0),
['x0'],
['out0', 'out1'],
check_prim=True,
check_pir=True,
)


class TestMeshgridOp3(unittest.TestCase):
@test_with_pir_api
def test_api(self):
x = paddle.static.data(shape=[100], dtype='int32', name='x')
y = paddle.static.data(shape=[200], dtype='int32', name='y')
Expand Down Expand Up @@ -167,6 +175,7 @@ def test_api(self):


class TestMeshgridOp4(unittest.TestCase):
@test_with_pir_api
def test_list_input(self):
x = paddle.static.data(shape=[100], dtype='int32', name='x')
y = paddle.static.data(shape=[200], dtype='int32', name='y')
Expand Down Expand Up @@ -204,6 +213,7 @@ def test_list_input(self):


class TestMeshgridOp5(unittest.TestCase):
@test_with_pir_api
def test_tuple_input(self):
x = paddle.static.data(shape=[100], dtype='int32', name='x')
y = paddle.static.data(shape=[200], dtype='int32', name='y')
Expand Down