
    Vpfr)                        U d dl 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 d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlZ ej        e          Zg aee         ed<   d	ee         d
dfdZd&dZd
ee         fdZd
efdZ	 d'dej         dej!        dej"        dej#        ded
efdZ$defdZ%dej         d
e&fdZ'dej         d
e&fdZ(d Z)dej!        d
dfdZ*dej!        fdZ+	 d(d!Z,d" Z-d#ee         fd$Z.d% Z/dS ))    N)cast)config)version_str)
xla_client)ir)passmanager_extra_flag_prefixesflag_prefixesreturnc                     t           | z  a dS )zFAdd flag prefixes to include in the cache key. Call prior to get().
  Nr	   )r
   s    R/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/cache_key.pyadd_flag_prefixesr   #   s     -'    c                  
    g a dS )z4Clear flag prefixes added by add_flag_prefixes().
  Nr    r   r   clear_flag_prefixesr   *   s     r   c                      t           S )z5Return flag prefixes added by add_flag_prefixes().
  r   r   r   r   get_flag_prefixesr   1   s
     
r   c                      dS )zCustom hook for any addition to the cache key.

  The custom hook will be called everytime get() is called and can be
  defined to return a string that will be hashed into the cache key.
   r   r   r   r   custom_hookr   7   s	     
r   	zstandardmoduledevicescompile_optionsbackendcompression_algorithmc                 x    d fdfdd fdd fdfdfd	fd
fdfdfdd fg}t          j                    }|D ]!\  }} ||           t          |||           " j        j        d         }	t          j        |	          j        }
|
dz   |                                	                                z   S )a  Creates a hashed string to use as a key to the compilation cache.

  Creates a cache key that is a hex-encoded string of a unique hash based on
  the arguments. The hex-encoded string is 256 characters long.

  Args:
    module: the input program
    devices: an array of accelerator devices that the program will run on
    compile_options: options passed to the XLA compiler
    backend: description of the platform (e.g., TPU version)
    compression_algorithm: a string representing the compression algorithm used
      for the executable before persisting in the cache

  Typical return value example:
   'jit__psum-14ac577cdb2ef6d986078b4054cc9893a9a14a16dbb0d8f37b89167c1f1aacdf'
  computationc                 $    t          |           S N)_hash_computation)hash_objr   s    r   <lambda>zget.<locals>.<lambda>V   s    '86'J'J r   zjax_lib versionc                 j    |                      t          t          j        d                              S Nzutf-8)updatebytesjaxlib_version_strencoder$   s    r   r%   zget.<locals>.<lambda>X   s+    #*733446 6 r   z	XLA flagsc                 :    t          | t                                S r"   )_hash_xla_flagsr   r,   s    r   r%   zget.<locals>.<lambda>[   s    2C2E2EFF r   r   c                 :    t          | j        dk              S )Ngpu)strip_device_assignment) _hash_serialized_compile_optionsplatform)r$   r   r   s    r   r%   zget.<locals>.<lambda>]   s,    8_ %,$4$=	@ @ @ r   accelerator_configc                 &    t          |           S r"   )_hash_accelerator_config)r$   r   r   s    r   r%   zget.<locals>.<lambda>c   s    28WgNN r   compressionc                 $    t          |           S r"   )_hash_string)r$   r   s    r   r%   zget.<locals>.<lambda>e   s    X/DEE r   r   c                 :    t          | t                                S r"   )r9   r   r,   s    r   r%   zget.<locals>.<lambda>f   s    |Hkmm'L'L r   sym_name-)
hashlibsha256_log_cache_key_hash	operation
attributesr   
StringAttrvaluedigesthex)r   r   r   r   r   entriesr$   namehashfnr;   module_names   `````      r   getrJ   @   s6   , JJJJK6 67 FFH@ @ @ @ @A 	N	N	N	N	NPEEEEGLLM#'( ^( 0 0ldF
F8$////(4(h''-+	s	X__..2244	44r   last_serializedc                    t                               t          j                  rt	          j                    } ||           t                               d||                                                                           t                               d||                                                                            d S d S )Nz'get_cache_key hash of serialized %s: %sz+get_cache_key hash after serializing %s: %s)	loggerisEnabledForloggingDEBUGr=   r>   debugrD   rE   )r$   rK   rH   fresh_hash_objs       r   r?   r?   r   s    '' ^%%N
F>
LL1##%%   LL5     r   mc                     t          j                    }| j                            |           |                                S )N)file)ioBytesIOr@   write_bytecodegetvalue)rS   outputs     r   _serialize_irr[      s6    :<<&+&)))			r   
m_originalc                 6   | j         5  t          t          j        | j                                                  }t          j                            d          }|	                    |j                   t          |          cd d d            S # 1 swxY w Y   d S )Nzbuiltin.module(strip-debuginfo))context	type_castr   Moduler@   clonepmPassManagerparserunr[   )r\   rS   passess      r   _canonicalize_irrg      s      ")Z17799::A^!!) F JJq{                 s   A9BBBc                     t           j        j        rt          |          }nt	          |          }|                     |           d S r"   )r   )compilation_cache_include_metadata_in_keyrC   r[   rg   r(   )r$   r   canonical_irs      r   r#   r#      sD    5; , ((LL#F++L
//,r   c                 D    |j         D ]}t          | |j                   d S r"   )flatr9   device_kind)r$   r   devices      r   _hash_devicesro      s3     / /f6-..../ /r   acceleratorsc                    g }|j         D ]}|                    |           	 |                     t          j        |                                                     d S # t          j        j        $ rT}t          	                    d|t          |                     t          | |           t          | |           Y d }~d S d }~ww xY w)Nz{get (_hash_accelerator_config): unable to hash accelerator config, falling back to hashing devices + platform: %s (type %s))rl   appendr(   r   get_topology_for_devices	serialize_xlaXlaRuntimeErrorrM   infotypero   _hash_platform)r$   rp   r   accelerator_devicesacceleratorexs         r   r6   r6      s    !& , ,k{++++&OO+,?@@JJLL     
	( & & & KK 346RB B B (L)))8W%%%%%%%%%&s   9A C2A	CCFc                    t          j        |          }|j        j        }d|_        d|_        d|_        d|_        d|_        d|_	        d|_
        d|_        d|_        d|_        d|_        d|_        d|_        d|_        d|_        d|_        d|_        d|_        |r|j        r|j                                        }|j                                        }t2          j                            t9          j        ||z                                ||g                    |_        |                     |                                           S )Nr   r   F)!copydeepcopyexecutable_build_optionsdebug_options$xla_force_host_platform_device_countxla_dump_toxla_dump_hlo_module_rexla_dump_hlo_pass_rexla_dump_hlo_as_textxla_dump_hlo_as_protoxla_dump_hlo_as_dotxla_dump_hlo_as_urlxla_dump_hlo_as_htmlxla_dump_fusion_visualizationxla_dump_hlo_snapshotsxla_dump_max_hlo_modulesxla_dump_module_metadataxla_dump_compress_protosxla_dump_hlo_as_long_textxla_dump_disable_metadataxla_dump_hlo_pipeline_rexla_gpu_cuda_data_dirdevice_assignmentreplica_countcomputation_countr   DeviceAssignmentcreatenparangereshaper(   SerializeAsString)r$   compile_options_objr1   compile_options_copyr   r   r   s          r   r2   r2      s[    ':;; '?M-78-4 -)+-&')-$',-$(--%&+-#&+-#',-$05--).-&+0-(+0-(+0-(,1-),1-)+--( )+-%  !5!G (:HHJJM,>PPRR-7-H-O-O
	-"3344<<+
,	. 	.. .* 
-??AA	B	BBr   c                     t          | |j                   t          | |j                   t          | |j                   d S r"   )r9   r3   platform_versionruntime_type)r$   r   s     r   ry   ry      sA    x)***x1222x-.....r   extra_flag_prefixesc                    g d}g }t          j        d          }|r'|                    |                                           t          j        d          }|r'|                    |                                           t          j        D ]G                    d          st          fd|D                       r|                               Ht          |          D ]f}|                    d          d         |v rt                              d|           ;t                              d	|           t          | |           gd S )
N)z--xla_dump_compress_protosz--xla_dump_module_metadataz--xla_dump_max_hlo_modulesz--xla_dump_include_timestampz--xla_dump_hlo_pass_rez--xla_dump_hlo_module_rez--xla_dump_hlo_snapshotsz--xla_dump_fusion_visualizationz--xla_dump_hlo_as_urlz--xla_dump_hlo_as_protoz--xla_dump_hlo_as_textz--xla_dump_hlo_as_long_textz--xla_dump_hlo_as_htmlz--xla_dump_hlo_as_dotz--xla_dump_toz&--xla_force_host_platform_device_countz--xla_dump_disable_metadataz--xla_dump_hlo_pipeline_rez$--xla_tpu_sdc_checker_streamz_metricz0--xla_tpu_sdc_checker_enable_sdc_event_callbacksz--xla_gpu_cuda_data_dir	XLA_FLAGSLIBTPU_INIT_ARGSz--xlac              3   B   K   | ]}                     |          V  d S r"   )
startswith).0pargs     r   	<genexpr>z"_hash_xla_flags.<locals>.<genexpr>  s@       & &q& & & & & &r   =r   z'Not including XLA flag in cache key: %sz#Including XLA flag in cache key: %s)osgetenvextendsplitsysargvr   anyrr   sortedrM   rQ   r9   )r$   r   #xla_flags_to_exclude_from_cache_key	xla_flagsxla_flags_env_varlibtpu_init_args_env_varflagr   s          @r   r.   r.      s   ) ) )%2 )i,, 0&,,..///Y'9:: 7-3355666X  c
~~g # & & & &#6& & & # #  s Y ! !dzz#q@@@ll<dCCC
LL6===4    ! !r   c                 z    |                      |                    d                                                     d S r'   )r(   r+   strip)r$   str_vars     r   r9   r9     s2    
//'..))//1122222r   )r   N)r   )F)0r~   r=   rV   rO   r   r   typingr   r_   jax._srcr   jax._src.libr   r*   r   jax._src.lib.mlirr   r   rb   numpyr   	getLogger__name__rM   r	   liststr__annotations__r   r   r   r   r`   ndarrayCompileOptionsClientrJ   r?   r)   r[   rg   r#   ro   r6   r2   ry   r.   r9   r   r   r   <module>r      s     				  				 



 $ $ $ $ $ $       : : : : : : # # # # # #             / / / / / /     
	8	$	$"$ d3i $ $ $(T#Y (4 ( ( ( (   49    S     &1	/5 /5	 /5/5#2/5 "/5  #	/5 69	/5 /5 /5 /5d3    $RY 5     u         /RZ /D / / / /
&RZ & & & && >C/C /C /C /Cd/ / /1!49 1! 1! 1! 1!h3 3 3 3 3r   