parameters: (input, label, reduction='mean', name=None)
docstring: r"""
      This operator computes the L1 Loss of Tensor ``input`` and ``label`` as follows.
  
      If `reduction` set to ``'none'``, the loss is:
  
      .. math::
          Out = \lvert input - label \rvert
  
      If `reduction` set to ``'mean'``, the loss is:
  
      .. math::
          Out = MEAN(\lvert input - label \rvert)
  
      If `reduction` set to ``'sum'``, the loss is:
  
      .. math::
          Out = SUM(\lvert input - label \rvert)
  
  
      Parameters:
          input (Tensor): The input tensor. The shapes is [N, `*`], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
          label (Tensor): label. The shapes is [N, `*`], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
          reduction (str, optional): Indicate the reduction to apply to the loss,
              the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
              If `reduction` is ``'none'``, the unreduced loss is returned;
              If `reduction` is ``'mean'``, the reduced mean loss is returned.
              If `reduction` is ``'sum'``, the reduced sum loss is returned.
              Default is ``'mean'``.
          name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
  
      Returns:
          Tensor, the L1 Loss of Tensor ``input`` and ``label``.
              If `reduction` is ``'none'``, the shape of output loss is [N, *], the same as ``input`` .
              If `reduction` is ``'mean'`` or ``'sum'``, the shape of output loss is [1].
  
      Examples:
          .. code-block:: python
  
              import paddle
  
              input = paddle.to_tensor([[1.5, 0.8], [0.2, 1.3]])
              label = paddle.to_tensor([[1.7, 1], [0.4, 0.5]])
  
              l1_loss = paddle.nn.functional.l1_loss(input, label)
              print(l1_loss.numpy())
              # [0.35]
  
              l1_loss = paddle.nn.functional.l1_loss(input, label, reduction='none')
              print(l1_loss.numpy())
              # [[0.20000005 0.19999999]
              # [0.2        0.79999995]]
  
              l1_loss = paddle.nn.functional.l1_loss(input, label, reduction='sum')
              print(l1_loss.numpy())
              # [1.4]
docstring_summary: r"""
      This operator computes the L1 Loss of Tensor ``input`` and ``label`` as follows.
docstring_tokens: r This operator computes the L1 Loss of Tensor input and label as follows .
function: def l1_loss(input, label, reduction='mean', name=None):
      r"""
      This operator computes the L1 Loss of Tensor ``input`` and ``label`` as follows.
  
      If `reduction` set to ``'none'``, the loss is:
  
      .. math::
          Out = \lvert input - label \rvert
  
      If `reduction` set to ``'mean'``, the loss is:
  
      .. math::
          Out = MEAN(\lvert input - label \rvert)
  
      If `reduction` set to ``'sum'``, the loss is:
  
      .. math::
          Out = SUM(\lvert input - label \rvert)
  
  
      Parameters:
          input (Tensor): The input tensor. The shapes is [N, `*`], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
          label (Tensor): label. The shapes is [N, `*`], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
          reduction (str, optional): Indicate the reduction to apply to the loss,
              the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
              If `reduction` is ``'none'``, the unreduced loss is returned;
              If `reduction` is ``'mean'``, the reduced mean loss is returned.
              If `reduction` is ``'sum'``, the reduced sum loss is returned.
              Default is ``'mean'``.
          name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
  
      Returns:
          Tensor, the L1 Loss of Tensor ``input`` and ``label``.
              If `reduction` is ``'none'``, the shape of output loss is [N, *], the same as ``input`` .
              If `reduction` is ``'mean'`` or ``'sum'``, the shape of output loss is [1].
  
      Examples:
          .. code-block:: python
  
              import paddle
  
              input = paddle.to_tensor([[1.5, 0.8], [0.2, 1.3]])
              label = paddle.to_tensor([[1.7, 1], [0.4, 0.5]])
  
              l1_loss = paddle.nn.functional.l1_loss(input, label)
              print(l1_loss.numpy())
              # [0.35]
  
              l1_loss = paddle.nn.functional.l1_loss(input, label, reduction='none')
              print(l1_loss.numpy())
              # [[0.20000005 0.19999999]
              # [0.2        0.79999995]]
  
              l1_loss = paddle.nn.functional.l1_loss(input, label, reduction='sum')
              print(l1_loss.numpy())
              # [1.4]
      """
      if reduction not in ['sum', 'mean', 'none']:
          raise ValueError(
              "The value of 'reduction' in L1Loss should be 'sum', 'mean' or 'none', but "
              "received %s, which is not allowed." % reduction)
  
      if in_dygraph_mode():
          unreduced = _elementwise_op_in_dygraph(
              input, label, axis=-1, act='abs', op_name='elementwise_sub')
          if reduction == 'mean':
              return _C_ops.mean(unreduced)
          elif reduction == 'sum':
              return _C_ops.reduce_sum(unreduced, 'dim', [0], 'keep_dim', False,
                                       'reduce_all', True)
          else:
              return unreduced
  
      fluid.data_feeder.check_variable_and_dtype(
          input, 'input', ['float32', 'float64', 'int32', 'int64'], 'l1_loss')
      fluid.data_feeder.check_variable_and_dtype(
          label, 'label', ['float32', 'float64', 'int32', 'int64'], 'l1_loss')
  
      if reduction == 'sum':
          unreduced = paddle.fluid.layers.elementwise_sub(input, label, act='abs')
          return paddle.sum(unreduced, name=name)
      elif reduction == 'mean':
          unreduced = paddle.fluid.layers.elementwise_sub(input, label, act='abs')
          return paddle.mean(unreduced, name=name)
      else:
          return paddle.fluid.layers.elementwise_sub(
              input, label, act='abs', name=name)
function_tokens: def l1_loss ( input , label , reduction = 'mean' , name = None ) : if reduction not in [ 'sum' , 'mean' , 'none' ] : raise ValueError ( "The value of 'reduction' in L1Loss should be 'sum', 'mean' or 'none', but " "received %s, which is not allowed." % reduction ) if in_dygraph_mode ( ) : unreduced = _elementwise_op_in_dygraph ( input , label , axis = - 1 , act = 'abs' , op_name = 'elementwise_sub' ) if reduction == 'mean' : return _C_ops . mean ( unreduced ) elif reduction == 'sum' : return _C_ops . reduce_sum ( unreduced , 'dim' , [ 0 ] , 'keep_dim' , False , 'reduce_all' , True ) else : return unreduced fluid . data_feeder . check_variable_and_dtype ( input , 'input' , [ 'float32' , 'float64' , 'int32' , 'int64' ] , 'l1_loss' ) fluid . data_feeder . check_variable_and_dtype ( label , 'label' , [ 'float32' , 'float64' , 'int32' , 'int64' ] , 'l1_loss' ) if reduction == 'sum' : unreduced = paddle . fluid . layers . elementwise_sub ( input , label , act = 'abs' ) return paddle . sum ( unreduced , name = name ) elif reduction == 'mean' : unreduced = paddle . fluid . layers . elementwise_sub ( input , label , act = 'abs' ) return paddle . mean ( unreduced , name = name ) else : return paddle . fluid . layers . elementwise_sub ( input , label , act = 'abs' , name = name )