o
    i                     @   st   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
dZ
dS )    )Mapping)OptionalN)silu_and_mul_kernelxx_scaleo_scaledtypereturnc                    s   | j \ }|d dksJ |d |p| j}tj f|| jd}dtttf dtttf f fdd}t	| ||
d|| | 
d|d|d	u|d	ud

 |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                    s    t | d fS )N
BLOCK_SIZE)tritoncdiv)r   bd R/home/ubuntu/vllm_env/lib/python3.10/site-packages/flashinfer/triton/activation.pygrid)   s   zsilu_and_mul.<locals>.gridi   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   r   silu_and_mul
   s&   

(r(   )NNN)collections.abcr   typingr   r   r   $flashinfer.triton.kernels.activationr   Tensorr   r(   r   r   r   r   <module>   s&    