o
    ٷi                     @   s   d dl Z d dlmZ d dlmZmZmZ eeZzd dl	m
Z
 W n ey.   ed ew G dd deZG dd	 d	eZdS )
    N)init_logger)AttentionBackendAttentionImplAttentionMetadata)sageattnzSageAttentionBackend is not available. You may install sage-attention by pip install git+https://github.com/thu-ml/SageAttention.gitc                   @   sX   e Zd ZU dZeed< edee fddZ	ede
fddZeded fd	d
ZdS )SageAttentionBackendTaccept_output_bufferreturnc                   C   s   g dS )N)    @   `                   r   r   r   d/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/diffusion/attention/backends/sage_attn.pyget_supported_head_sizes   s   z-SageAttentionBackend.get_supported_head_sizesc                   C   s   dS )N	SAGE_ATTNr   r   r   r   r   get_name"      zSageAttentionBackend.get_nameSageAttentionImplc                   C   s   t S N)r   r   r   r   r   get_impl_cls&   r   z!SageAttentionBackend.get_impl_clsN)__name__
__module____qualname__r   bool__annotations__staticmethodlistintr   strr   typer   r   r   r   r   r      s   
 r   c                   @   sh   e Zd Z			ddedededededB d	ed
dfddZ	ddej	dej	dej	de
d
ej	f
ddZdS )r   FN 	num_heads	head_sizesoftmax_scalecausalnum_kv_headsprefixr	   c                 K   s   || _ || _d S r   )r)   r(   )selfr&   r'   r(   r)   r*   r+   extra_impl_argsr   r   r   __init__,   s   

zSageAttentionImpl.__init__querykeyvalueattn_metadatac                 C   s   t |||d| j| jd}|S )NNHD)tensor_layout	is_causalsm_scale)r   r)   r(   )r,   r/   r0   r1   r2   outputr   r   r   forward_cuda9   s   zSageAttentionImpl.forward_cuda)FNr%   r   )r   r   r   r"   floatr   r#   r.   torchTensorr   r8   r   r   r   r   r   +   s>    	
r   )r:   vllm.loggerr   /vllm_omni.diffusion.attention.backends.abstractr   r   r   r   loggersageattentionr   ImportErrorwarningr   r   r   r   r   r   <module>   s   
