o
    ٷi                     @  s   U d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ eG dd dZd	ad
ed< d!ddZd"ddZ							d#d$ddZed%ddZe							d#d$dd Zd	S )&    )annotations)contextmanager)	dataclass)
VllmConfig)AttentionMetadata)OmniDiffusionConfigc                   @  s|   e Zd ZU dZdZded< dZded< dZded< d	Zd
ed< dZ	ded< dZ
ded< dZded< edddZdd ZdS )ForwardContextz2
    set forward context for diffusion models
    NVllmConfig | Nonevllm_configOmniDiffusionConfig | Noneomni_diffusion_configHdict[str, AttentionMetadata] | list[dict[str, AttentionMetadata]] | Noneattn_metadataFboolsplit_text_embed_in_spr   intsp_padding_sizez
int | Nonesp_original_seq_len_sp_shard_depthreturnc                 C  s
   | j dkS )zIReturns True when inside an SP sharded region (between shard and gather).r   )r   self r   W/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/diffusion/forward_context.py	sp_active'   s   
zForwardContext.sp_activec                 C  s   d S Nr   r   r   r   r   __post_init__,   s   zForwardContext.__post_init__r   r   )__name__
__module____qualname____doc__r
   __annotations__r   r   r   r   r   r   propertyr   r   r   r   r   r   r      s   
 r   NForwardContext | None_forward_contextr   c                   C  s   t dusJ dt S )z Get the current forward context.NzXForward context is not set. Please use `set_forward_context` to set the forward context.r%   r   r   r   r   get_forward_context3   s   
r'   r   c                   C  s   t d uS r   r&   r   r   r   r   is_forward_context_available;   s   r(   Fr
   r	   r   r   r   r   r   c                 C  s   t | |||dS )Nr
   r   r   r   )r   r)   r   r   r   create_forward_context?   s   r*   forward_contextc                 c  s"    t }| a zdV  W |a dS |a w )zA context manager that overrides the current forward context.
    This is used to override the forward context for a specific
    forward pass.
    Nr&   )r+   prev_contextr   r   r   override_forward_contextM   s   r-   c              	   c  s    t | |||d}t|> | du rdV  n%ddlm} ||  dV  W d   n1 s.w   Y  W d   dS W d   dS W d   dS 1 sNw   Y  dS )zA context manager that stores the current forward context,
    can be attention metadata, split_text_embed_in_sp, etc.
    Here we can inject common logic for every model forward pass.
    r)   Nr   )set_current_vllm_config)r*   r-   vllm.config.vllmr.   )r
   r   r   r   r+   r.   r   r   r   set_forward_context\   s&   

"r0   )r   r   r   )NNNF)r
   r	   r   r   r   r   r   r   )r+   r$   )
__future__r   
contextlibr   dataclassesr   vllm.configr   /vllm_omni.diffusion.attention.backends.abstractr   vllm_omni.diffusion.datar   r   r%   r"   r'   r(   r*   r-   r0   r   r   r   r   <module>   s0    !

