
    uki                         U 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aee	d<   d Z
dedz  fdZdefd	Zdd
ZdededefdZy)    N)config)hardware_utilsFrunning_in_cloud_tpu_vmc                  .    	 dd l } | S # t        $ r Y y w xY w)Nr   )libtpuImportError)r   s    R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/cloud_tpu_init.pymaybe_import_libtpur
      s'    
  M 
 s    	returnc                      t        j                  d      } | <t         j                  j                  |       r| S d|  d}t	        j
                  |       t               }||j                         S y )NTPU_LIBRARY_PATHz0TPU_LIBRARY_PATH is set to a non-existent path: z_. Falling back to default libtpu path. Please unset TPU_LIBRARY_PATH or set it to a valid path.)osgetenvpathisfilewarningswarnr
   get_library_path)path_from_envwarning_messagelibtpu_modules      r	   get_tpu_library_pathr   (   sr    ))./-	ww~~m$
:=/ J& 	& 
 MM/"%'-))++	    c                  &    dt         j                  v S )NJAX_FORCE_TPU_INIT)r   environ r   r	   jax_force_tpu_initr   ;   s    		++r   c                  V   ddl m}  t               }t        j                         \  }}|dk(  rdt
        j                  d<   |F|t        j                  j                  k\  r)t        j                         st        j                  d       ||dk(  rt               sydat
        j                  j                  dd	       t
        j                  j                  d
d       t
        j                  j                  d| j                         t
        j                  j                  dd       dt
        j                  j!                  dd      vr4t
        j                  j!                  dd      dz   t
        j                  d<   t
        j                  j                  dd       t
        j                  j                  dd       t"        j$                  j&                  t#        j(                  dd       t"        j*                  j&                  $t#        j(                  dd| j                          yy)aa  Automatically sets Cloud TPU topology and other env vars.

  **This must be called before the TPU runtime is loaded, which happens as soon
  as JAX's C++ backend is loaded! I.e. call this before xla_bridge or xla_client
  is imported.**

  Safe to call in non-Cloud TPU environments.

  Some of these environment variables are used to tell the TPU runtime what kind
  of mesh topology to use. It assumes a single-host topology by default, so we
  manually set them here to default to the full pod slice if applicable.

  This will not set any env vars if a single topology-related env var is already
  set.
  r   )version1TPU_SKIP_MDS_QUERYNa  Transparent hugepages are not enabled. TPU runtime startup and shutdown time should be significantly improved on TPU v5e and newer. If not already set, you may need to enable transparent hugepages in your VM image (sudo sh -c "echo always > /sys/kernel/mm/transparent_hugepage/enabled")TGRPC_VERBOSITYERRORTPU_ML_PLATFORMJAXTPU_ML_PLATFORM_VERSIONENABLE_RUNTIME_UPTIME_TELEMETRYz%--xla_tpu_use_enhanced_launch_barrierLIBTPU_INIT_ARGS z+ --xla_tpu_use_enhanced_launch_barrier=true'TENSORSTORE_CURL_LOW_SPEED_TIME_SECONDS60&TENSORSTORE_CURL_LOW_SPEED_LIMIT_BYTES256jax_platformsztpu,cpujax_pjrt_client_create_optionsz+ml_framework_name:JAX;ml_framework_version:)jaxr    r   r   %num_available_tpu_chips_and_device_idr   r   
TpuVersionv5etransparent_hugepages_enabledr   r   r   r   
setdefault__version__getr   r/   valueupdater0   )r    libtpu_pathnum_tpu_chipstpu_ids       r	   cloud_tpu_initr>   ?   s   $  %&+(NNP-a'*BJJ#$
N--11
1::<MM	9 ]a/9K9M
 **('2**)51**173F3FG**93?,BJJNN"5  	

)2.
7	8 JJ!" **A4H**@%H
 '
MM/9-**008
MM(
5g6I6I5JK 9r   yearmonthdayc                 @   d|j                   vry|j                   j                  d      d   }t        j                  d|      }t	        |      dk7  ryt        j                  | ||      }|j                  t        |d   dd             }||k  xr |j                  d	kD  S )
NzTFRT TPUF
z\(.*?\)   Tr   i  )
platform_versionsplitrefindalllendatetimedatefromtimestampintr?   )r?   r@   rA   backendrF   resultsrL   
build_dates           r	   is_cloud_tpu_older_thanrR      s    w///
 --33D9"=JJz#34'\Q	tUC	($!!#gaj2&6"78*	d		5z55r   )r   N)rK   r   rH   r   jax._srcr   r   r   bool__annotations__r
   strr   r   r>   rN   rR   r   r   r	   <module>rW      sf     	 	   # %  %cDj &,D ,DN6# 6c 6 6r   