提交 72061b0a 编写于 作者: B baojun 提交者: Tao Luo

Add ngraph op coverage (#15721)

上级 572c67e6
......@@ -46,8 +46,6 @@ void BuildFillConstantNode(
ng_dtype = ngraph::element::i64;
} else if (data_type == paddle::framework::proto::VarType::INT32) {
ng_dtype = ngraph::element::i32;
} else if (data_type == paddle::framework::proto::VarType::BOOL) {
ng_dtype = ngraph::element::boolean;
} else {
PADDLE_THROW("unsupported data type: %s", data_type);
}
......
......@@ -15,39 +15,7 @@
from __future__ import print_function
import unittest
import numpy as np
from paddle.fluid.tests.unittests.op_test import OpTest
class TestNGRAPHAccuracyOp(OpTest):
def setUp(self):
self.op_type = "accuracy"
self.dtype = np.float32
self.init_dtype()
n = 128
infer = np.random.random((n, 1)).astype(self.dtype)
indices = np.random.randint(0, 2, (n, 1))
label = np.random.randint(0, 2, (n, 1))
self.inputs = {'Out': infer, 'Indices': indices, "Label": label}
num_correct = 0
for rowid in range(n):
for ele in indices[rowid]:
if ele == label[rowid]:
num_correct += 1
break
self.outputs = {
'Accuracy': np.array([num_correct / float(n)]).astype(self.dtype),
'Correct': np.array([num_correct]).astype("int64"),
'Total': np.array([n]).astype("int64")
}
self._cpu_only = True
def init_dtype(self):
pass
def test_check_output(self):
self.check_output()
from paddle.fluid.tests.unittests.test_accuracy_op import TestAccuracyOp
if __name__ == '__main__':
unittest.main()
......@@ -17,21 +17,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_batch_norm_op import TestBatchNormOpTraining, TestBatchNormOpInference
class TestNGRAPHBatchNormOpTraining(TestBatchNormOpTraining):
def init_kernel_type(self):
super(TestNGRAPHBatchNormOpTraining, self).init_kernel_type()
class TestNGRAPHBatchNormOpInference(TestBatchNormOpInference):
def init_kernel_type(self):
super(TestNGRAPHBatchNormOpInference, self).init_kernel_type()
class TestNGRAPHBatchNormOpWithReluInference(TestBatchNormOpInference):
def init_kernel_type(self):
super(TestNGRAPHBatchNormOpWithReluInference, self).init_kernel_type()
if __name__ == '__main__':
unittest.main()
......@@ -17,60 +17,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_conv2d_op import TestConv2dOp, TestWithPad, TestWithStride, TestWithGroup, TestWith1x1, TestWithInput1x1Filter1x1
class TestNGRAPH(TestConv2dOp):
def setUp(self):
super(TestNGRAPH, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPH, self).init_kernel_type()
class TestNGRAPHWithPad(TestWithPad):
def setUp(self):
super(TestNGRAPHWithPad, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPHWithPad, self).init_kernel_type()
class TestNGRAPHWithStride(TestWithStride):
def setUp(self):
super(TestNGRAPHWithStride, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPHWithStride, self).init_kernel_type()
class TestNGRAPHWithGroup(TestWithGroup):
def setUp(self):
super(TestNGRAPHWithGroup, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPHWithGroup, self).init_kernel_type()
class TestNGRAPHWith1x1(TestWith1x1):
def setUp(self):
super(TestNGRAPHWith1x1, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPHWith1x1, self).init_kernel_type()
class TestNGRAPHWithInput1x1Filter1x1(TestWithInput1x1Filter1x1):
def setUp(self):
super(TestNGRAPHWithInput1x1Filter1x1, self).setUp()
self._cpu_only = True
def init_kernel_type(self):
super(TestNGRAPHWithInput1x1Filter1x1, self).init_kernel_type()
if __name__ == '__main__':
unittest.main()
......@@ -13,18 +13,9 @@
# limitations under the License.
from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_elementwise_add_op import TestElementwiseAddOp
class TestNGRAPHElementwiseAddOp(TestElementwiseAddOp):
def setUp(self):
super(TestNGRAPHElementwiseAddOp, self).setUp()
self._cpu_only = True
def init_input_output(self):
super(TestNGRAPHElementwiseAddOp, self).init_input_output()
import unittest
from paddle.fluid.tests.unittests.test_elementwise_add_op import TestElementwiseAddOp, TestElementwiseAddOp_broadcast_0
if __name__ == '__main__':
unittest.main()
......@@ -13,24 +13,34 @@
# limitations under the License.
from __future__ import print_function
import unittest
import numpy as np
from paddle.fluid.tests.unittests.test_fill_constant_op import TestFillConstantOp1, TestFillConstantOp2, TestFillConstantOpWithSelectedRows
class TestNGRAPHFillConstantOp1(TestFillConstantOp1):
class TestNGRAPHFillConstantFP64(TestFillConstantOp1):
def setUp(self):
super(TestNGRAPHFillConstantOp1, self).setUp()
super(TestNGRAPHFillConstantFP64, self).setUp()
self.attrs = {'shape': [123, 92], 'value': 3.8, 'dtype': 6}
self.outputs = {'Out': np.full((123, 92), 3.8)}
class TestNGRAPHFillConstantOp2(TestFillConstantOp2):
class TestNGRAPHFillConstantINT32(TestFillConstantOp2):
def setUp(self):
super(TestNGRAPHFillConstantOp2, self).setUp()
super(TestNGRAPHFillConstantINT32, self).setUp()
self.attrs = {'shape': [123, 92], 'dtype': 2}
self.outputs = {'Out': np.full((123, 92), 0)}
class TestNGRAPHFillConstantOpWithSelectedRows(
TestFillConstantOpWithSelectedRows):
class TestNGRAPHFillConstantINT64(TestFillConstantOp2):
def setUp(self):
super(TestFillConstantOpWithSelectedRows, self).setUp()
super(TestNGRAPHFillConstantINT64, self).setUp()
self.attrs = {'shape': [123, 92], 'dtype': 3}
self.outputs = {'Out': np.full((123, 92), 0)}
if __name__ == "__main__":
......
......@@ -16,12 +16,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_mean_op import TestMeanOp
class TestNGRAPHMeanOp(TestMeanOp):
def setUp(self):
super(TestNGRAPHMeanOp, self).setUp()
self._cpu_only = True
if __name__ == "__main__":
unittest.main()
......@@ -15,39 +15,7 @@
from __future__ import print_function
import unittest
import numpy as np
from paddle.fluid.tests.unittests.op_test import OpTest
class TestNGRAPHMulOp(OpTest):
def setUp(self):
self.op_type = "mul"
self.dtype = np.float32
self.init_dtype_type()
self.inputs = {
'X': np.random.random((2, 4)).astype(self.dtype),
'Y': np.random.random((4, 4)).astype(self.dtype)
}
self.outputs = {'Out': np.dot(self.inputs['X'], self.inputs['Y'])}
self._cpu_only = True
def init_dtype_type(self):
pass
def test_check_output(self):
self.check_output()
def test_check_grad_normal(self):
self.check_grad(['X', 'Y'], 'Out', max_relative_error=0.5)
def test_check_grad_ingore_x(self):
self.check_grad(
['Y'], 'Out', max_relative_error=0.5, no_grad_set=set("X"))
def test_check_grad_ingore_y(self):
self.check_grad(
['X'], 'Out', max_relative_error=0.5, no_grad_set=set('Y'))
from paddle.fluid.tests.unittests.test_mul_op import TestMulOp, TestMulOp2
if __name__ == "__main__":
unittest.main()
......@@ -14,61 +14,25 @@
from __future__ import print_function
from paddle.fluid.tests.unittests.test_pool2d_op import TestPool2D_Op, TestCase1, TestCase2, TestCase3, TestCase4, TestCase5
class TestNGRAPHPool2D_Op(TestPool2D_Op):
def setUp(self):
super(TestNGRAPHPool2D_Op, self).setUp()
self._cpu_only = True
def init_test_case(self):
super(TestNGRAPHPool2D_Op, self).init_test_case()
class TestNGRAPHCase1(TestCase1):
def setUp(self):
super(TestNGRAPHCase1, self).setUp()
self._cpu_only = True
def init_test_case(self):
super(TestNGRAPHCase1, self).init_test_case()
import unittest
class TestNGRAPHCase2(TestCase2):
def setUp(self):
super(TestNGRAPHCase2, self).setUp()
self._cpu_only = True
def init_test_case(self):
super(TestNGRAPHCase2, self).init_test_case()
class TestNGRAPHCase3(TestCase3):
def setUp(self):
super(TestNGRAPHCase3, self).setUp()
self._cpu_only = True
def init_pool_type(self):
super(TestNGRAPHCase3, self).init_pool_type()
from paddle.fluid.tests.unittests.test_pool2d_op import TestPool2D_Op, TestCase1, TestCase2, TestCase3, TestCase4, TestCase5
class TestNGRAPHCase4(TestCase4):
class TestNGRAPHCeilMode(TestCase1):
def setUp(self):
super(TestNGRAPHCase4, self).setUp()
self._cpu_only = True
super(TestNGRAPHCeilMode, self).setUp()
def init_pool_type(self):
super(TestNGRAPHCase4, self).init_pool_type()
def init_ceil_mode(self):
self.ceil_mode = True
class TestNGRAPHCase5(TestCase5):
class TestNGRAPHAdaptive(TestCase1):
def setUp(self):
super(TestNGRAPHCase5, self).setUp()
self._cpu_only = True
super(TestNGRAPHAdaptive, self).setUp()
def init_pool_type(self):
super(TestNGRAPHCase5, self).init_pool_type()
def init_adaptive(self):
self.adaptive = True
if __name__ == '__main__':
......
......@@ -15,24 +15,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_scale_op import TestScaleOp, TestScaleOpSelectedRows
class TestNGRAPHScaleOp(TestScaleOp):
def setUp(self):
super(TestNGRAPHScaleOp, self).setUp()
self._cpu_only = True
def init_dtype_type(self):
pass
class TestNGRAPHScaleOpSelectedRows(TestScaleOpSelectedRows):
def setUp(self):
super(TestNGRAPHScaleOpSelectedRows, self).setUp()
self._cpu_only = True
def init_dtype_type(self):
pass
if __name__ == "__main__":
unittest.main()
......@@ -16,11 +16,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_softmax_op import TestSoftmaxOp
class TestSoftmaxNGRAPHOp(TestSoftmaxOp):
def setUp(self):
super(TestSoftmaxNGRAPHOp, self).setUp()
if __name__ == "__main__":
unittest.main()
......@@ -16,30 +16,5 @@ from __future__ import print_function
import unittest
from paddle.fluid.tests.unittests.test_top_k_op import TestTopkOp, TestTopkOp3d, TestTopkOp2, TestTopkOp3, TestTopkOp4
class TestNGRAPHTopkOp(TestTopkOp):
def setUp(self):
super(TestNGRAPHTopkOp, self).setUp()
self._cpu_only = True
class TestNGRAPHTopkOp2(TestTopkOp2):
def setUp(self):
super(TestNGRAPHTopkOp2, self).setUp()
self._cpu_only = True
class TestNGRAPHTopkOp3(TestTopkOp3):
def setUp(self):
super(TestNGRAPHTopkOp3, self).setUp()
self._cpu_only = True
class TestNGRAPHTopkOp4(TestTopkOp4):
def setUp(self):
super(TestNGRAPHTopkOp4, self).setUp()
self._cpu_only = True
if __name__ == "__main__":
unittest.main()
......@@ -14,6 +14,7 @@
from __future__ import print_function
import os
import unittest
import numpy as np
import random
......@@ -374,6 +375,9 @@ class OpTest(unittest.TestCase):
return []
places = [fluid.CPUPlace()]
cpu_only = self._cpu_only if hasattr(self, '_cpu_only') else False
use_ngraph = bool(os.getenv("FLAGS_use_ngraph", False))
if use_ngraph:
cpu_only = True
if core.is_compiled_with_cuda() and core.op_support_gpu(self.op_type)\
and not cpu_only:
places.append(core.CUDAPlace(0))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册