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] Add float16 OpTest for squeeze, unsqueeze #52018

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions python/paddle/fluid/tests/unittests/test_squeeze_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ def init_attrs(self):
self.attrs = {"axes": self.axes}


class TestSqueezeFP16Op(OpTest):
def setUp(self):
self.op_type = "squeeze"
self.init_test_case()
self.inputs = {"X": np.random.random(self.ori_shape).astype("float16")}
self.init_attrs()
self.outputs = {
"Out": self.inputs["X"].reshape(self.new_shape),
}

def test_check_output(self):
self.check_output()

def test_check_grad(self):
self.check_grad(["X"], "Out")

def init_test_case(self):
self.ori_shape = (1, 3, 1, 40)
self.axes = (0, 2)
self.new_shape = (3, 40)

def init_attrs(self):
self.attrs = {"axes": self.axes}


class TestSqueezeBF16Op(OpTest):
def setUp(self):
self.op_type = "squeeze"
Expand Down
23 changes: 23 additions & 0 deletions python/paddle/fluid/tests/unittests/test_unsqueeze_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ def init_attrs(self):
self.attrs = {"axes": self.axes}


class TestUnsqueezeFP16Op(OpTest):
def setUp(self):
self.init_test_case()
self.op_type = "unsqueeze"
self.inputs = {"X": np.random.random(self.ori_shape).astype("float16")}
self.init_attrs()
self.outputs = {"Out": self.inputs["X"].reshape(self.new_shape)}

def test_check_output(self):
self.check_output()

def test_check_grad(self):
self.check_grad(["X"], "Out")

def init_test_case(self):
self.ori_shape = (3, 40)
self.axes = (1, 2)
self.new_shape = (3, 1, 1, 40)

def init_attrs(self):
self.attrs = {"axes": self.axes}


class TestUnsqueezeBF16Op(OpTest):
def setUp(self):
self.init_test_case()
Expand Down