all cases use large shape and skip special cases (#22332)

revert-22710-feature/integrated_ps_api
zhupengyang 5 years ago committed by hong19860320
parent 82bc814a57
commit cf0e264e63

@ -16,7 +16,7 @@ from __future__ import print_function
import unittest
import numpy as np
import paddle.fluid.core as core
from paddle.fluid.tests.unittests.op_test import OpTest
from paddle.fluid.tests.unittests.op_test import OpTest, skip_check_grad_ci
from paddle.fluid.tests.unittests.test_elementwise_add_op import *
'''
Some tests differ from the tests defined in test_elementwise_add_op.py
@ -35,6 +35,8 @@ class TestMKLDNNElementwiseAddOp(TestElementwiseAddOp):
self.use_mkldnn = True
@skip_check_grad_ci(
reason="[skip shape check] Use y_shape(1) to test broadcast.")
class TestMKLDNNElementwiseAddOp_scalar(TestElementwiseAddOp_scalar):
def init_input_output(self):
self.x = np.random.rand(2, 3, 4, 5).astype(self.dtype)
@ -45,6 +47,8 @@ class TestMKLDNNElementwiseAddOp_scalar(TestElementwiseAddOp_scalar):
self.use_mkldnn = True
@skip_check_grad_ci(
reason="[skip shape check] Use y_shape(1,1) to test broadcast.")
class TestMKLDNNElementwiseAddOp_scalar2(TestElementwiseAddOp_scalar2):
def init_input_output(self):
self.x = np.random.rand(2, 3, 4, 5).astype(self.dtype)
@ -62,9 +66,9 @@ class TestMKLDNNElementwiseAddOp_Vector(TestElementwiseAddOp_Vector):
class TesMKLDNNtElementwiseAddOp_broadcast_0(TestElementwiseAddOp_broadcast_0):
def init_input_output(self):
self.x = np.random.rand(2, 3, 4, 5).astype(self.dtype)
self.y = np.random.rand(2).astype(self.dtype)
self.out = self.x + self.y.reshape(2, 1, 1, 1)
self.x = np.random.rand(100, 2, 3, 4).astype(self.dtype)
self.y = np.random.rand(100).astype(self.dtype)
self.out = self.x + self.y.reshape(100, 1, 1, 1)
def init_kernel_type(self):
self.use_mkldnn = True
@ -72,9 +76,9 @@ class TesMKLDNNtElementwiseAddOp_broadcast_0(TestElementwiseAddOp_broadcast_0):
class TestMKLDNNElementwiseAddOp_broadcast_1(TestElementwiseAddOp_broadcast_1):
def init_input_output(self):
self.x = np.random.rand(2, 3, 4, 5).astype(self.dtype)
self.y = np.random.rand(3).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 3, 1, 1)
self.x = np.random.rand(2, 100, 3, 4).astype(self.dtype)
self.y = np.random.rand(100).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 100, 1, 1)
def init_kernel_type(self):
self.use_mkldnn = True
@ -82,9 +86,9 @@ class TestMKLDNNElementwiseAddOp_broadcast_1(TestElementwiseAddOp_broadcast_1):
class TestMKLDNNElementwiseAddOp_broadcast_2(TestElementwiseAddOp_broadcast_2):
def init_input_output(self):
self.x = np.random.rand(2, 2, 3, 4).astype(self.dtype)
self.y = np.random.rand(4).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 1, 1, 4)
self.x = np.random.rand(2, 2, 3, 100).astype(self.dtype)
self.y = np.random.rand(100).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 1, 1, 100)
def init_kernel_type(self):
self.use_mkldnn = True
@ -103,9 +107,9 @@ class TestMKLDNNElementwiseAddOp_broadcast_4(TestElementwiseAddOp_broadcast_4):
class TestMKLDNNElementwiseAddOp_rowwise_add_0(
TestElementwiseAddOp_rowwise_add_0):
def init_input_output(self):
self.x = np.random.rand(2, 3, 4, 5).astype(self.dtype)
self.y = np.random.rand(3, 4).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 3, 4, 1)
self.x = np.random.rand(2, 10, 12, 3).astype(self.dtype)
self.y = np.random.rand(10, 12).astype(self.dtype)
self.out = self.x + self.y.reshape(1, 10, 12, 1)
def init_kernel_type(self):
self.use_mkldnn = True
@ -120,8 +124,8 @@ class TestMKLDNNElementwiseAddOp_rowwise_add_1(
class TestMKLDNNElementwiseAddOp_channelwise_add(
TestElementwiseAddOp_channelwise_add):
def init_input_output(self):
self.x = np.random.rand(3, 5, 20, 20).astype(self.dtype)
self.y = np.random.rand(3, 1, 1, 1).astype(self.dtype)
self.x = np.random.rand(100, 2, 3, 3).astype(self.dtype)
self.y = np.random.rand(100, 1, 1, 1).astype(self.dtype)
self.out = self.x + self.y
def init_kernel_type(self):

@ -232,7 +232,6 @@ class OpTest(unittest.TestCase):
cls.op_type)
if not get_numeric_gradient.is_large_shape \
and cls.op_type not in check_shape_white_list.NOT_CHECK_OP_LIST \
and cls.op_type not in check_shape_white_list.NEED_TO_FIX_OP_LIST:
raise AssertionError(
"Input's shape should be large than or equal to 100 for " +

@ -15,7 +15,7 @@
from __future__ import print_function
import unittest
import numpy as np
from op_test import OpTest
from op_test import OpTest, skip_check_grad_ci
class TestElementwiseOp(OpTest):
@ -42,6 +42,8 @@ class TestElementwiseOp(OpTest):
['X'], 'Out', max_relative_error=0.005, no_grad_set=set('Y'))
@skip_check_grad_ci(
reason="[skip shape check] Use y_shape(1) to test broadcast.")
class TestElementwiseSubOp_scalar(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
@ -66,13 +68,13 @@ class TestElementwiseSubOp_broadcast_0(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 13, 4).astype(np.float64),
'Y': np.random.rand(2).astype(np.float64)
'X': np.random.rand(100, 3, 2).astype(np.float64),
'Y': np.random.rand(100).astype(np.float64)
}
self.attrs = {'axis': 0}
self.outputs = {
'Out': self.inputs['X'] - self.inputs['Y'].reshape(2, 1, 1)
'Out': self.inputs['X'] - self.inputs['Y'].reshape(100, 1, 1)
}
@ -80,13 +82,13 @@ class TestElementwiseSubOp_broadcast_1(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 4).astype(np.float64),
'Y': np.random.rand(3).astype(np.float64)
'X': np.random.rand(2, 100, 3).astype(np.float64),
'Y': np.random.rand(100).astype(np.float64)
}
self.attrs = {'axis': 1}
self.outputs = {
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 3, 1)
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 100, 1)
}
@ -94,12 +96,12 @@ class TestElementwiseSubOp_broadcast_2(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 4).astype(np.float64),
'Y': np.random.rand(4).astype(np.float64)
'X': np.random.rand(2, 3, 100).astype(np.float64),
'Y': np.random.rand(100).astype(np.float64)
}
self.outputs = {
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 1, 4)
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 1, 100)
}
@ -107,13 +109,13 @@ class TestElementwiseSubOp_broadcast_3(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 4, 5).astype(np.float64),
'Y': np.random.rand(3, 4).astype(np.float64)
'X': np.random.rand(2, 10, 12, 3).astype(np.float64),
'Y': np.random.rand(10, 12).astype(np.float64)
}
self.attrs = {'axis': 1}
self.outputs = {
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 3, 4, 1)
'Out': self.inputs['X'] - self.inputs['Y'].reshape(1, 10, 12, 1)
}
@ -121,8 +123,8 @@ class TestElementwiseSubOp_broadcast_4(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 4, 5).astype(np.float64),
'Y': np.random.rand(2, 3, 1, 5).astype(np.float64)
'X': np.random.rand(2, 5, 3, 12).astype(np.float64),
'Y': np.random.rand(2, 5, 1, 12).astype(np.float64)
}
self.outputs = {'Out': self.inputs['X'] - self.inputs['Y']}
@ -131,8 +133,8 @@ class TestElementwiseSubOp_commonuse_1(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 4).astype(np.float64),
'Y': np.random.rand(1, 1, 4).astype(np.float64)
'X': np.random.rand(2, 3, 100).astype(np.float64),
'Y': np.random.rand(1, 1, 100).astype(np.float64)
}
self.outputs = {'Out': self.inputs['X'] - self.inputs['Y']}
@ -141,8 +143,8 @@ class TestElementwiseSubOp_commonuse_2(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(2, 3, 1, 5).astype(np.float64),
'Y': np.random.rand(2, 1, 4, 1).astype(np.float64)
'X': np.random.rand(10, 3, 1, 4).astype(np.float64),
'Y': np.random.rand(10, 1, 12, 1).astype(np.float64)
}
self.outputs = {'Out': self.inputs['X'] - self.inputs['Y']}
@ -151,14 +153,14 @@ class TestElementwiseSubOp_xsize_lessthan_ysize(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_sub"
self.inputs = {
'X': np.random.rand(4, 5).astype(np.float64),
'Y': np.random.rand(2, 3, 4, 5).astype(np.float64)
'X': np.random.rand(10, 12).astype(np.float64),
'Y': np.random.rand(2, 3, 10, 12).astype(np.float64)
}
self.attrs = {'axis': 2}
self.outputs = {
'Out': self.inputs['X'].reshape(1, 1, 4, 5) - self.inputs['Y']
'Out': self.inputs['X'].reshape(1, 1, 10, 12) - self.inputs['Y']
}

@ -12,21 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
NOT_CHECK_OP_LIST = [
# The increment's input must be 1-d and only has one data
'increment',
# elementwise ops have cases(y_shape: (1) or (1,1)) to test broadcast
'elementwise_add',
'elementwise_sub',
NEED_TO_FIX_OP_LIST = [
'elementwise_mul',
'elementwise_div',
'elementwise_max',
'elementwise_min',
'elementwise_pow',
'fused_elemwise_activation',
]
NEED_TO_FIX_OP_LIST = [
'bilinear_tensor_product',
'conv2d_transpose',
'deformable_conv',

Loading…
Cancel
Save