
    .`iJ7                        d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlZddlmZ ddlmZ  ee          Zd Zed	             Zd
edeej        z  fdZdedefdZed             Z G d d          Z G d de          Z G d de          Z G d de	          Zed
edefd            Z defdZ!defdZ"defdZ#defdZ$defdZ%defdZ&defd Z'defd!Z(defd"Z)dS )#zg
Contains helpers related to importing modules.

This is similar in concept to the `importlib` module.
    N)cache)
ModuleType)Any)Never)init_loggerc                      ddl mc m}  | S )a  
    Historical comments:

    libnvml.so is the library behind nvidia-smi, and
    pynvml is a Python wrapper around it. We use it to get GPU
    status without initializing CUDA context in the current process.
    Historically, there are two packages that provide pynvml:
    - `nvidia-ml-py` (https://pypi.org/project/nvidia-ml-py/): The official
        wrapper. It is a dependency of vLLM, and is installed when users
        install vLLM. It provides a Python module named `pynvml`.
    - `pynvml` (https://pypi.org/project/pynvml/): An unofficial wrapper.
        Prior to version 12.0, it also provides a Python module `pynvml`,
        and therefore conflicts with the official one. What's worse,
        the module is a Python package, and has higher priority than
        the official one which is a standalone Python file.
        This causes errors when both of them are installed.
        Starting from version 12.0, it migrates to a new module
        named `pynvml_utils` to avoid the conflict.
    It is so confusing that many packages in the community use the
    unofficial one by mistake, and we have to handle this case.
    For example, `nvcr.io/nvidia/pytorch:24.12-py3` uses the unofficial
    one, and it will cause errors, see the issue
    https://github.com/vllm-project/vllm/issues/12847 for example.
    After all the troubles, we decide to copy the official `pynvml`
    module to our codebase, and use it directly.
    r   N)vllm.third_party.pynvmlthird_partypynvml)r   s    k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/utils/import_utils.pyimport_pynvmlr      s$    6 -,,,,,,,,M    c                  J   t          d          r+ddl} t                              d| j         dd           dS t          d          r?ddlmc m}  t                              d| j         dd           | t          j        d<   dS t          	                    d	           dS )
z
    For convenience, prioritize triton_kernels that is available in
    `site-packages`. Use `vllm.third_party.triton_kernels` as a fall-back.
    triton_kernelsr   Nz#Loading module triton_kernels from .local)scopevllm.third_party.triton_kernelsztriton_kernels unavailable in this build. Please consider installing triton_kernels from https://github.com/triton-lang/triton/tree/main/python/triton_kernels)
_has_moduler   logger
debug_once__file__vllm.third_party.triton_kernelsr
   sysmodules	info_once)r   s    r   import_triton_kernelsr   :   s     #$$ 
L.2ILLL 	 	
 	
 	
 	
 	
 
6	7	7 
@@@@@@@@@L.2ILLL 	 	
 	
 	
 )7$%%%T	
 	
 	
 	
 	
r   module_name	file_pathc                    t           j                            | |          }|t          d|           |j        J t           j                            |          }|t          j        | <   |j                            |           |S )z
    Import a Python file according to its file path.

    Based on the official recipe:
    https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
    NzNo module named )		importlibutilspec_from_file_locationModuleNotFoundErrorloadermodule_from_specr   r   exec_module)r   r   specmodules       r   import_from_pathr*   W   s     >11+yIID|!"D["D"DEEE;"""^,,T22F%CKKF###Mr   qualnamereturnc                 |    |                      dd          \  }}t          j        |          }t          ||          S )z>
    Resolve an object by its fully-qualified class name.
    r      )rsplitr!   import_modulegetattr)r+   r   obj_namer)   s       r   resolve_obj_by_qualnamer3   j   s<     %OOC33K$[11F68$$$r   c                      t           j                            d          } |                     dg           |                     dg           }fd|D             S )NvllmzRequires-DistzProvides-Extrac                 0    i | ]fd D             S )c                 x    g | ]6}|                     d  d          t          j        d|          d         7S )z
extra == ""z
;|>=|<=|==r   )endswithresplit).0reqextras     r   
<listcomp>z=get_vllm_optional_dependencies.<locals>.<dictcomp>.<listcomp>z   sX     
 
 
||111122
H]C((+
 
 
r    )r<   r>   requirementss    @r   
<dictcomp>z2get_vllm_optional_dependencies.<locals>.<dictcomp>y   sR         	 
 
 
 
#
 
 
  r   )r!   metadataget_all)rC   extrasrA   s     @r   get_vllm_optional_dependenciesrF   s   sq    !**622H##OR88L.33F       r   c                      e Zd ZdZdedefdZdefdZdefdZ	defdZ
defd	Zdefd
ZdefdZd Zd ZdedefdZd ZdefdZdedefdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZd3dedefd Zdefd!Zdefd"Zdefd#Z defd$Z!defd%Z"d& Z#d' Z$d( Z%d) Z&d* Z'd3d+efd,Z(d- Z)d. Z*d/ Z+d0 Z,dedefd1Z-d2S )4_PlaceholderBasea]  
    Disallows downstream usage of placeholder modules.

    We need to explicitly override each dunder method because
    [`__getattr__`][vllm.utils.import_utils._PlaceholderBase.__getattr__]
    is not called when they are accessed.

    Info:
        [Special method lookup](https://docs.python.org/3/reference/datamodel.html#special-lookup)
    keyr,   c                     t           )z
        The main class should implement this to throw an error
        for attribute accesses representing downstream usage.
        )NotImplementedErrorselfrI   s     r   __getattr__z_PlaceholderBase.__getattr__   s
    
 "!r   otherc                 ,    |                      d          S )N__lt__rN   rM   rO   s     r   rQ   z_PlaceholderBase.__lt__       )))r   c                 ,    |                      d          S )N__le__rR   rS   s     r   rV   z_PlaceholderBase.__le__   rT   r   c                 ,    |                      d          S )N__eq__rR   rS   s     r   rX   z_PlaceholderBase.__eq__   rT   r   c                 ,    |                      d          S )N__ne__rR   rS   s     r   rZ   z_PlaceholderBase.__ne__   rT   r   c                 ,    |                      d          S )N__gt__rR   rS   s     r   r\   z_PlaceholderBase.__gt__   rT   r   c                 ,    |                      d          S )N__ge__rR   rS   s     r   r^   z_PlaceholderBase.__ge__   rT   r   c                 ,    |                      d          S )N__hash__rR   rM   s    r   r`   z_PlaceholderBase.__hash__       
+++r   c                 ,    |                      d          S )N__bool__rR   ra   s    r   rd   z_PlaceholderBase.__bool__   rb   r   argskwargsc                 ,    |                      d          S )N__call__rR   rM   re   rf   s      r   rh   z_PlaceholderBase.__call__   rb   r   c                 ,    |                      d          S )N__len__rR   ra   s    r   rk   z_PlaceholderBase.__len__       	***r   c                 ,    |                      d          S )N__getitem__rR   rL   s     r   rn   z_PlaceholderBase.__getitem__       ...r   valuec                 ,    |                      d          S )N__setitem__rR   )rM   rI   rp   s      r   rr   z_PlaceholderBase.__setitem__   ro   r   c                 ,    |                      d          S )N__delitem__rR   rL   s     r   rt   z_PlaceholderBase.__delitem__   ro   r   c                 ,    |                      d          S )N__add__rR   rS   s     r   rv   z_PlaceholderBase.__add__   rl   r   c                 ,    |                      d          S )N__sub__rR   rS   s     r   rx   z_PlaceholderBase.__sub__   rl   r   c                 ,    |                      d          S )N__mul__rR   rS   s     r   rz   z_PlaceholderBase.__mul__   rl   r   c                 ,    |                      d          S )N
__matmul__rR   rS   s     r   r|   z_PlaceholderBase.__matmul__       ---r   c                 ,    |                      d          S )N__truediv__rR   rS   s     r   r   z_PlaceholderBase.__truediv__   ro   r   c                 ,    |                      d          S )N__floordiv__rR   rS   s     r   r   z_PlaceholderBase.__floordiv__   s    ///r   c                 ,    |                      d          S )N__mod__rR   rS   s     r   r   z_PlaceholderBase.__mod__   rl   r   c                 ,    |                      d          S )N
__divmod__rR   rS   s     r   r   z_PlaceholderBase.__divmod__   r}   r   .moduloc                 ,    |                      d          S )N__pow__rR   )rM   rO   r   s      r   r   z_PlaceholderBase.__pow__   rl   r   c                 ,    |                      d          S )N
__lshift__rR   rS   s     r   r   z_PlaceholderBase.__lshift__   r}   r   c                 ,    |                      d          S )N
__rshift__rR   rS   s     r   r   z_PlaceholderBase.__rshift__   r}   r   c                 ,    |                      d          S )N__and__rR   rS   s     r   r   z_PlaceholderBase.__and__   rl   r   c                 ,    |                      d          S )N__xor__rR   rS   s     r   r   z_PlaceholderBase.__xor__   rl   r   c                 ,    |                      d          S )N__or__rR   rS   s     r   r   z_PlaceholderBase.__or__   rT   r   c                 ,    |                      d          S )N__neg__rR   ra   s    r   r   z_PlaceholderBase.__neg__   rl   r   c                 ,    |                      d          S )N__pos__rR   ra   s    r   r   z_PlaceholderBase.__pos__   rl   r   c                 ,    |                      d          S )N__abs__rR   ra   s    r   r   z_PlaceholderBase.__abs__   rl   r   c                 ,    |                      d          S )N
__invert__rR   ra   s    r   r   z_PlaceholderBase.__invert__  r}   r   c                 ,    |                      d          S )N	__index__rR   ra   s    r   r   z_PlaceholderBase.__index__      ,,,r   ndigitsc                 ,    |                      d          S )N	__round__rR   )rM   r   s     r   r   z_PlaceholderBase.__round__
  r   r   c                 ,    |                      d          S )N	__trunc__rR   ra   s    r   r   z_PlaceholderBase.__trunc__  r   r   c                 ,    |                      d          S )N	__floor__rR   ra   s    r   r   z_PlaceholderBase.__floor__  r   r   c                 ,    |                      d          S )N__ceil__rR   ra   s    r   r   z_PlaceholderBase.__ceil__  rb   r   c                 ,    |                      d          S )N	__enter__rR   ra   s    r   r   z_PlaceholderBase.__enter__  r   r   c                 ,    |                      d          S )N__exit__rR   ri   s      r   r   z_PlaceholderBase.__exit__  rb   r   N).).__name__
__module____qualname____doc__strr   rN   objectrQ   rV   rX   rZ   r\   r^   r`   rd   rh   rk   rn   rr   rt   rv   rx   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   r   r   rH   rH      s       	 	"s "u " " " "*F * * * **F * * * **F * * * **F * * * **F * * * **F * * * *, , ,, , ,
,f , , , , ,
+ + +/v / / / //v /f / / / //v / / / /+V + + + ++V + + + ++V + + + +. . . . ./ / / / /0& 0 0 0 0+V + + + +. . . . .+ +V +V + + + +. . . . .. . . . .+V + + + ++V + + + +*F * * * *+ + ++ + ++ + +. . .- - -- - - - - -- - -- - -, , ,
- - -,f , , , , , , ,r   rH   c                   H     e Zd ZdZdeddf fdZdefdZdedefd	Z xZ	S )
PlaceholderModulez
    A placeholder object to use when a module does not exist.

    This enables more informative errors when trying to access attributes
    of a module that does not exist.
    namer,   Nc                 V    t                                                       || _        d S N)super__init___PlaceholderModule__name)rM   r   	__class__s     r   r   zPlaceholderModule.__init__'  s&     r   	attr_pathc                 "    t          | |          S r   )_PlaceholderModuleAttrrM   r   s     r   placeholder_attrz"PlaceholderModule.placeholder_attr-  s    %dI666r   rI   c                    | j         }	 t          j        |           nW# t          $ rJ}t	                                                      D ]"\  }}||v rd| d| d}t          |          |#|d }~ww xY wt          d          )NzPlease install vllm[z] for z supportMPlaceholderModule should not be used when the original module can be imported)r   r!   r0   ImportErrorrF   itemsAssertionError)rM   rI   r   excr>   namesmsgs          r   rN   zPlaceholderModule.__getattr__0  s    {	#D)))) 	 	 	 > @ @ F F H H 4 4u5==MMMeMMMC%c**3 ! I	 7
 
 	
s    
A2AA--A2)
r   r   r   r   r   r   r   r   rN   __classcell__r   s   @r   r   r     s         S T      7# 7 7 7 7
s 
u 
 
 
 
 
 
 
 
r   r   c                   H     e Zd Zdededdf fdZdefdZdedefdZ xZ	S )	r   r)   r   r,   Nc                 d    t                                                       || _        || _        d S r   )r   r   _PlaceholderModuleAttr__module!_PlaceholderModuleAttr__attr_path)rM   r)   r   r   s      r   r   z_PlaceholderModuleAttr.__init__D  s0     $r   c                 @    t          | j        | j         d|           S )Nr   )r   r   r   r   s     r   r   z'_PlaceholderModuleAttr.placeholder_attrK  s%    %dm8H5V5V95V5VWWWr   rI   c                 ^    t          | j        | j         d|            t          d          )Nr   r   )r1   r   r   r   rL   s     r   rN   z"_PlaceholderModuleAttr.__getattr__N  s<    $"2::S::;;;7
 
 	
r   )
r   r   r   r   r   r   r   r   rN   r   r   s   @r   r   r   C  s        %0 %S %T % % % % % %X# X X X X
s 
u 
 
 
 
 
 
 
 
r   r   c                   t     e Zd ZdZdedeeef         def fdZdefdZ	dedefd	Z
dee         fd
Z xZS )
LazyLoadera  
    `LazyLoader` module borrowed from [Tensorflow]
    (https://github.com/tensorflow/tensorflow/blob/main/tensorflow/python/util/lazy_loader.py)
    with an addition of "module caching".

    Lazily import a module, mainly to avoid pulling in large dependencies.
    Modules such as `xgrammar` might do additional side effects, so we
    only want to use this when it is needed, delaying all eager effects.
    
local_nameparent_module_globalsr   c                     || _         || _        d | _        t                                          t          |                     d S r   )_local_name_parent_module_globals_moduler   r   r   )rM   r   r   r   r   s       r   r   zLazyLoader.__init__b  s@     &&;#*.T#####r   r,   c                     	 t          j        | j                  }|| j        | j        <   |t
          j        | j        <   n# t          $ r}|d d }~ww xY w| j        	                    |j                   |S r   )
r!   r0   r   r   r   r   r   r$   __dict__update)rM   r)   errs      r   _loadzLazyLoader._loadn  s    	 ,T];;F<BD'(89 -3CK())" 	  	  	 4	  	V_---s   <? 
A	AAitemc                 l    | j         |                                 | _         t          | j         |          S r   )r   r   r1   )rM   r   s     r   rN   zLazyLoader.__getattr__  s+    <::<<DLt|T***r   c                 j    | j         |                                 | _         t          | j                   S r   )r   r   dirra   s    r   __dir__zLazyLoader.__dir__  s)    <::<<DL4<   r   )r   r   r   r   r   dictr   r   r   r   rN   listr   r   r   s   @r   r   r   W  s         
$
$  $CH~
$ 	
$ 
$ 
$ 
$ 
$ 
$z    "+ + + + + +
!c ! ! ! ! ! ! ! !r   r   c                 D    t           j                            |           duS )zReturn True if *module_name* can be found in the current environment.

    The result is cached so that subsequent queries for the same module incur
    no additional overhead.
    N)r!   r"   	find_spec)r   s    r   r   r     s     >##K00<<r   c                       t          d          S )z9Whether the optional `pplx_kernels` package is available.pplx_kernelsr   r@   r   r   has_pplxr     s    ~&&&r   c                       t          d          S )z4Whether the optional `deep_ep` package is available.deep_epr   r@   r   r   has_deep_epr     s    y!!!r   c                       t          d          S )z6Whether the optional `deep_gemm` package is available.	deep_gemmr   r@   r   r   has_deep_gemmr     s    {###r   c                  b    t          d          pt          d          } | rt                       | S )z;Whether the optional `triton_kernels` package is available.r   r   )r   r   )is_availables    r   has_triton_kernelsr     s@    /00 K)5 5L   r   c                       t          d          S )z5Whether the optional `tilelang` package is available.tilelangr   r@   r   r   has_tilelangr     s    z"""r   c                       t          d          S )z=Whether the optional `arctic_inference` package is available.arctic_inferencer   r@   r   r   has_arctic_inferencer     s     )***r   c                       t          d          S )a$  Whether the optional `helion` package is available.

    Helion is a Python-embedded DSL for writing ML kernels.
    See: https://github.com/pytorch/helion

    Usage:
        if has_helion():
            import helion
            import helion.language as hl
            # use helion...
    helionr   r@   r   r   
has_helionr     s     x   r   c                       t          d          S )z2Whether the optional `aiter` package is available.aiterr   r@   r   r   	has_aiterr     s    wr   c                       t          d          S )z1Whether the optional `mori` package is available.morir   r@   r   r   has_morir     s    vr   )*r   importlib.metadatar!   importlib.utilosr   	functoolsr   typesr   typingr   regexr:   typing_extensionsr   vllm.loggerr   r   r   r   r   r   PathLiker*   r3   rF   rH   r   r   r   boolr   r   r   r   r   r   r   r   r   r   r@   r   r   <module>r     s            				 



                       # # # # # # # # # # # #	X		  @ 
 
 
8# #2C    &%c %c % % % %   Y, Y, Y, Y, Y, Y, Y, Y,x!
 !
 !
 !
 !
( !
 !
 !
H
 
 
 
 
- 
 
 
(0! 0! 0! 0! 0! 0! 0! 0!h =S =T = = = ='$ ' ' ' '
"T " " " "
$t $ $ $ $
D    #d # # # #
+d + + + +!D ! ! ! ! 4        
$      r   