
    )`i                         d dl mZ d dlmZ d dlZd dlZd dlmZ 	 	 	 ddej        deej                 deej                 deej	                 d	ej        f
d
Z
dS )    )Mapping)OptionalN)silu_and_mul_kernelxx_scaleo_scaledtypereturnc                   	 | j         \  }|dz  dk    sJ |dz  	|p| j        }t          j        	f|| j                  }dt
          t          t          f         dt          t          t          f         f	fd}t          |         ||
                    d          || | 
                    d          |	d|du|du	
  
         |S )
a  Sigmoid Linear Unit and Multiplication

    Computes `silu(x[:,:d]) * x[:, d:]`, where `d = x.shape[-1] // 2.

    If the scale of `x` is `x_scale`, the scale applied to the output
    is the square of that, as the sigmoid function ranges in (0, 1).

    Args:
        x: The input tensor, of shape `(b, 2 * d)`.
        x_scale: An optional scale which was applied to `x`.
        o_scale: The scale to apply to the output.
        dtype: The desired output dtype.

    Returns:
        The output activation, of shape `(b, d)`.
       r   )r	   devicemetar
   c                 >    t          j        | d                   fS )N
BLOCK_SIZE)tritoncdiv)r   bds    p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/triton/activation.pygridzsilu_and_mul.<locals>.grid)   s    6;q$|"45566    i   N)
o_ptro_strideo_scale_ptrx_ptrx_stridex_scale_ptrr   r   HAS_X_SCALEHAS_O_SCALE)shaper	   torchemptyr   r   strinttupler   stride)
r   r   r   r	   no_dtypeor   r   r   s
           @@r   silu_and_mulr*   
   s    . 7DAqq5A::::	QAqwGQF'!(;;;A7738$ 7sCx 7 7 7 7 7 7 7 !!
4'4'    Hr   )NNN)collections.abcr   typingr   r!   r   $flashinfer.triton.kernels.activationr   Tensorr	   r*    r   r   <module>r0      s    # # # # # #         D D D D D D
 '+&*#'	/ /|/el#/ el#/ EK 	/
 \/ / / / / /r   