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

[AMP OP&Test] Element wise op add fp16 test #52240

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Changes from all 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
37 changes: 27 additions & 10 deletions python/paddle/fluid/tests/unittests/test_elementwise_add_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,29 @@ def init_dtype(self):

def test_check_output(self):
# TODO(wangzhongpu): support mkldnn op in dygraph mode
if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
if core.is_float16_supported(place):
self.check_output_with_place(
place,
atol=1e-3,
check_dygraph=self.check_dygraph(),
check_prim=self.check_prim,
)
place = core.CUDAPlace(0)
self.check_output_with_place(
place,
atol=1e-3,
check_dygraph=self.check_dygraph(),
check_prim=self.check_prim,
)

def test_check_grad_normal(self):
place = core.CUDAPlace(0)
self.check_grad_with_place(place, ['X', 'Y'], 'Out', check_prim=True)

def test_check_grad_ingore_x(self):
place = core.CUDAPlace(0)
self.check_grad_with_place(
place, ['Y'], 'Out', no_grad_set=set("X"), check_prim=True
)

def test_check_grad_ingore_y(self):
place = core.CUDAPlace(0)
self.check_grad_with_place(
place, ['X'], 'Out', no_grad_set=set('Y'), check_prim=True
)


@unittest.skipIf(
Expand Down Expand Up @@ -487,11 +501,14 @@ def if_enable_cinn(self):
self.enable_cinn = False


@skip_check_grad_ci(
reason="[skip shape check] Use y_shape(1) to test broadcast."
)
class TestFP16ElementwiseAddOp_rowwise_add_1(TestFP16ElementwiseAddOp):
def init_input_output(self):
self.x = np.random.rand(100, 1).astype(self.dtype)
self.y = np.random.rand(1).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 1)
self.out = self.x + self.y


class TestElementwiseAddOp_channelwise_add(TestElementwiseAddOp):
Expand Down