o
    "Õj¨
  ã                   @   s,   d dl mZ d dlmZ G dd„ deƒZdS )é    )Ú
functional)ÚLayerc                       s2   e Zd ZdZd‡ fdd„	Zdd„ Zd	d
„ Z‡  ZS )ÚFusedDropoutAddaª  
    Fused Dropout and Add.

    Parameters:
        p (float|int, optional): Probability of setting units to zero. Default: 0.5
        mode(str, optional): ['upscale_in_train'(default) | 'downscale_in_infer']

                               1. upscale_in_train (default), upscale the output at training time

                                  - train: :math:`out = x \times \frac{mask}{(1.0 - p)} + y`
                                  - inference: :math:`out = x + y`

                               2. downscale_in_infer, downscale the output at inference

                                  - train: :math:`out = x \times mask + y`
                                  - inference: :math:`out = x \times (1.0 - p) + y`
        name (str, optional): Name for the operation, Default: None. For more information, please refer to :ref:`api_guide_Name`.

    Shape:
        - x: N-D tensor.
        - y: N-D tensor.
        - output: N-D tensor, the same shape as x.


    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:GPU)
            >>> import paddle
            >>> paddle.device.set_device('gpu')
            >>> from paddle.incubate.nn.layer.fused_dropout_add import FusedDropoutAdd

            >>> x = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32")
            >>> y = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32")

            >>> m = FusedDropoutAdd(p=0.5)

            >>> out = m(x, y)
    ç      à?Úupscale_in_trainNc                    s    t ƒ  ¡  || _|| _|| _d S )N)ÚsuperÚ__init__ÚpÚmodeÚname)Úselfr	   r
   r   ©Ú	__class__© úk/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/incubate/nn/layer/fused_dropout_add.pyr   <   s   

zFusedDropoutAdd.__init__c                 C   s"   t j||| j| j| j| jd}|S )N)r	   Útrainingr
   r   )ÚFZfused_dropout_addr	   r   r
   r   )r   ÚxÚyÚoutr   r   r   ÚforwardB   s   úzFusedDropoutAdd.forwardc                 C   s.   | j r	d| j › nd}d| j› d| j› |› S )Nz, name=Ú zp=z, mode=)r   r	   r
   )r   Zname_strr   r   r   Ú
extra_reprM   s   zFusedDropoutAdd.extra_repr)r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__classcell__r   r   r   r   r      s
    (r   N)Zpaddle.incubate.nnr   r   Z	paddle.nnr   r   r   r   r   r   Ú<module>   s   