Skip to content

Commit

Permalink
[PIR] Migrate paddle.nn.LeakyReLU into pir (#58340)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioLulab authored Oct 25, 2023
1 parent ff17b89 commit b4b8337
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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
11 changes: 7 additions & 4 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 @@ -4750,7 +4751,9 @@ def test_check_grad(self):
create_test_act_fp16_class(TestSwish)
create_test_act_fp16_class(TestHardSwish, check_prim=True)
create_test_act_fp16_class(TestMish)
create_test_act_fp16_class(TestLeakyRelu, check_prim=True, enable_cinn=True)
create_test_act_fp16_class(
TestLeakyRelu, check_prim=True, enable_cinn=True, check_pir=True
)
create_test_act_fp16_class(
TestLeakyReluAlpha1, check_prim=True, enable_cinn=True
)
Expand Down Expand Up @@ -4898,7 +4901,7 @@ def test_check_grad(self):
create_test_act_bf16_class(TestSwish)
create_test_act_bf16_class(TestHardSwish, check_prim=True)
create_test_act_bf16_class(TestMish)
create_test_act_bf16_class(TestLeakyRelu, check_prim=True)
create_test_act_bf16_class(TestLeakyRelu, check_prim=True, check_pir=True)
create_test_act_bf16_class(TestLeakyReluAlpha1, check_prim=True)
create_test_act_bf16_class(TestLeakyReluAlpha2, check_prim=True)
create_test_act_bf16_class(TestLeakyReluAlpha3, check_prim=True)
Expand Down

0 comments on commit b4b8337

Please sign in to comment.