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.221】 Migrate paddle.nn.Swish/LeakyReLU into pir #58394

Merged
merged 3 commits into from
Oct 31, 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
4 changes: 2 additions & 2 deletions python/paddle/nn/functional/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def leaky_relu(x, negative_slope=0.01, name=None):
[-0.02000000, 0. , 1. ])

"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.leaky_relu(x, negative_slope)
else:
check_variable_and_dtype(
Expand Down Expand Up @@ -1448,7 +1448,7 @@ def swish(x, name=None):
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.23840584, 0. , 0.73105860])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.swish(x)
else:
check_variable_and_dtype(
Expand Down
8 changes: 6 additions & 2 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -2466,12 +2466,12 @@ def if_enable_cinn(self):
pass

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):
if self.dtype == np.float16:
return
self.check_grad(['X'], 'Out', check_prim=True)
self.check_grad(['X'], 'Out', check_prim=True, check_pir=True)


class TestLeakyReluAlpha1(TestLeakyRelu):
Expand Down Expand Up @@ -2508,6 +2508,7 @@ def setUp(self):
else paddle.CPUPlace()
)

@test_with_pir_api
def test_static_api(self):
with static_guard():
with paddle.static.program_guard(paddle.static.Program()):
Expand Down Expand Up @@ -4407,6 +4408,7 @@ def test_check_grad(self):
self.check_grad(
['X'],
'Out',
check_pir=True,
)


Expand All @@ -4426,6 +4428,7 @@ def setUp(self):
else paddle.CPUPlace()
)

@test_with_pir_api
def test_static_api(self):
with static_guard():
with paddle.static.program_guard(paddle.static.Program()):
Expand All @@ -4449,6 +4452,7 @@ def test_dygraph_api(self):
for r in [out1, out2]:
np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05)

@test_with_pir_api
def test_base_api(self):
with static_guard():
with base.program_guard(base.Program()):
Expand Down