o
    ٷil
                     @  sr   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ eeZdddZdS )    )annotations)init_logger)NoParallelAttentionParallelAttentionStrategy)RingParallelAttention)UlyssesParallelAttention) get_sequence_parallel_world_sizeget_sp_group)get_forward_contextscatter_idxint
gather_idxuse_syncboolreturnr   c           	      C  s0  z	t  j}|j}W n ty& } ztd|  t W  Y d}~S d}~ww t|dd}t|dd}zt }t	 dkr@t W S W n, tym } z |dksQ|dkr`t
d| d| d| d	 t W  Y d}~S d}~ww |dkrtd
| d t|| ||dS |dkrtd| d t|dS t S )a&  Select a parallel attention strategy based on current diffusion config.

    Design principle:
    - Attention kernel backend selection remains in `attention/selector.py`.
    - Parallel attention selection is handled here, based on distributed config
      and initialized process groups.
    z>No forward context available for parallel attention strategy: Nulysses_degree   ring_degreezSP configured (ulysses=z, ring=z) but SP group not available: zH. Falling back to NoParallelAttention. This may cause incorrect results.z/Using UlyssesParallelAttention (ulysses_degree=))sp_groupr   r   r   z)Using RingParallelAttention (ring_degree=)r   )r
   omni_diffusion_configparallel_config	Exceptionloggerdebugr   getattrr	   r   warningr   r   )	r   r   r   cfgper   r   r    r    b/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/diffusion/attention/parallel/factory.py!build_parallel_attention_strategy   sJ   


r"   N)r   r   r   r   r   r   r   r   )
__future__r   vllm.loggerr   +vllm_omni.diffusion.attention.parallel.baser   r   +vllm_omni.diffusion.attention.parallel.ringr   .vllm_omni.diffusion.attention.parallel.ulyssesr   .vllm_omni.diffusion.distributed.parallel_stater   r	   #vllm_omni.diffusion.forward_contextr
   __name__r   r"   r    r    r    r!   <module>   s   