o
    ۷i                     @   s   d dl mZmZ d dlmZ d dlmZmZ d dlZd dl	m
Z
 G dd deZeG dd	 d	Zed
edZG dd deee ZdS )    )ABCabstractmethod)	dataclass)GenericTypeVarN)current_omni_platformc                   @   s   e Zd ZU dZdZeed< edefddZe	e
defddZe	e
ded	 fd
dZe	e
ded fddZe	e
dd Ze	e
dee fddZededefddZdS )AttentionBackendz0Abstract class for diffusion attention backends.Faccept_output_bufferreturnc                 C   s   dS )NF )clsr   r   e/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm_omni/diffusion/attention/backends/abstract.pysupports_attention_mask   s   z(AttentionBackend.supports_attention_maskc                   C      t NNotImplementedErrorr   r   r   r   get_name      zAttentionBackend.get_nameAttentionImplc                   C   r   r   r   r   r   r   r   get_impl_cls   r   zAttentionBackend.get_impl_clsAttentionMetadatac                   C   r   r   r   r   r   r   r   get_metadata_cls    r   z!AttentionBackend.get_metadata_clsc                   C   r   r   r   r   r   r   r   get_builder_cls%   r   z AttentionBackend.get_builder_clsc                   C   r   )z6Get the list of supported head sizes for this backend.r   r   r   r   r   get_supported_head_sizes*   s   z)AttentionBackend.get_supported_head_sizes	head_sizec                 C   s   |   }| p
||v S r   )r   )r   r   supported_head_sizesr   r   r   supports_head_size0   s   z#AttentionBackend.supports_head_sizeN)__name__
__module____qualname____doc__r	   bool__annotations__classmethodr   staticmethodr   strr   typer   r   r   listintr   r   r   r   r   r   r      s,   
 r   c                   @   st   e Zd ZU dZejdB ed< dZejdB ed< dZejdB ed< dZ	ejdB ed< dZ
ejdB ed< dZeed< dS )	r   N	attn_maskjoint_attn_maskjoint_query	joint_keyjoint_valuefrontjoint_strategy)r   r   r    r*   torchTensorr#   r+   r,   r-   r.   r0   r&   r   r   r   r   r   6   s   
 r   T)boundc                   @   s(  e Zd Ze			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B d
e	j
f
ddZ	dde	j
de	j
de	j
dedB d
e	j
f
ddZ	dde	j
de	j
de	j
dedB d
e	j
f
ddZ	dde	j
de	j
de	j
dedB d
e	j
f
ddZ	dde	j
de	j
de	j
dedB d
e	j
f
ddZdS )r   FN 	num_headsr   softmax_scalecausalnum_kv_headsprefixr
   c                 K   r   r   r   )selfr6   r   r7   r8   r9   r:   extra_impl_argsr   r   r   __init__I   s   zAttentionImpl.__init__querykeyvalueattn_metadatac                 C   sn   t  r| ||||S t  r| ||||S t  r$| ||||S t  r0| ||||S t	dt  )z5Dispatch to platform-specific forward implementation.z(No forward implementation for platform: )
r   is_rocmforward_hipis_cudaforward_cudais_npuforward_npuis_xpuforward_xpur   r;   r>   r?   r@   rA   r   r   r   forwardV   s   zAttentionImpl.forwardc                 C   r   r   r   rJ   r   r   r   rE   i      zAttentionImpl.forward_cudac                 C   r   r   r   rJ   r   r   r   rG   r   rL   zAttentionImpl.forward_npuc                 C   r   r   r   rJ   r   r   r   rI   {   rL   zAttentionImpl.forward_xpuc                 C   s   |  ||||S r   )rE   rJ   r   r   r   rC      s   zAttentionImpl.forward_hip)FNr5   r   )r   r   r    r   r)   floatr"   r&   r=   r1   r2   r3   rK   rE   rG   rI   rC   r   r   r   r   r   H   s    	



r   )abcr   r   dataclassesr   typingr   r   r1   vllm_omni.platformsr   r   r   r3   r   r   r   r   r   <module>   s   )