parameters: (function=None, input_spec=None, build_strategy=None)
return_statement: return decorated
docstring: Converts imperative dygraph APIs into declarative function APIs. Decorator
      @declarative handles the Program and Executor of static mode and returns
      the result as dygraph Tensor(s). Users could use the returned dygraph
      Tensor(s) to do imperative training, inference, or other operations. If the
      decorated function calls other imperative function, the called one will be
      converted into declarative function as well.
  
      Args:
          function (callable): callable imperative function.
          input_spec(list[InputSpec]|tuple[InputSpec]): list/tuple of InputSpec to specific the shape/dtype/name
              information of each input Tensor.
          build_strategy(BuildStrategy|None): This argument is used to compile the
              converted program with the specified options, such as operators' fusion
              in the computational graph and memory optimization during the execution
              of the computational graph. For more information about build_strategy,
              please refer to :code:`paddle.static.BuildStrategy`. The default is None.
  
  
      Returns:
          Tensor(s): containing the numerical result.
  
      Examples:
          .. code-block:: python
  
              import paddle
              from paddle.jit import to_static
  
              @to_static
              def func(x):
                  if paddle.mean(x) < 0:
                      x_v = x - 1
                  else:
                      x_v = x + 1
                  return x_v
  
              x = paddle.ones([1, 2], dtype='float32')
              x_v = func(x)
              print(x_v) # [[2. 2.]]
docstring_summary: Converts imperative dygraph APIs into declarative function APIs. Decorator
      @declarative handles the Program and Executor of static mode and returns
      the result as dygraph Tensor(s). Users could use the returned dygraph
      Tensor(s) to do imperative training, inference, or other operations. If the
      decorated function calls other imperative function, the called one will be
      converted into declarative function as well.
docstring_tokens: Converts imperative dygraph APIs into declarative function APIs . Decorator @declarative handles the Program and Executor of static mode and returns the result as dygraph Tensor ( s ) . Users could use the returned dygraph Tensor ( s ) to do imperative training inference or other operations . If the decorated function calls other imperative function the called one will be converted into declarative function as well .
function: def declarative(function=None, input_spec=None, build_strategy=None):
      """
      Converts imperative dygraph APIs into declarative function APIs. Decorator
      @declarative handles the Program and Executor of static mode and returns
      the result as dygraph Tensor(s). Users could use the returned dygraph
      Tensor(s) to do imperative training, inference, or other operations. If the
      decorated function calls other imperative function, the called one will be
      converted into declarative function as well.
  
      Args:
          function (callable): callable imperative function.
          input_spec(list[InputSpec]|tuple[InputSpec]): list/tuple of InputSpec to specific the shape/dtype/name
              information of each input Tensor.
          build_strategy(BuildStrategy|None): This argument is used to compile the
              converted program with the specified options, such as operators' fusion
              in the computational graph and memory optimization during the execution
              of the computational graph. For more information about build_strategy,
              please refer to :code:`paddle.static.BuildStrategy`. The default is None.
  
  
      Returns:
          Tensor(s): containing the numerical result.
  
      Examples:
          .. code-block:: python
  
              import paddle
              from paddle.jit import to_static
  
              @to_static
              def func(x):
                  if paddle.mean(x) < 0:
                      x_v = x - 1
                  else:
                      x_v = x + 1
                  return x_v
  
              x = paddle.ones([1, 2], dtype='float32')
              x_v = func(x)
              print(x_v) # [[2. 2.]]
  
      """
  
      def decorated(python_func):
          """
          Decorates a python function into a StaticFunction object.
          """
          # Step 1. unwrap the function if it is already decorated.
          _, python_func = unwrap_decorators(python_func)
  
          # Step 2. copy some attributes from original python function.
          static_layer = copy_decorator_attrs(
              original_func=python_func,
              decorated_obj=StaticFunction(
                  function=python_func,
                  input_spec=input_spec,
                  build_strategy=build_strategy))
  
          return static_layer
  
      build_strategy = build_strategy or BuildStrategy()
      if not isinstance(build_strategy, BuildStrategy):
          raise TypeError(
              "Required type(build_strategy) shall be `paddle.static.BuildStrategy`, but received {}".
              format(type(build_strategy).__name__))
  
      # for usage: `declarative(foo, ...)`
      if function is not None:
          if isinstance(function, Layer):
              if isinstance(function.forward, StaticFunction):
                  class_name = function.__class__.__name__
                  logging_utils.warn(
                      "`{}.forward` has already been decorated somewhere. It will be redecorated to replace previous one.".
                      format(class_name))
              function.forward = decorated(function.forward)
              return function
          else:
              return decorated(function)
  
      # for usage: `@declarative`
      return decorated
function_tokens: def declarative ( function = None , input_spec = None , build_strategy = None ) : def decorated ( python_func ) : """
          Decorates a python function into a StaticFunction object.
          """ # Step 1. unwrap the function if it is already decorated. _ , python_func = unwrap_decorators ( python_func ) # Step 2. copy some attributes from original python function. static_layer = copy_decorator_attrs ( original_func = python_func , decorated_obj = StaticFunction ( function = python_func , input_spec = input_spec , build_strategy = build_strategy ) ) return static_layer build_strategy = build_strategy or BuildStrategy ( ) if not isinstance ( build_strategy , BuildStrategy ) : raise TypeError ( "Required type(build_strategy) shall be `paddle.static.BuildStrategy`, but received {}" . format ( type ( build_strategy ) . __name__ ) ) # for usage: `declarative(foo, ...)` if function is not None : if isinstance ( function , Layer ) : if isinstance ( function . forward , StaticFunction ) : class_name = function . __class__ . __name__ logging_utils . warn ( "`{}.forward` has already been decorated somewhere. It will be redecorated to replace previous one." . format ( class_name ) ) function . forward = decorated ( function . forward ) return function else : return decorated ( function ) # for usage: `@declarative` return decorated