From 3b7d9f7b833e29ce263a5d03e60359fdc438c453 Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Thu, 20 Sep 2018 20:37:23 +0800 Subject: [PATCH] remove kwargs of some activation api --- paddle/fluid/API.spec | 32 +++++++++---------- .../fluid/layers/layer_function_generator.py | 29 ++++++++++++++++- python/paddle/fluid/layers/ops.py | 30 ++++++++++------- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 1ce2cf83e8..de101be521 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -257,23 +257,23 @@ paddle.fluid.layers.sum ArgSpec(args=[], varargs='args', keywords='kwargs', defa paddle.fluid.layers.slice ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) paddle.fluid.layers.shape ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) paddle.fluid.layers.maxout ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.sigmoid ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.logsigmoid ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.exp ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.tanh ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.tanh_shrink ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) +paddle.fluid.layers.sigmoid ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.logsigmoid ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.exp ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.tanh ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.tanh_shrink ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) paddle.fluid.layers.softshrink ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.sqrt ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.abs ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.ceil ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.floor ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.cos ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.sin ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.round ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.reciprocal ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.square ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.softplus ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) -paddle.fluid.layers.softsign ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) +paddle.fluid.layers.sqrt ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.abs ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.ceil ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.floor ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.cos ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.sin ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.round ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.reciprocal ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.square ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.softplus ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) +paddle.fluid.layers.softsign ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None) paddle.fluid.layers.brelu ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) paddle.fluid.layers.leaky_relu ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) paddle.fluid.layers.soft_relu ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) diff --git a/python/paddle/fluid/layers/layer_function_generator.py b/python/paddle/fluid/layers/layer_function_generator.py index 8963d74de0..0f7a4a076a 100644 --- a/python/paddle/fluid/layers/layer_function_generator.py +++ b/python/paddle/fluid/layers/layer_function_generator.py @@ -23,7 +23,10 @@ from ..proto import framework_pb2 from ..framework import OpProtoHolder, Variable from ..layer_helper import LayerHelper -__all__ = ['deprecated', 'generate_layer_fn', 'autodoc', 'templatedoc'] +__all__ = [ + 'deprecated', 'generate_layer_fn', 'generate_layer_fn_noattr', 'autodoc', + 'templatedoc' +] def _convert_(name): @@ -205,6 +208,30 @@ def generate_layer_fn(op_type): return func +def generate_layer_fn_noattr(op_type): + """Register the Python layer for an Operator without Attribute. + + Args: + op_type: The name of the operator to be created. + + This function takes in the operator type (sigmoid, exp , tanh etc) and + creates the operator functionality. + + """ + op_proto = OpProtoHolder.instance().get_op_proto(op_type) + + def func(x): + helper = LayerHelper(op_type, **locals()) + output = helper.create_tmp_variable(dtype=helper.input_dtype()) + helper.append_op( + type=op_type, inputs={"X": [x]}, outputs={"Out": [output]}) + return output + + func.__name__ = op_type + func.__doc__ = _generate_doc_string_(op_proto) + return func + + def deprecated(func_or_class): """ Deprecated warning decorator. It will result a warning message. diff --git a/python/paddle/fluid/layers/ops.py b/python/paddle/fluid/layers/ops.py index 129252653d..85476312db 100644 --- a/python/paddle/fluid/layers/ops.py +++ b/python/paddle/fluid/layers/ops.py @@ -13,15 +13,27 @@ # limitations under the License. from __future__ import print_function -from .layer_function_generator import generate_layer_fn +from .layer_function_generator import generate_layer_fn, generate_layer_fn_noattr __activations__ = [ + 'softshrink', + 'brelu', + 'leaky_relu', + 'soft_relu', + 'elu', + 'relu6', + 'pow', + 'stanh', + 'hard_sigmoid', + 'swish', +] + +__activations_noattr__ = [ 'sigmoid', 'logsigmoid', 'exp', 'tanh', 'tanh_shrink', - 'softshrink', 'sqrt', 'abs', 'ceil', @@ -33,15 +45,6 @@ __activations__ = [ 'square', 'softplus', 'softsign', - 'brelu', - 'leaky_relu', - 'soft_relu', - 'elu', - 'relu6', - 'pow', - 'stanh', - 'hard_sigmoid', - 'swish', ] __all__ = [ @@ -75,6 +78,11 @@ __all__ = [ for _OP in set(__all__): globals()[_OP] = generate_layer_fn(_OP) +__all__ += __activations_noattr__ + +for _OP in set(__activations_noattr__): + globals()[_OP] = generate_layer_fn_noattr(_OP) + __all__ += ["uniform_random"] _uniform_random_ = generate_layer_fn('uniform_random') -- GitLab