o
    پi	                     @  s   U d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlZer+d dlmZ dadadadd	 Zd
d Zdd Zedd Zedd Zed'ddZeG dd dZdaded< d(ddZed)d%d&ZdS )*    )annotations)contextmanager)	dataclass)TYPE_CHECKINGAnyListOptionalN)ForwardBatchFc                   C     t S N_in_piecewise_cuda_graph r   r   d/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/compilation/piecewise_context_manager.pyis_in_piecewise_cuda_graph      r   c                   C  r
   r   _in_pcg_torch_compiler   r   r   r   is_in_pcg_torch_compile   r   r   c                   C  r
   r   _pcg_capture_streamr   r   r   r   get_pcg_capture_stream   r   r   c                   c      da d V  da d S NTFr   r   r   r   r   #enable_piecewise_cuda_graph_compile      r   c                   c  r   r   r   r   r   r   r   enable_piecewise_cuda_graph%   s   r   streamtorch.cuda.Streamc                 c  s    | a d V  d a d S r   r   )r   r   r   r   set_pcg_capture_stream/   r   r   c                   @  sF   e Zd Zdd ZdddZdd	d
ZdddZdddZdddZdS )ForwardContextc                 C  s"   d | _ d | _d | _d | _d | _d S r   )forward_batchattention_layerquant_config
moe_layersmoe_fusions)selfr   r   r   __init__9   s
   
zForwardContext.__init__r!   r	   c                 C  
   || _ d S r   )r!   )r&   r!   r   r   r   set_forward_batch@      
z ForwardContext.set_forward_batchlayers	List[Any]c                 C  r(   r   )attention_layersr&   r+   r   r   r   set_attention_layersC   r*   z#ForwardContext.set_attention_layersr#   r   c                 C  r(   r   )r#   )r&   r#   r   r   r   set_quant_configF   r*   zForwardContext.set_quant_configc                 C  r(   r   )r$   r.   r   r   r   set_moe_layersI   r*   zForwardContext.set_moe_layersfusionsc                 C  r(   r   )r%   )r&   r2   r   r   r   set_moe_fusionsL   r*   zForwardContext.set_moe_fusionsN)r!   r	   )r+   r,   )r#   r   )r2   r,   )	__name__
__module____qualname__r'   r)   r/   r0   r1   r3   r   r   r   r   r    7   s    



r    Optional[ForwardContext]_forward_contextreturnc                   C  s   t d u rd S t S r   )r8   r   r   r   r   get_forward_contextS   s   r:   r!   r	   r-   r,   r#   r   r$   r%   c                 c  sR    t  at|  t| t| t| t| zd V  W d ad S d aw r   )r    r8   r)   r/   r0   r1   r3   )r!   r-   r#   r$   r%   r   r   r   set_forward_contextY   s   	




r;   )r   r   )r9   r7   )
r!   r	   r-   r,   r#   r   r$   r,   r%   r,   )
__future__r   
contextlibr   dataclassesr   typingr   r   r   r   torch,sglang.srt.model_executor.forward_batch_infor	   r   r   r   r   r   r   r   r   r   r    r8   __annotations__r:   r;   r   r   r   r   <module>   s2    

	
