
    x-j                        U d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ er9d dlmZmZmZ d dlmZ ed	         Zd
ed<   ed         Zd
ed<   eeef         Zd
ed<   dddZdS )    )annotations)TYPE_CHECKING)_C_ops)check_variable_and_dtype)LayerHelper)in_dynamic_or_pir_mode)Literal	TypeAliasUnion)Tensor)meansumnoner
   _ReduceModeStringLiteral)r         _ReduceModeNumberLiteral_ReduceModer   xr   	reductionreturnc                   t          |t                    r<dddd                    |                                          }|t	          d          t                      rt          j        | |          S t          | ddd	gd
           d|i}t          di t                      }|                    d          }|                    |          }|                    d
d| id|i|           |S )a  Marks a tensor as being part of the loss calculation for IPU.

    This operator is used to handle on the (final) loss of a model so that
    it is used as the start of backpropagation.

    When `reduction` is `none`, return raw `Out`.

    When `reduction` is `mean`, return

    .. math::
        Out = MEAN(Out)

    When `reduction` is `sum`, return

    .. math::
        Out = SUM(Out)

    Parameters:
        x (Variable): 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 on CPU and float16, float32 on IPU.
        reduction(str|int, optional): Reduce the loss output. Supported string values are: 'sum', 'mean', 'none'
                            the corresponding int values are 0, 1, 2 respectively. The default value is "none".

    Returns:
        Variable: The loss ``Tensor`` with the specified reduction applied.

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> paddle.enable_static()
            >>> loss = paddle.static.data(name="loss", shape=[-1, 1], dtype="float32")
            >>> out = paddle.incubate.identity_loss(loss, reduction=1)
    r   r   r   )r   r   r   NzUnsupported reduction type.r   float32float64identity_lossr   )input_param_nameXOut)typeinputsoutputsattrs)r   )
isinstancestrgetlower	TypeErrorr   r   r   r   r   localsinput_dtype"create_variable_for_type_inference	append_op)r   r   r"   helperdtypeouts         W/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/incubate/nn/loss.pyr   r   $   s   H )S!! ;q!44889J9JKK	9::: 2#Ay111Qi%;_MMM)$E55FHH55F44E

3
3E
:
:C
c1Xs|5     J    N)r   )r   r   r   r   r   r   )
__future__r   typingr   paddler   paddle.base.data_feederr   paddle.base.layer_helperr   paddle.frameworkr   r	   r
   r   r   r   __annotations__r   r   r    r0   r/   <module>r9      s'   # " " " " " "                   < < < < < < 0 0 0 0 0 0 3 3 3 3 3 3 	0000000000*12G*HHHHH*1'*:::::" "::K    
4 4 4 4 4 4 4r0   