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] No.46 Migrate paddle.nn.functional.pad into pir #57348

Merged
merged 13 commits into from
Sep 26, 2023
Merged
9 changes: 7 additions & 2 deletions python/paddle/nn/functional/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
from paddle import _C_ops
from paddle.base.layer_helper import LayerHelper
from paddle.common_ops_import import Variable, default_main_program
from paddle.framework import core, in_dynamic_mode, in_pir_mode
from paddle.framework import (
core,
in_dynamic_mode,
in_dynamic_or_new_ir_mode,
0x45f marked this conversation as resolved.
Show resolved Hide resolved
in_pir_mode,
)
from paddle.tensor.creation import full

from ...base.data_feeder import (
Expand Down Expand Up @@ -1655,7 +1660,7 @@ def pad(x, pad, mode='constant', value=0.0, data_format="NCHW", name=None):
paddings = pad
pad_value = value

if in_dynamic_mode():
if in_dynamic_or_new_ir_mode():
0x45f marked this conversation as resolved.
Show resolved Hide resolved
out = _C_ops.pad(x, paddings, float(pad_value))
return out

Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_pad2d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def setUp(self):
self.outputs = {'Out': out}

def test_check_output(self):
self.check_output(check_dygraph=False)
self.check_output(check_dygraph=False, check_new_ir=True)

def test_check_grad_normal(self):
self.check_grad(['X'], 'Out', check_dygraph=False)
self.check_grad(['X'], 'Out', check_dygraph=False, check_new_ir=True)

def initTestCase(self):
self.shape = (2, 3, 4, 5)
Expand Down
8 changes: 4 additions & 4 deletions test/legacy_test/test_pad3d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def setUp(self):
self.outputs['Out'] = convert_float_to_uint16(self.outputs['Out'])

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

def test_check_grad_normal(self):
self.check_grad(['X'], 'Out')
self.check_grad(['X'], 'Out', check_new_ir=True)

def get_dtype(self):
return np.float64
Expand Down Expand Up @@ -251,12 +251,12 @@ def get_dtype(self):

def test_check_output(self):
place = core.CUDAPlace(0)
self.check_output_with_place(place, atol=1e-2)
self.check_output_with_place(place, atol=1e-2, check_new_ir=True)

def test_check_grad_normal(self):
place = core.CUDAPlace(0)
self.check_grad_with_place(
place, ['X'], 'Out', max_relative_error=1e-2
place, ['X'], 'Out', max_relative_error=1e-2, check_new_ir=True
)

cls_name = "{}_{}".format(parent.__name__, "BF16OP")
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_pad_constant_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def setUp(self):
}

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

def test_check_grad_normal(self):
self.check_grad(['Y'], 'Out')
self.check_grad(['Y'], 'Out', check_new_ir=True)

def initTestCase(self):
self.x_shape = (16, 40)
Expand Down