
    uki+              
           d dl mZ d dlZd dlZd dlmZ d dlZddlmZ	 ddgdd	gd
Z
dddededededz  fdZdedededefdZdddee   dedededz  fdZy)    )SequenceN)
ModuleType   )__version__jax_cuda13_pluginjax_cuda12_pluginjax_rocm7_pluginjax_rocm60_plugin)cudarocmTcheck_versionplugin_namesubmodule_namer   returnc                f    | t         vrt        d|        t        d|  gt         |    z   ||      S )aF  Import a submodule from a known plugin with version checking.

  Args:
    plugin_name: The name of the plugin. The supported values are "cuda" or
      "rocm".
    submodule_name: The name of the submodule to import, e.g. "_triton".
    check_version: Whether to check that the plugin version is compatible with
      the jaxlib version. If the plugin is installed but the versions are not
      compatible, this function produces a warning and returns None.

  Returns:
    The imported submodule, or None if the plugin is not installed or if the
    versions are incompatible.
  zUnknown plugin: .r   )_PLUGIN_MODULE_NAMES
ValueErrormaybe_import_plugin_submodule)r   r   r   s      P/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jaxlib/plugin_support.pyimport_from_pluginr      sK    " ,,
'}5
66	&	
;-0==!
     jaxlib_versionplugin_versionc           	          t        j                  d      dt        dt        t        df   ffd} ||       ||      k7  r%t        j                  d|  d| d| d	t               y
y)Nz[0-9]+(?:\.[0-9]+)*vr   .c                     j                  |       }|t        d|  d      t        d |j                  d      j	                  d      D              S )Nz Unable to parse version string ''c              3   2   K   | ]  }t        |        y w)N)int).0xs     r   	<genexpr>z?check_plugin_version.<locals>._parse_version.<locals>.<genexpr>D   s     7AQ7s   r   r   )matchr   tuplegroupsplit)r   mversion_regexs     r   _parse_versionz,check_plugin_version.<locals>._parse_version@   sQ    AAy9!A>??7!1!1#!6777r   zJAX plugin z	 version zJ is installed, but it is not compatible with the installed jaxlib version z, so it will not be used.FT)recompilestrr&   r!   warningswarnRuntimeWarning)r   r   r   r+   r*   s       @r   check_plugin_versionr2   8   s~     **34-8 8c3h 8 N#~n'EEMM
k])N+; <B
3	5 		 	r   plugin_module_namesc                   | D ]b  }	 t        j                  | d| d      }|s|c S 	 t        j                  | dd      }t        |dd      }t	        |t
        |      s`|c S  y # t        $ r |cY c S w xY w# t        $ r Y w xY w)Nr   jaxlib)packagez.versionr    )	importlibimport_moduleImportErrorgetattrr2   r   )r3   r   r   plugin_module_namemoduleversion_moduler   s          r   r   r   Q   s     0 && .!1
2f "00!"(+
 ~}bAn	
nn
 -. 
    s"   A<A))A98A9<	BB)collections.abcr   r8   r,   typesr   r/   versionr   r   r   r.   boolr   r2   r    r   r   <module>rD      s    %  	   2 !"56!45  EI&)=A$4&);>	: 	!# 	
 $r   