o
    àÙ·iu  ã                   @   sv   d dl Z d dlmZ zd dlmZ d dlmZ W n ey#   edƒ‚w dgZG dd„ de j	j
ƒZG dd	„ d	eƒZdS )
é    N)ÚOptional)ÚTemplatedRingAttention)ÚParallelConfigz®Context parallelism requires the 'diffusers>=0.36.dev0'.Please install latest version of diffusers from source: 
pip3 install git+https://github.com/huggingface/diffusers.gitÚUnifiedTemplatedRingAttentionc                   @   sd   e Zd Ze	ddejjjdejdejdejde	ej de
ded	e	e
 d
edede	d fdd„ƒZdS )r   NÚctxÚqueryÚkeyÚvalueÚ	attn_maskÚ	dropout_pÚ	is_causalÚscaleÚ
enable_gqaÚ
return_lseÚ_parallel_configr   c                 C   s    t  |||||||||	|
||¡S ©N)Ú_TemplatedRingAttentionÚapply)r   r   r   r	   r
   r   r   r   r   r   Ú
forward_opÚbackward_opr   © r   úc/home/ubuntu/.local/lib/python3.10/site-packages/cache_dit/parallelism/attention/_templated_ring.pyÚforward   s   ôz%UnifiedTemplatedRingAttention.forwardr   )Ú__name__Ú
__module__Ú__qualname__ÚstaticmethodÚtorchÚautogradÚfunctionÚFunctionCtxÚTensorr   ÚfloatÚboolr   r   r   r   r   r      s4    óÿþýüûúùø	÷
öóc                   @   s   e Zd ZdZdS )r   zFA wrapper of diffusers' TemplatedRingAttention to avoid name conflict.N)r   r   r   Ú__doc__r   r   r   r   r   5   s    r   )r   Útypingr   Ú#diffusers.models.attention_dispatchr   Ú#diffusers.models._modeling_parallelr   ÚImportErrorÚ__all__r   ÚFunctionr   r   r   r   r   r   Ú<module>   s   ÿÿ!