Skip to content

Commit

Permalink
[PIR] Migrate paddle.sin into pir (PaddlePaddle#58094)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioLulab authored Oct 17, 2023
1 parent 4607791 commit 6650a12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/paddle/tensor/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ def sin(x, name=None):
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.38941833, -0.19866933, 0.09983342, 0.29552022])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.sin(x)
else:
check_variable_and_dtype(
Expand Down
17 changes: 13 additions & 4 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from paddle import base, static
from paddle.base import Program, core, program_guard
from paddle.base.layer_helper import LayerHelper
from paddle.pir_utils import test_with_pir_api


@contextmanager
Expand Down Expand Up @@ -2066,14 +2067,22 @@ def setUp(self):
def init_shape(self):
self.shape = [10, 12]

@test_with_pir_api
def test_out_name(self):
# inherit from `TestParameter`
super().test_out_name()

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

def test_check_grad(self):
if self.dtype == np.float16:
return
# TODO(ScottWong98): set `check_prim=False` when `fill_any_like` supports `complex` dtype
if self.dtype == np.complex64 or self.dtype == np.complex128:
self.check_grad(['X'], 'Out', check_prim=False)
self.check_grad(['X'], 'Out', check_prim=False, check_pir=True)
else:
self.check_grad(['X'], 'Out', check_prim=True)
self.check_grad(['X'], 'Out', check_prim=True, check_pir=True)

def if_enable_cinn(self):
pass
Expand Down Expand Up @@ -4675,7 +4684,7 @@ def test_check_grad(self):
create_test_act_fp16_class(TestTan)
create_test_act_fp16_class(TestCosh)
create_test_act_fp16_class(TestAcos)
create_test_act_fp16_class(TestSin)
create_test_act_fp16_class(TestSin, check_pir=True)
create_test_act_fp16_class(TestSinh)
create_test_act_fp16_class(TestAsin)
create_test_act_fp16_class(TestAtan)
Expand Down Expand Up @@ -4827,7 +4836,7 @@ def test_check_grad(self):
create_test_act_bf16_class(TestTan)
create_test_act_bf16_class(TestCosh)
create_test_act_bf16_class(TestAcos)
create_test_act_bf16_class(TestSin)
create_test_act_bf16_class(TestSin, check_pir=True)
create_test_act_bf16_class(TestSinh)
create_test_act_bf16_class(TestAsin)
create_test_act_bf16_class(TestAtan)
Expand Down

0 comments on commit 6650a12

Please sign in to comment.