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

clean elem_arithmetic part4 unittest (#48465)

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