o
    "j~                     @   sV   d dl mZ d dlmZ d dlmZ d dlmZ 	dddZdd	d
Z		dddZ
dS )    )_legacy_C_ops)LayerHelper)in_dynamic_mode)matmulNFc              	   C   sz   |du rt | ||||S t rt| ||d|d|S tdi t }|j| jd}|jd| ||dd|i||d	d
 |S )a  
    Applies matrix multiplication of two tensors and then bias addition if provided.
    This method requires CUDA version >= 11.6.

    Args:
        x (Tensor): the first input Tensor to be multiplied.
        y (Tensor): the second input Tensor to be multiplied. Its rank must be 2.
        bias (Tensor, optional): the input bias Tensor. If it is None, no bias addition would
            be performed. Otherwise, the bias is added to the matrix multiplication result. Default: None.
        transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default: False.
        transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default: False.
        name (str, optional): For detailed information, please refer to
            :ref:`api_guide_Name` . Usually name is no need to set and None by default.

    Returns:
        Tensor: the output Tensor.

    Examples:
        .. code-block:: python

            >>> # doctest: +SKIP('fused_gemm_epilogue is only supported when CUDA version >= 11.6')
            >>> # doctest: +REQUIRES(env:GPU)
            >>> import paddle
            >>> from paddle.incubate.nn.functional import fused_matmul_bias

            >>> paddle.set_device('gpu')
            >>> x = paddle.randn([3, 5])
            >>> y = paddle.randn([4, 5])
            >>> bias = paddle.randn([5])
            >>> out = fused_matmul_bias(x, y, bias)
            >>> print(out.shape)
            [3, 5]
    Ntrans_xtrans_yfused_matmul_biasdtypefused_gemm_epilogueXYZBiasOut)r   r   typeZinputsZoutputsattrsr   )	r   r   r   r   r   locals"create_variable_for_type_inferencer
   	append_op)xybiasZtranspose_xZtranspose_ynamehelperout r   p/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/incubate/nn/functional/fused_matmul_bias.pyr      s   $
r   c                 C   s   t | ||d||S )a?  
    Fully-connected linear transformation operator. This method requires CUDA version >= 11.6.

    Args:
        x (Tensor): the input Tensor to be multiplied.
        weight (Tensor): the weight Tensor to be multiplied. Its rank must be 2.
        bias (Tensor, optional): the input bias Tensor. If it is None, no bias addition would
            be performed. Otherwise, the bias is added to the matrix multiplication result. Default: None.
        transpose_weight (bool, optional): Whether to transpose :math:`weight` before multiplication. Default: False.
        name (str, optional): For detailed information, please refer to
            :ref:`api_guide_Name` . Usually name is no need to set and None by default.

    Returns:
        Tensor: the output Tensor.

    Examples:
        .. code-block:: python

            >>> # doctest: +SKIP('fused_gemm_epilogue is only supported when CUDA version >= 11.6')
            >>> # doctest: +REQUIRES(env:GPU)
            >>> import paddle
            >>> from paddle.incubate.nn.functional import fused_linear

            >>> paddle.set_device('gpu')
            >>> x = paddle.randn([3, 4])
            >>> weight = paddle.randn([4, 5])
            >>> bias = paddle.randn([5])
            >>> out = fused_linear(x, weight, bias)
            >>> print(out.shape)
            [3, 5]
    Fr   )r   weightr   Ztranspose_weightr   r   r   r   fused_linearK   s    r    c                 C   st   |du rd}t  rt| ||d|d|d|	S tdi t }|j| jd}|jd| ||d	d
|i|||dd |S )a  
    Fully-connected linear and activation transformation operator. This method requires CUDA version >= 11.6.

    Args:
        x (Tensor): the input Tensor to be multiplied.
        y (Tensor): the weight Tensor to be multiplied. Its rank must be 2.
        bias (Tensor): the input bias Tensor, the bias is added to the matrix multiplication result.
        trans_x (bool, optional): Whether to transpose :math:`x` before multiplication.
        trans_y (bool, optional): Whether to transpose :math:`y` before multiplication.
        activation (str, optional): Activation function, Currently, the available activation functions are
            limited to "gelu" (Gaussian Error Linear Unit) and "relu" (Rectified Linear Unit).
            These activation functions are applied to the output of the bias add. Default: None.

    Returns:
        Tensor: the output Tensor.

    Examples:
        .. code-block:: python

            >>> # doctest: +SKIP('fused_gemm_epilogue is only supported when CUDA version >= 11.6')
            >>> # doctest: +REQUIRES(env:GPU)
            >>> import paddle
            >>> from paddle.incubate.nn.functional import fused_linear_activation

            >>> paddle.set_device('gpu')
            >>> x = paddle.randn([3, 4])
            >>> weight = paddle.randn([4, 5])
            >>> bias = paddle.randn([5])
            >>> out = fused_linear_activation(x, weight, bias)
            >>> print(out.shape)
            [3, 5]
    Nnoner   r   
activationr   r	   r   r   r   )r   r   r"   r   r   )r   r   r   r   r   r   r
   r   )r   r   r   r   r   r"   r   r   r   r   r   fused_linear_activationn   s4   #
r#   )NFFN)NFN)FFN)Zpaddler   Zpaddle.base.layer_helperr   Zpaddle.frameworkr   Zpaddle.tensor.linalgr   r   r    r#   r   r   r   r   <module>   s   

6$