未验证 提交 dab1896d 编写于 作者: H HongyuJia 提交者: GitHub

clean elem_arithmetic part4 unittest (#48465)

上级 ab85f87a
......@@ -43,7 +43,7 @@ class TestBase(IPUOpTest):
name=self.feed_list[0], shape=self.feed_shape[0], dtype='float32'
)
x = paddle.assign(x)
out = paddle.fluid.layers.elementwise_add(x, x)
out = paddle.add(x, x)
self.fetch_list = [out.name]
def run_model(self, exec_mode):
......@@ -72,7 +72,7 @@ class TestAssignFp32Value(TestBase):
name=self.feed_list[0], shape=self.feed_shape[0], dtype='float32'
)
assign = paddle.assign(self.assign_fp32)
out = paddle.fluid.layers.elementwise_add(x, assign)
out = paddle.add(x, assign)
self.fetch_list = [out.name]
......
......@@ -51,7 +51,7 @@ class TestBase(IPUOpTest):
name=self.feed_list[0], shape=self.feed_shape[0], dtype='float32'
)
x = paddle.fluid.layers.dropout(x, **self.attrs)
out = paddle.fluid.layers.elementwise_add(x, x)
out = paddle.add(x, x)
self.fetch_list = [out.name]
def run_model(self, exec_mode):
......
......@@ -126,17 +126,17 @@ class TestMul(IPUOpTest):
class TestAdd(TestMul):
def set_test_op(self):
self.op = paddle.fluid.layers.elementwise_add
self.op = paddle.add
class TestSub(TestMul):
def set_test_op(self):
self.op = paddle.fluid.layers.elementwise_sub
self.op = paddle.subtract
class TestDiv(TestMul):
def set_test_op(self):
self.op = paddle.fluid.layers.elementwise_div
self.op = paddle.divide
class TestMin(TestMul):
......
......@@ -47,7 +47,7 @@ class TestBase(IPUOpTest):
name=self.feed_list[0], shape=self.feed_shape[0], dtype='float32'
)
x_fill = paddle.full_like(x, **self.attrs)
out = paddle.fluid.layers.elementwise_add(x_fill, x_fill)
out = paddle.add(x_fill, x_fill)
self.fetch_list = [out.name]
def run_model(self, exec_mode):
......@@ -71,7 +71,7 @@ class TestError(TestBase):
def build_model(self):
x = paddle.fluid.data('x', [-1, 3, 13], 'float32')
x_fill = paddle.full_like(x, **self.attrs)
out = paddle.fluid.layers.elementwise_add(x_fill, x_fill)
out = paddle.add(x_fill, x_fill)
self.fetch_list = [out.name]
def test(self):
......
......@@ -47,7 +47,7 @@ class TestBase(IPUOpTest):
@IPUOpTest.static_graph
def build_model(self):
x = paddle.fluid.layers.fill_constant(**self.attrs)
out = paddle.fluid.layers.elementwise_add(x, x)
out = paddle.add(x, x)
self.fetch_list = [out.name]
def run_model(self, exec_mode):
......
......@@ -50,7 +50,7 @@ class TestBase(IPUOpTest):
x = paddle.static.data(
name=self.feed_list[0], shape=self.feed_shape[0], dtype='float32'
)
add = paddle.fluid.layers.elementwise_add(x, x)
add = paddle.add(x, x)
out = paddle.reshape(add, **self.attrs)
self.fetch_list = [out.name]
......
......@@ -48,7 +48,7 @@ class TestBase(IPUOpTest):
self.main_prog.global_block().append_op(
type="share_data", inputs={"X": x}, outputs={'Out': y}
)
out = paddle.fluid.layers.elementwise_add(y, y)
out = paddle.add(y, y)
self.fetch_list = [out.name]
def run_model(self, exec_mode):
......@@ -82,7 +82,7 @@ class TestCase1(TestBase):
self.main_prog.global_block().append_op(
type="share_data", inputs={"X": x}, outputs={'Out': y}
)
out = paddle.fluid.layers.elementwise_add(x, y)
out = paddle.add(x, y)
self.fetch_list = [out.name]
......
......@@ -59,9 +59,9 @@ class TestBase(IPUOpTest):
shape=self.feed_shape[0],
dtype=self.feed_dtype[0],
)
add1 = paddle.fluid.layers.elementwise_add(x, x)
add1 = paddle.add(x, x)
reshape = paddle.reshape(add1, **self.attrs)
add2 = paddle.fluid.layers.elementwise_add(reshape, reshape)
add2 = paddle.add(reshape, reshape)
scale1 = paddle.scale(add2)
scale2 = paddle.scale(scale1, scale=1.3, bias=0.5)
scale3 = paddle.scale(scale2, scale=2, bias=0.7)
......
......@@ -230,9 +230,7 @@ class FlDNNLayer(nn.Layer):
with paddle.fluid.device_guard(
self.PART_B_JOINT_OP_DEVICE_FlAG
): # joint point
interactive = paddle.fluid.layers.elementwise_add(
bottom_a, bottom_b
)
interactive = paddle.add(bottom_a, bottom_b)
return interactive
def top_layer(self, interactive, label_input):
......
......@@ -121,7 +121,7 @@ def bottleneck_block(input, num_filters, stride, cardinality, reduction_ratio):
short = shortcut(input, num_filters * 2, stride)
return fluid.layers.elementwise_add(x=short, y=scale, act='relu')
return paddle.nn.functional.relu(paddle.add(x=short, y=scale))
img_shape = [3, 224, 224]
......
......@@ -95,7 +95,7 @@ class TestArgsortOpCPU(unittest.TestCase):
input=x, axis=self.axis, descending=self.descending
)
self.sorted_x.stop_gradient = False
loss = fluid.layers.elementwise_mul(self.sorted_x, label)
loss = paddle.multiply(self.sorted_x, label)
self.loss = paddle.sum(loss)
def forward(self):
......
......@@ -90,7 +90,7 @@ class TestAssignOpWithLoDTensorArray(unittest.TestCase):
y = fluid.layers.fill_constant(
shape=[100, 10], dtype='float32', value=1
)
z = fluid.layers.elementwise_add(x=x, y=y)
z = paddle.add(x=x, y=y)
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=0)
init_array = fluid.layers.array_write(x=z, i=i)
array = fluid.layers.assign(init_array)
......@@ -144,7 +144,7 @@ class TestAssignOApi(unittest.TestCase):
y = fluid.layers.fill_constant(
shape=[100, 10], dtype='float32', value=1
)
z = fluid.layers.elementwise_add(x=x, y=y)
z = paddle.add(x=x, y=y)
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=0)
init_array = fluid.layers.array_write(x=z, i=i)
array = paddle.assign(init_array)
......
......@@ -243,10 +243,8 @@ class SimpleNet(BackwardNet):
x3, size=[100, 64], param_attr=fluid.ParamAttr(name='w2v')
)
# merge layers
x_merge = fluid.layers.elementwise_add(x_emb, x2_emb, name='x_add_x2')
x2_merge = fluid.layers.elementwise_add(
x2_emb, x3_emb, name='x2_add_x3'
)
x_merge = paddle.add(x_emb, x2_emb, name='x_add_x2')
x2_merge = paddle.add(x2_emb, x3_emb, name='x2_add_x3')
# shared fc_w
predict = fluid.layers.fc(
input=x_merge,
......
......@@ -299,12 +299,12 @@ class TestMutiTask(unittest.TestCase):
adagrad = optimizer.Adagrad(learning_rate=0.001)
def fn_1():
sum = layers.elementwise_mul(x, y)
sum = paddle.multiply(x, y)
loss = paddle.mean(sum, name="f_1_loss")
adam.minimize(loss)
def fn_2():
sum = layers.elementwise_mul(x, y)
sum = paddle.multiply(x, y)
loss = paddle.mean(sum, name="f_2_loss")
adagrad.minimize(loss)
......
......@@ -33,7 +33,7 @@ class TestComplexVariable(unittest.TestCase):
with dg.guard():
x = dg.to_variable(a, "x")
y = dg.to_variable(b)
out = paddle.fluid.layers.elementwise_add(x, y)
out = paddle.add(x, y)
self.assertIsNotNone("{}".format(out))
np.testing.assert_allclose(out.numpy(), a + b, rtol=1e-05)
......
......@@ -310,15 +310,15 @@ class TestCondNestedControlFlow(unittest.TestCase):
def less_than_branch(i, a):
return layers.cond(
i >= 3.0,
lambda: layers.elementwise_add(a, a),
lambda: layers.elementwise_sub(a, a),
lambda: paddle.add(a, a),
lambda: paddle.subtract(a, a),
)
def greater_equal_branch(i, a):
return layers.cond(
i < 8.0,
lambda: layers.elementwise_mul(a, a),
lambda: layers.elementwise_div(a, a),
lambda: paddle.multiply(a, a),
lambda: paddle.divide(a, a),
)
main_program = Program()
......@@ -374,12 +374,12 @@ class TestCondNestedControlFlow(unittest.TestCase):
a < b,
lambda: fluid.layers.cond(
a - b < -1.0,
lambda: fluid.layers.elementwise_add(a, b),
lambda: fluid.layers.elementwise_mul(a, b),
lambda: paddle.add(a, b),
lambda: paddle.multiply(a, b),
),
lambda: fluid.layers.cond(
a == b,
lambda: fluid.layers.elementwise_sub(a, b),
lambda: paddle.subtract(a, b),
lambda: paddle.pow(a, b),
),
)
......
......@@ -1029,9 +1029,7 @@ class TestDataset2(unittest.TestCase):
name=slot, shape=[1], dtype="float32", lod_level=1
)
slots_vars.append(var)
fake_cost = fluid.layers.elementwise_sub(
slots_vars[0], slots_vars[-1]
)
fake_cost = paddle.subtract(slots_vars[0], slots_vars[-1])
fake_cost = paddle.mean(fake_cost)
with fluid.scope_guard(scope):
place = fluid.CPUPlace()
......@@ -1101,9 +1099,7 @@ class TestDataset2(unittest.TestCase):
name=slot, shape=[1], dtype="float32", lod_level=1
)
slots_vars.append(var)
fake_cost = fluid.layers.elementwise_sub(
slots_vars[0], slots_vars[-1]
)
fake_cost = paddle.subtract(slots_vars[0], slots_vars[-1])
fake_cost = paddle.mean(fake_cost)
with fluid.scope_guard(scope):
place = fluid.CPUPlace()
......@@ -1234,9 +1230,7 @@ class TestDataset2(unittest.TestCase):
name=slot, shape=[1], dtype="float32", lod_level=1
)
slots_vars.append(var)
fake_cost = fluid.layers.elementwise_sub(
slots_vars[0], slots_vars[-1]
)
fake_cost = paddle.subtract(slots_vars[0], slots_vars[-1])
fake_cost = paddle.mean(fake_cost)
with fluid.scope_guard(scope):
place = fluid.CPUPlace()
......
......@@ -75,7 +75,7 @@ class TestExecutorReturnTensorNotOverOverwritingWithLayers(unittest.TestCase):
def calc_add_out(self, place=None, parallel=None):
x = paddle.ones(shape=[3, 3], dtype='float32')
y = paddle.ones(shape=[3, 3], dtype='float32')
out = fluid.layers.elementwise_add(x=x, y=y)
out = paddle.add(x=x, y=y)
program = fluid.default_main_program()
if parallel:
program = fluid.CompiledProgram(program).with_data_parallel(
......@@ -88,7 +88,7 @@ class TestExecutorReturnTensorNotOverOverwritingWithLayers(unittest.TestCase):
def calc_sub_out(self, place=None, parallel=None):
x = paddle.ones(shape=[2, 2], dtype='float32')
y = paddle.ones(shape=[2, 2], dtype='float32')
out = fluid.layers.elementwise_sub(x=x, y=y)
out = paddle.subtract(x=x, y=y)
program = fluid.default_main_program()
if parallel:
program = fluid.CompiledProgram(program).with_data_parallel(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册