Skip to content

Commit

Permalink
[AMP OP&Test] Add float16 OpTest for squeeze, unsqueeze (#52018)
Browse files Browse the repository at this point in the history
* add squeeze, unsqueeze, transpose fp16 unitest

* Update test_transpose_op.py
  • Loading branch information
wang-xinyu authored Mar 28, 2023
1 parent d6011cb commit 866c287
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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 @@ -52,6 +52,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

0 comments on commit 866c287

Please sign in to comment.