未验证 提交 8045fcfd 编写于 作者: A Allen Guo 提交者: GitHub

add unary ops (#773) (#43363)

* add unary ops

* move to activation_ops
上级 6aee6410
......@@ -27,26 +27,98 @@ Node *activation_op_handler(Graph *graph, Node *node, const std::string &type) {
return new_node;
}
Node *relu_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_relu");
Node *abs_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_abs");
}
Node *tanh_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_tanh");
Node *acos_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_acos");
}
Node *asin_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_asin");
}
Node *atan_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_atan");
}
Node *ceil_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_ceil");
}
Node *cos_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_cos");
}
Node *cosh_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_cosh");
}
Node *erf_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_erf");
}
Node *exp_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_exp");
}
Node *floor_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_floor");
}
Node *log_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_log");
}
Node *reciprocal_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_reciprocal");
}
Node *relu_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_relu");
}
Node *round_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_round");
}
Node *sigmoid_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_sigmoid");
}
Node *sign_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_sign");
}
Node *sin_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_sin");
}
Node *sinh_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_sinh");
}
Node *softplus_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_softplus");
}
Node *softsign_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_softsign");
}
Node *sqrt_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_sqrt");
}
Node *tan_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_tan");
}
Node *tanh_handler(Graph *graph, Node *node) {
return activation_op_handler(graph, node, "popart_tanh");
}
Node *gelu_handler(Graph *graph, Node *node) {
auto *op = node->Op();
auto approximate_ = BOOST_GET_CONST(bool, op->GetAttr("approximate"));
......@@ -93,10 +165,28 @@ Node *log_softmax_handler(Graph *graph, Node *node) {
} // namespace platform
} // namespace paddle
REGISTER_HANDLER(relu, relu_handler);
REGISTER_HANDLER(tanh, tanh_handler);
REGISTER_HANDLER(abs, abs_handler);
REGISTER_HANDLER(acos, acos_handler);
REGISTER_HANDLER(asin, asin_handler);
REGISTER_HANDLER(atan, atan_handler);
REGISTER_HANDLER(ceil, ceil_handler);
REGISTER_HANDLER(cos, cos_handler);
REGISTER_HANDLER(cosh, cosh_handler);
REGISTER_HANDLER(erf, erf_handler);
REGISTER_HANDLER(exp, exp_handler);
REGISTER_HANDLER(floor, floor_handler);
REGISTER_HANDLER(log, log_handler);
REGISTER_HANDLER(reciprocal, reciprocal_handler);
REGISTER_HANDLER(relu, relu_handler);
REGISTER_HANDLER(round, round_handler);
REGISTER_HANDLER(sigmoid, sigmoid_handler);
REGISTER_HANDLER(sign, sign_handler);
REGISTER_HANDLER(sin, sin_handler);
REGISTER_HANDLER(sinh, sinh_handler);
REGISTER_HANDLER(softplus, softplus_handler);
REGISTER_HANDLER(softsign, softsign_handler);
REGISTER_HANDLER(sqrt, sqrt_handler);
REGISTER_HANDLER(tan, tan_handler);
REGISTER_HANDLER(tanh, tanh_handler);
REGISTER_HANDLER(gelu, gelu_handler);
REGISTER_HANDLER(log_softmax, log_softmax_handler);
......@@ -16,14 +16,13 @@ import unittest
import numpy as np
import paddle
import paddle.nn.functional as F
import paddle.static
from paddle.fluid.tests.unittests.ipu.op_test_ipu import IPUOpTest
@unittest.skipIf(not paddle.is_compiled_with_ipu(),
"core is not compiled with IPU")
class TestRelu(IPUOpTest):
class TestBase(IPUOpTest):
def setUp(self):
self.set_atol()
......@@ -33,7 +32,7 @@ class TestRelu(IPUOpTest):
self.set_feed_attr()
def set_test_op(self):
self.op = paddle.fluid.layers.relu
self.op = paddle.fluid.layers.abs
self.op_attrs = {}
def set_data_feed(self):
......@@ -64,33 +63,171 @@ class TestRelu(IPUOpTest):
self.check()
class TestTanh(TestRelu):
class TestAcos(TestBase):
@property
def fp16_enabled(self):
return False
def set_atol(self):
super().set_atol()
self.atol = 1e-6
def set_test_op(self):
self.op = paddle.fluid.layers.acos
self.op_attrs = {}
class TestAsin(TestAcos):
def set_test_op(self):
self.op = paddle.fluid.layers.asin
self.op_attrs = {}
class TestSinh(TestAcos):
def set_test_op(self):
self.op = paddle.fluid.layers.sinh
self.op_attrs = {}
class TestAtan(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.atan
self.op_attrs = {}
class TestCeil(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.ceil
self.op_attrs = {}
class TestCos(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.cos
self.op_attrs = {}
class TestCosh(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.cosh
self.op_attrs = {}
class TestErf(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.erf
self.op_attrs = {}
class TestExp(TestBase):
def set_test_op(self):
self.op = F.tanh
self.op = paddle.fluid.layers.exp
self.op_attrs = {}
class TestLog(TestRelu):
class TestFloor(TestBase):
@property
def fp16_enabled(self):
return False
def set_test_op(self):
self.op = paddle.fluid.layers.floor
self.op_attrs = {}
class TestLog(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.log
self.op_attrs = {}
class TestSigmoid(TestRelu):
class TestReciprocal(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.reciprocal
self.op_attrs = {}
class TestRelu(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.relu
self.op_attrs = {}
class TestRound(TestBase):
def set_test_op(self):
self.op = F.sigmoid
self.op = paddle.fluid.layers.round
self.op_attrs = {}
class TestSqrt(TestRelu):
class TestSigmoid(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.sigmoid
self.op_attrs = {}
class TestSign(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.sign
self.op_attrs = {}
class TestSin(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.sin
self.op_attrs = {}
class TestSoftplus(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.softplus
self.op_attrs = {}
class TestSoftsign(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.softsign
self.op_attrs = {}
class TestSqrt(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.sqrt
self.op_attrs = {}
class TestTan(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.tan
self.op_attrs = {}
class TestTanh(TestBase):
def set_test_op(self):
self.op = paddle.fluid.layers.tanh
self.op_attrs = {}
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册