
    -`i	                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZmZmZmZ d dlZd dlmZ d dlmZmZ d dlmZ erd d	lmZ  ed
          rd dlmZ nddlmZ dgZda ed          Z  ed          Z! G d d          Z"d dZ#ed!d            Z$ G d de          Z% G d de%          Z&d"dZ'dS )#    )annotationsN)Callable	Generator)contextmanager)TYPE_CHECKINGAny	ParamSpecTypeVar)fx)FakeTensorModeunset_fake_temporarily)is_torch_equal_or_newer)Rangez2.6)CustomGraphPass   )Torch25CustomGraphPassr   PRc                      e Zd ZddZdS )PassContextcompile_ranger   c                    || _         d S N)r   selfr   s     r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/compilation/inductor_pass.py__init__zPassContext.__init__)   s    $1    N)r   r   )__name__
__module____qualname__r    r   r   r   r   (   s(        2 2 2 2 2 2r   r   returnc                 "    t           J t           S )zGet the current pass context.)_pass_contextr"   r   r   get_pass_contextr&   -   s    $$$r   r   r   Generator[None, None, None]c              #  R   K   t           }t          |           a 	 dV  |a dS # |a w xY w)zmA context manager that stores the current pass context,
    usually it is a list of sizes to specialize.
    N)r%   r   )r   prev_contexts     r   pass_contextr*   3   sB       !L..M%$$$$$s   " &c                  R    e Zd ZdZddZedd            Zedd
            ZddZdS )InductorPassz
    A custom graph pass that uses a hash of its source as the UUID.
    This is defined as a convenience and should work in most cases.
    r#   strc                6    t                               |           S )z
        Provide a unique identifier for the pass, used in Inductor code cache.
        This should depend on the pass implementation, so that changes to the
        pass result in recompilation.
        By default, the object source is hashed.
        )r,   hash_sourcer   s    r   uuidzInductorPass.uuidG   s     ''---r   srcs	str | Anyc                 x   t          j                    }| D ]}t          |t                    r|}nOt          |t          j        t          f          rt          j        |          }nt          j        |j	                  }|
                    |                    d                     |                                S )z
        Utility method to hash the sources of functions or objects.
        :param srcs: strings or objects to add to the hash.
        Objects and functions have their source inspected.
        :return:
        utf-8)hashlibsha256
isinstancer-   typesFunctionTypetypeinspect	getsource	__class__updateencode	hexdigest)r2   hashersrcsrc_strs       r   r/   zInductorPass.hash_sourceP   s     !! 	3 	3C#s## ;C%"4d!;<< ;!+C00 "+CM::MM'..112222!!!r   dict_dict[Any, Any]c                    t          j        | d                              d          }t          j        |                                          S )z
        Utility method to hash a dictionary, can alternatively be used for uuid.
        :return: A sha256 hash of the json rep of the dictionary.
        T)	sort_keysr5   )jsondumpsr@   r6   r7   rA   )rE   encodeds     r   	hash_dictzInductorPass.hash_dictd   sB     *Ud333::7CC~g&&00222r   r   r   boolc                    dS )NTr"   r   s     r   is_applicable_for_rangez$InductorPass.is_applicable_for_rangem   s    tr   N)r#   r-   )r2   r3   r#   r-   )rE   rF   r#   r-   )r   r   r#   rM   )	r   r    r!   __doc__r1   staticmethodr/   rL   rO   r"   r   r   r,   r,   A   s         
. . . . " " " \"& 3 3 3 \3     r   r,   c                  .    e Zd ZdZ	 ddd	ZddZddZdS )CallableInductorPasszo
    This class is a wrapper for a callable that automatically provides an
    implementation of the UUID.
    NcallableCallable[[fx.Graph], None]r1   
Any | Noner#   Nonec                P    || _         ||                     |          n|| _        d S r   )rT   r/   _uuid)r   rT   r1   s      r   r   zCallableInductorPass.__init__w   s-     !37<T%%h///T


r   graphtorch.fx.Graphc                0    |                      |           d S r   )rT   )r   rZ   s     r   __call__zCallableInductorPass.__call__}   s    er   r   c                    | j         S r   )rY   r0   s    r   r1   zCallableInductorPass.uuid   s
    zr   r   )rT   rU   r1   rV   r#   rW   )rZ   r[   r#   rW   )r#   r   )r   r    r!   rP   r   r]   r1   r"   r   r   rS   rS   q   sk          HLJ J J J J        r   rS   fnCallable[P, R]c                H     t          j                   d fd            }|S )	z}
    Applies a FakeTensorMode context. This is useful when you don't want to
    create or run things with real tensors.
    argsP.argskwargsP.kwargsr#   r   c                    t           j                            d           5  t                      5  t	                      5   | i |}d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |S r   )torch_guardstracingr   r   )rb   rd   resultr_   s      r   fn_newz enable_fake_mode.<locals>.fn_new   sJ   ]""4(( 	) 	)*@*B*B 	) 	)NDTDT 	) 	)R(((F	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) sW   BA+	AA+AA+AA+B+A/	/B2A/	3BB	B)rb   rc   rd   re   r#   r   )	functoolswraps)r_   rk   s   ` r   enable_fake_modern      s?     _R      Mr   )r#   r   )r   r   r#   r'   )r_   r`   r#   r`   )(
__future__r   rl   r6   r<   rI   r9   collections.abcr   r   
contextlibr   typingr   r   r	   r
   rg   r   torch._subclasses.fake_tensorr   r   vllm.utils.torch_utilsr   vllm.config.utilsr   !torch._inductor.custom_graph_passr   torch25_custom_graph_passr   __all__r%   r   r   r   r&   r*   r,   rS   rn   r"   r   r   <module>ry      s4   # " " " " "         / / / / / / / / % % % % % % 9 9 9 9 9 9 9 9 9 9 9 9        P P P P P P P P : : : : : : (''''''5!! AAAAAAA     
 
IcNNGCLL2 2 2 2 2 2 2 2
    
% 
% 
% 
%- - - - -? - - -`    <   &     r   