o
    ÔÙ¾i¥  ã                   @   sV   d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 e  
e¡ZG dd„ deƒZdS )é    N)Úfx)ÚFixFunctionalizationPass)ÚCustomGraphPassÚInductorPassÚSGLangInductorPassÚget_pass_contextc                   @   sF   e Zd ZdZdd„ Zdejfdd„Zdd„ Zd	e	fd
d„Z
dd„ ZdS )ÚPostGradPassManagera$  
    The pass manager for post-grad passes.
    It handles configuration, adding custom passes, and running passes.
    It supports uuid for the Inductor code cache. That includes torch<2.6
    support using pickling (in .inductor_pass.CustomGraphPass).

    The order of the post-grad post-passes is:
    1. passes (constructor parameter)
    2. default passes (NoopEliminationPass, FusionPass)
    3. config["post_grad_custom_post_pass"] (if it exists)
    4. fix_functionalization
    This way, all passes operate on a functionalized graph.
    c                 C   s
   g | _ d S ©N)Úpasses©Úself© r   úW/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/compilation/pass_manager.pyÚ__init__!   s   
zPostGradPassManager.__init__Úgraphc                 C   s4   t ƒ j}| jD ]}| |¡r||ƒ q|  |¡ d S r	   )r   Úruntime_shaper
   Úis_applicable_for_shapeÚfix_functionalization)r   r   ÚshapeÚpass_r   r   r   Ú__call__$   s   

€zPostGradPassManager.__call__c                 C   s   t ƒ | _tƒ | _d S r	   )ÚdictÚpass_configr   r   r   r   r   r   Ú	configure-   s   zPostGradPassManager.configurer   c                 C   s   t |tƒsJ ‚| j |¡ d S r	   )Ú
isinstancer   r
   Úappend)r   r   r   r   r   Úadd3   s   zPostGradPassManager.addc                 C   sJ   d}|g dœ}| j D ]}|d  | ¡ ¡ q
|d  | j ¡ ¡ t |¡S )zí
        The PostGradPassManager is set as a custom pass in the Inductor and
        affects compilation caching. Its uuid depends on the UUIDs of all
        dependent passes and the pass config. See InductorPass for more info.
        Ú	fshdakhsa)r   r
   r
   )r
   r   Úuuidr   r   Ú	hash_dict)r   Úpass_manager_uuidÚstater   r   r   r   r   7   s   


zPostGradPassManager.uuidN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚGraphr   r   r   r   r   r   r   r   r   r      s    	r   )ÚloggingÚtorchr   Ú,sglang.srt.compilation.fix_functionalizationr   Ú$sglang.srt.compilation.inductor_passr   r   r   r   Ú	getLoggerr"   Úloggerr   r   r   r   r   Ú<module>   s   
