
    Vpf{             	         d dl mZ d dlmZmZmZ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Zd dlZd dlmZmZmZmZmZmZ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  e
j        e          Z ed
          Z d5dZ!d6dZ" G d dee                    Z# G d d          Z$d Z% e$            Z&e&j'        Z'e&j(        Z(e&j)        Z) G d d          Z* e*            Z+ G d d          Z, e,            Z- ej.                    Z/ G d dee                    Z0dZ1dZ2ddd d!d"d7d,Z3ddd-d8d3Z4ddd-d9d6Z5ddd-d:d:Z6ddd-d;d?Z7ddd-d<d@Z8ddd-d=dAZ9ddddBd>dGZ: G dH dIee                    Z;d?dKZ<d@dMZ=dAdOZ>dBdQZ?dBdRZ@d aA G dS dTe          ZBdU ZC G dV dWe          ZD G dX dYej.                  ZE eE            ZFdZ ZG e3d[d d\]          ZH e3d^ e!d_d`          da]          ZI e6db e"dcd           dd]          ZJ e6de e"dfdg          dh]          ZK e3di e!djd           dk]          ZL e9dlddm]          ZM e9dnddo]          ZN e3dpd dq]          ZO e3drd ds]          ZP e3dtd du]          ZQ ejR        eQd`          ZS e3dvd dw]          ZT e3dxd dy]          ZU e3dzd d{]          ZV e3d|d d}]          ZW e3d~d d]          ZX e3dd d`d          ZYd ZZd Z[ e3dd d`eZe[d          Z\ e4dddgdd          Z] e3dd d]          Z^ e6dd dd d           Z_ e4dg ddd          Z` e3dd d`d          Za e4dg ddd          Zb e3dd d`dd d           Zc e3dd dd d           Zd e3dd d`dd d           Ze e3dd d`d          Zf e3dd d]          Zg e7ddd]          Zh e6dd d]          Zi e3dd d]          Zj e9ddd]          Zk e3dd`d]          Zl e6ddd]          Zm e3dd d]          Zn e3dd d]          Zo e6dddì]          Zp e3dd ddƄ dǄ           Zq e6dddd˄ d̄           Zr e6dddϬ]          Zs e3dd`dѬ]          Zt e9dddӬ]          Zu e6ddd֬]          Zv e4dddgddڬ          Zw e4dddgddd߄ d           Zxd Zyd Zz e3dd deyez          Z{e&j|        }                    d            e~e$d ed                      d Zd Zd Z e:dddeee          Zd Zd Z e3dd dee          Z e4dg dddd d           Z e5dg dddd d           Z e4dg ddd          Z e3d d d]          Z e3d e ej        dd!                    dd d           Z e3dd`d]          Z e3d	d`d`d
          Z e3dd d`d          Z e3dd d]          Z e6dd dd d           Zej        dCd            Zej        dCd            Zd Z e5dg dddd d           Z e5dg dddd d           Z e5d g ddd!d" d#           Zd$ Z e5d%g ddd&e'          Zej        dDd)            ZdEd+Z e8d,d!d-e.            e3d/d d0]          Z e3d1d d`d2d3 d4           ZdS (F      )annotations)CallableHashableIteratorSequenceN)AnyGeneric
NamedTupleNoReturnProtocolTypeVarcast)lib)jax_jit)transfer_guard_lib)
xla_client)logging_config_Tvarnamestrdefaultboolreturnc                    t          j        | t          |                    }|                                }|dv rdS |dv rdS t	          d|d|           )ab  Read an environment variable and interpret it as a boolean.

  True values are (case insensitive): 'y', 'yes', 't', 'true', 'on', and '1';
  false values are 'n', 'no', 'f', 'false', 'off', and '0'.

  Args:
    varname: the name of the variable
    default: the default boolean value
  Raises: ValueError if the environment variable is anything else.
  )yyesttrueon1T)nnoffalseoff0Fzinvalid truth value z for environment )osgetenvr   lower
ValueError)r   r   vals      O/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/config.pybool_envr-   &   si     		'3w<<((#		#0004
3335
OCOOGOO
P
PP    intc                `    t          t          j        | t          |                              S )z<Read an environment variable and interpret it as an integer.)r/   r'   r(   r   )r   r   s     r,   int_envr1   :   s"    	RYwG--	.	..r.   c                  &    e Zd ZU dZded<   ddZdS )	ValueHolderzA holder for a configuration value.

  There are two kinds of value holders: ``Flag``, which is assigned exactly
  once and never modified after; and ``State``, which can be changed locally
  within a thread via a context manager.
  r   valuer   Nonec                    d S N selfr4   s     r,   _setzValueHolder._setI   s      r.   Nr4   r   r   r5   )__name__
__module____qualname____doc____annotations__r;   r8   r.   r,   r3   r3   ?   s3           )))((((((r.   r3   c                  X    e Zd ZdZd Zd Zd Zd Zed             Z	d Z
d Zd	 Zd
 ZdS )ConfigTc                V    i | _         i | _        d| _        t                      | _        d S )NF)_value_holdersmetause_abslset_contextmanager_flagsr:   s    r,   __init__zConfig.__init__O   s*    24DDIDM!$Dr.   c                |    || j         vrt          d|           | j         |                             |           d S NzUnrecognized config option: )rE   AttributeErrorr;   )r:   namer+   s      r,   updatezConfig.updateU   sI    4&&&@$@@AAA""3'''''r.   c                j    || j         v rt          d| d| d          |                     |          S )NzQFor flags with a corresponding contextmanager, read their value via e.g. `config.z` rather than `config.FLAGS.z`.)rI   rN   _readr:   rO   s     r,   readzConfig.readZ   sc    t)))I"I I@DI I IJ J J ::dr.   c                h    	 | j         |         j        S # t          $ r t          d|           w xY wrM   )rE   r4   KeyErrorrN   rS   s     r,   rR   zConfig._reada   sO    B &,, B B B@$@@AAABs    1c                H    d | j                                         D             S )Nc                $    i | ]\  }}||j         S r8   r4   ).0rO   holders      r,   
<dictcomp>z!Config.values.<locals>.<dictcomp>i   s     OOO<4D&,OOOr.   )rE   itemsrJ   s    r,   valueszConfig.valuesg   s%    OO43F3L3L3N3NOOOOr.   c                l    || j         v rt          d| d          || j         |<   |||f| j        |<   d S )NzConfig option z already defined)rE   	ExceptionrF   )r:   rO   r[   opt_type	meta_argsmeta_kwargss         r,   
add_optionzConfig.add_optionk   sM    t"""=t===>>> &DK8DIdOOOr.   c           
     v   	 ddl m} ddlm}m	 d _        	 _        t          	j        t          	j	        t          	j        t          	j        d	j        i} j                                        D ].\  }\  }}} j        |         } ||         ||j        g|R i | /|                    	 fd           dS )a  Registers absl flags for the JAX configs.

    E.g., for each JAX config defined using bool_state(), this method
    registers an absl boolean flag, with the same name.

    This is the recommended method to call if you use `app.run(main)` and you
    need JAX flags.

    Examples:

    ```python
    from absl import app
    import jax
    ...

    if __name__ == '__main__':
      jax.config.config_with_absl()
      app.run(main)
    ```

    r   N)appflagsTenumc                 .                                    S r7   )complete_absl_config)
absl_flagsr:   s   r,   <lambda>z)Config.config_with_absl.<locals>.<lambda>   s     9 9* E E r.   )
absl.flagsrg   abslrf   rG   rk   r   DEFINE_boolr/   DEFINE_integerfloatDEFINE_floatr   DEFINE_stringDEFINE_enumrF   r]   rE   r4   call_after_init)
r:   
absl_FLAGSrf   	absl_defsrO   	flag_typerb   rc   r[   rk   s
   `        @r,   config_with_abslzConfig.config_with_abslq   s    , $#####--------DM DO
.
10
0*0	3I 6:Y__5F5F J J11y)["4(fi	4I	III[IIIIEEEEEFFFFFr.   c                    | j                                         D ]E\  }}	 |j        |         }n# t          $ r Y  w xY w|j        r|                    |j                   Fd S r7   )rE   r]   FLAGSrV   presentr;   r4   )r:   rk   rO   r[   flags        r,   rj   zConfig.complete_absl_config   s     +1133    f%    	 
  DJ   s   .
;;c                   t           st          j        d t          j                  }dgd |D             }ddl}|                                  |j                            |d           | 	                    |j                   da dS dS )a  Parses command-line args that start with --jax.

    This method should be used only by advanced users. Most users should use
    :meth:`config_with_absl` instead.

    This method has serious limitations: e.g., although it parses only the
    --jax* command-line args, it runs the validators of all registered absl
    flags, even non-JAX ones that have not been set yet; as such, for the
    non-JAX flags, the validators run on the default flag values, not on the
    values indicated by the command-line args.
    c                    | dk    S )Nz--r8   )as    r,   rl   z.Config.parse_flags_with_absl.<locals>.<lambda>   s
    qDy r.    c              3  D   K   | ]}|                     d           |V  dS )z--jaxN)
startswith)rZ   r   s     r,   	<genexpr>z/Config.parse_flags_with_absl.<locals>.<genexpr>   s3      EEaq||G/D/DEEEEEEEr.   r   NT)
known_only)
already_configured_with_absl	itertools	takewhilesysargvrm   ry   rg   r{   rj   )r:   jax_argvrn   s      r,   parse_flags_with_abslzConfig.parse_flags_with_absl   s     ( * $%8%8#(CChFEE8EEEFh

jxD111

+++%)"""* *r.   N)r=   r>   r?   _HAS_DYNAMIC_ATTRIBUTESrK   rP   rT   rR   propertyr^   rd   ry   rj   r   r8   r.   r,   rC   rC   L   s         ' ' '( ( (
  B B B P P 8P9 9 9$G $G $GL      * * * * *r.   rC   c                    t          j                    } d}d}| j        }|r|j        |j        }|r|j        r|j        }||t
          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t           j        t"          j        t$          j        t&          j        t(          j        t*          j        t,          j        t.          j        fS )zReturns a tuple of configuration values that affect tracing.

  These values are included in the cache key for linear_util.cache.

  Values included in this set should also most likely be included in
  the C++ JIT state, which is handled separately.
  r8   )r   thread_local_stateextra_jit_contextaxis_env_statemesh_context_manager
enable_x64r4   numpy_rank_promotiondefault_matmul_precisiondynamic_shapesnumpy_dtype_promotiondefault_devicerandom_seed_offsetthreefry_partitionablethreefry_gpu_kernel_loweringsoftmax_custom_jvpenable_memoriesdisable_jitdebug_key_reusejax_xla_profile_version&hlo_source_file_canonicalization_regexpgle_profiling_runsenable_pgleuse_shardy_partitioner)tlsr   r   contexts       r,   trace_contextr      s     	"$$#.&' ,'3+N 8- 8"7
.
0@

$&>&D

 5 ;

 2 8
 
&
&
,

"






!
'
0
6

#


 
&
( (r.   c                      e Zd ZdS )	NoDefaultNr=   r>   r?   r8   r.   r,   r   r                r.   r   c                      e Zd ZdS )_UnsetNr   r8   r.   r,   r   r      r   r.   r   c                  z    e Zd ZdZddddefddZddZddZedd            Z	e
j        efd d            Zd ZdS )!State)_name_value_update_thread_local_hook_update_global_hook
_validator_default_context_manager_valuer@   r=   Nr   rO   r   r   r   update_global_hookCallable[[_T], None] | Noneupdate_thread_local_hook"Callable[[_T | None], None] | None	validatorCallable[[Any], None] | Noneextra_descriptiondefault_context_manager_valuer   c	                    || _         |                    d          r
|dd          n|| _        d| d| d| | _        || _        || _        || _        || _        |                     |           d S )Njax_   zContext manager for `z` config optionz.

)	r   r   r=   r@   r   r   r   r   r;   )	r:   rO   r   helpr   r   r   r   r   s	            r,   rK   zState.__init__   s     DJ $ 7 7ADHHTDM6D 6 6(6 6/36 6DL1D%=D"DO*GD'IIgr.   r   r   c                j    t          d                    t          |           j                            Nz[bool() not supported for instances of type '{0}' (did you mean to use '{0}.value' instead?)	TypeErrorformattyper=   rJ   s    r,   __bool__zState.__bool__  4    
	55;VJJ6! 6!" " "r.   r4   r5   c                    | j         r|                      |           || _        | j        r|                     |           d S d S r7   )r   r   r   r9   s     r,   r;   z
State._set  sT     
ooeDK &
u%%%%%& &r.   c                    t           j                            | j        t                    }|t          urt          t          |          n| j        S r7   )_thread_local_state__dict__getr   unsetr   r   r   )r:   r+   s     r,   r4   zState.value  s:    

&
*
*4:u
=
=Cu,,4C===$+=r.   new_valc              #    K   |t           u r.| j        t           ur| j        }nt          d| j         d          | j        r|                     |           t          t          | j        t                    }t          t          | j        |           | j
        r| 
                    |           	 d V  |t          u r:t          t          | j                   | j
        r| 
                    d            d S d S t          t          | j        |           | j
        r*| 
                    t          t          |                     d S d S # |t          u r8t          t          | j                   | j
        r| 
                    d            w w t          t          | j        |           | j
        r)| 
                    t          t          |                     w w xY w)NzContext manager for zU config option requires an argument representing the new value for the config option.)
no_defaultr   r   r=   r   getattrr   r   r   setattrr   delattrr   r   )r:   r   prev_vals      r,   __call__zState.__call__!  s     *		,J	>	>5  -t} - - - . . 	.  
oog*DJ>>HW555% .
$$W---
=eee	U		#TZ000) 	/

(
(
.
.
.
.
.	/ 	/ 	#TZ:::) 	=

(
(b(););
<
<
<
<
<	= 	= 
U		#TZ000) 	/

(
(
.
.
.
.	/ 	#TZ:::) 	=

(
(b(););
<
<
<
<	=s   .E BGc                B    || _         || _         || j                   dS )zmPrivate method that adds hooks to an existing context-manager.

    Used to avoid cyclic import dependencies.N)r   r   r   )r:   r   r   s      r,   
_add_hookszState._add_hooks>  s-     &>D"1Dt{#####r.   )rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   )r   r   )r   r   )r=   r>   r?   	__slots__r   rK   r   r;   r   r4   
contextlibcontextmanagerr   r   r8   r.   r,   r   r      s        ) 9=EI04!+5    *" " " "& & & & > > > 8> $. = = = = =8$ $ $ $ $r.   r   z This will be enabled by default in future versions of JAX, at which point all uses of the flag will be considered deprecated (following the `API compatibility policy <https://jax.readthedocs.io/en/latest/api_compatibility.html>`_).z (transient)Fr   )r   r   upgrader   rO   r   r   Callable[[bool], None] | Noner   $Callable[[bool | None], None] | Noner   r   State[bool]c               d   t          |t                    s>t          d| dt          t	          |          dt	          |                               t          |                                 |          }|                                 } |r|dt          z   z  }|t          z  }t          j                            |            t          t                   | |||||d          t                              | t          g d|i           t          t           | t#          fd	                     S )
a=  Set up thread-local state and return a contextmanager for managing it.

  This function is a convenience wrapper. It defines a flag, environment
  variable, and corresponding thread-local state, which can be managed via the
  contextmanager it returns.

  The thread-local state value can be read via the ``config.<option_name>``
  attribute, where ``config`` is the singleton ``Config`` instance.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: boolean, a default value for the option.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.
    update_global_hook: a optional callback that is called with the updated
      value of the global state when it is altered or set initially.
    update_thread_local_hook: a optional callback that is called with the
      updated value of the thread-local state when it is altered or set
      initially.
    upgrade: optional indicator that this flag controls a canonical feature
      upgrade, so that it is `True` for the incoming functionality, `False`
      for the outgoing functionality to be deprecated.
    extra_description: string, optional: extra information to add to the
      summary description.

  Returns:
    A contextmanager to control the thread-local state value.

  Examples:

    ENABLE_FOO = config.bool_state(
        name='jax_enable_foo',
        default=False,
        help='Enable foo.')

    # Now the JAX_ENABLE_FOO shell environment variable and --jax_enable_foo
    # command-line flag can be used to control the process-level value of
    # the configuration option, in addition to using e.g.
    # ``config.update("jax_enable_foo", True)`` directly. We can also use a
    # context manager:

    with enable_foo(True):
      ...

  The value of the thread-local state or flag can be accessed via
  ``config.jax_enable_foo``. Reading it via ``config.FLAGS.jax_enable_foo`` is
  an error.
  z(Default value must be of type bool, got 	 of type r=    T)r   r   r   r   r   rb   rc   c                    j         S r7   rY   _ss    r,   rl   zbool_state.<locals>.<lambda>  	    17 r.   )
isinstancer   r   r   r   r-   upperr)   UPGRADE_BOOL_HELPUPGRADE_BOOL_EXTRA_DESCconfigrI   addr   rd   r   rC   r   )rO   r   r   r   r   r   r   r   s          @r,   
bool_stater   P  sC   x 
GT	"	" T
 Sw S S&tG}}j$w--PPS S T T TTZZ\\7++'	$ 1C###D00""4(((Dk
GT.@7)O O O! 	D!TRfd^LLL	&$!2!2!2!233444	
(r.   )r   r   enum_valuesSequence[str]Callable[[str], None] | None#Callable[[str | None], None] | None
State[str]c               p   t          |t                    s>t          d| dt          t	          |          dt	          |                               |                                 } t          j        |                                 |          }|vrt          d| d|            t          j                            |            fd}t          t                   | |||||          t                              | dg |d	
           t          t           | t#          fd                     S )a}  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    enum_values: list of strings representing the possible values for the
      option.
    default: string, default value.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.

  Returns:
    A contextmanager to control the thread-local state value.
  'Default value must be of type str, got r   r=   Invalid value "" for JAX flag c           
         t          |           t          us| vr&t          d d|  dt          |            d          d S )Nznew enum value must be in , got r   .r   r   r*   r   r   s    r,   r   zenum_state.<locals>.validator  sy    G}}C7+#=#= AK A A%A A04WA A A B B B $>#=r.   r   r   r   rh   r   r   r   c                    j         S r7   rY   r   s    r,   rl   zenum_state.<locals>.<lambda>  r   r.   r   r   r   r   r   r)   r'   r(   r   r*   r   rI   r   r   rd   r   rC   r   )rO   r   r   r   r   r   r   r   s    `     @r,   
enum_stater    sy   4 
GS	!	! T
 Sg S S&tG}}j$w--PPS S T T T	$IdjjllG,,'K
GGGGG
H
HH""4(((B B B B B
 Cj

+7  ! 	
Av"-t<<    
 
&$!2!2!2!233444	
(r.   
str | NoneState[str | None]c               l   |St          |t                    s>t          d| dt          t	          |          dt	          |                               |                                 } t          j        |                                 |          }||vrt          d| d|            t          j                            |            fd}t          d         | |||||          t                              | d	g |d
           t          t           | t#          fd                     S )a  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    enum_values: list of strings representing the possible values for the
      option.
    default: optional string, default value.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.

  Returns:
    A contextmanager to control the thread-local state value.
  N/Default value must be of type str or None, got r   r=   r   r   c           
         | @t          |           t          us| vr(t          d d|  dt          |            d          d S d S )Nz"new enum value must be None or in r   r   r   r   r   s    r,   validatez%optional_enum_state.<locals>.validate  s    G}}C7+#=#= AK A A%A A04WA A A B B B 	#=#=r.   r  rh   r  r   c                    j         S r7   rY   r   s    r,   rl   z%optional_enum_state.<locals>.<lambda>
  r   r.   r  )rO   r   r   r   r   r   r  r   s    `     @r,   optional_enum_stater    sz   4 GS!9!9
 Sg S S&tG}}j$w--PPS S T T T	$IdjjllG,,'WK77
GGGGG
H
HH""4(((B B B B B L
GT-/G ! 	
Av"-t<<    
 
&$!2!2!2!233444	
(r.   Callable[[int], None] | None#Callable[[int | None], None] | None
State[int]c                  t          |t                    s>t          d| dt          t	          |          dt	          |                               |                                 } t          j        |                                           }|4	 t          |          }n## t          $ r t          d| d|            w xY wt          j                            |            d }t          t                   | |||||          t                              | t          g d|i	           t          t           | t#          fd
                     S )a+  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: optional int, default value.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.

  Returns:
    A contextmanager to control the thread-local state value.
  z'Default value must be of type int, got r   r=   Nr   r   c                |    | 7t          | t                    s$t          d|  dt          |                      d S d S )Nz6new int config value must be None or of type int, got r   )r   r/   r*   r   r   s    r,   r  zint_state.<locals>.validate1  sd    :gs#;#; @%@ @04W@ @ A A A r.   r   r   c                    j         S r7   rY   r   s    r,   rl   zint_state.<locals>.<lambda>9  r   r.   )r   r/   r   r   r   r)   r'   r(   r   r*   r   rI   r   r   rd   r   rC   r   rO   r   r   r   r   default_envr  r   s          @r,   	int_stater    s}   . 
GS	!	! T
 Sg S S&tG}}j$w--PPS S T T T	$	$**,,''+OK  gg O O OM+MMtMMNNNO""4(((A A A
 Cjw&8)85 5!D!SBVTNKKK	&$!2!2!2!233444	
(   B" " Crq   Callable[[float], None] | None%Callable[[float | None], None] | NoneState[float]c                  t          |t                    s>t          d| dt          t	          |          dt	          |                               |                                 } t          j        |                                           }|4	 t          |          }n## t          $ r t          d| d|            w xY wt          j                            |            d }t          t                   | |||||          t                              | t          g d|i	           t          t           | t#          fd
                     S )a  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: default value.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.

  Returns:
    A contextmanager to control the thread-local state value.
  z)Default value must be of type float, got r   r=   Nr   r   c                    | >t          | t          t          f          s$t          d|  dt	          |                      d S d S )Nz:new float config value must be None or of type float, got r   )r   rq   r/   r*   r   r  s    r,   r  zfloat_state.<locals>.validate`  s`    :gs|#D#D	1	1 	1!%g	1 	12 2 2 r.   r   r   c                    j         S r7   rY   r   s    r,   rl   zfloat_state.<locals>.<lambda>i  r   r.   )r   rq   r   r   r   r)   r'   r(   r   r*   r   rI   r   r   rd   r   rC   r   r  s          @r,   float_stater  =  sz   . 
GU	#	# T
 S S S&tG}}j$w--PPS S T T T	$	$**,,''+Ok""gg O O OM+MMtMMNNNO""4(((2 2 2 El4$(:+X7 7!D!UbvtnMMM	&$!2!2!2!233444	
(r  c                   t          |t                    s>t          d| dt          t	          |          dt	          |                               d }t          | |||||          S )al  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: string, a default value for the option.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.
    update_global_hook: an optional callback that is called with the updated
      value of the global state when it is altered or set initially.
    update_thread_local_hook: an optional callback that is called with the
      updated value of the thread-local state when it is altered or set
      initially.

  Returns:
    A contextmanager to control the thread-local state value.
  r   r   r=   c                v    t          | t                    s#t          d|  dt          |            d          d S )Nz1new string config value must be of type str, got r   r   )r   r   r   r   r  s    r,   r   zstring_state.<locals>.validator  sf    gs## C B&B B15gB B B C C CC Cr.   r  r   r   r   r   r   string_or_object_staterO   r   r   r   r   r   s         r,   string_stater%  m  s    8 
GS	!	! T
 Sg S S&tG}}j$w--PPS S T T TC C C
 
 
GT+7	
 
 
 r.   c                   |St          |t                    s>t          d| dt          t	          |          dt	          |                               d }t          | |||||          S )au  Set up thread-local state and return a contextmanager for managing it.

  See docstring for ``bool_state``.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: optional string, a default value for the option.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.
    update_global_hook: an optional callback that is called with the updated
      value of the global state when it is altered or set initially.
    update_thread_local_hook: an optional callback that is called with the
      updated value of the thread-local state when it is altered or set
      initially.

  Returns:
    A contextmanager to control the thread-local state value.
  Nr	  r   r=   c                ~    | 8t          | t                    s%t          d|  dt          |            d          d S d S )Nz9new string config value must be None or of type str, got r   r   )r   r   r*   r   r  s    r,   r   z(optional_string_state.<locals>.validator  sj    :gs#;#; B&B B15gB B B C C C r.   r  r"  r$  s         r,   optional_string_stater(    s    8 GS!9!9
 Sg S S&tG}}j$w--PPS S T T TC C C
 
 
GT+7	
 
 
 r.   r  r   r   r   
State[Any]c                  |                                  } t          j        |                                 |          }t          j                            |            t          t                   | |||||          t          t          | t          fd                     t                              | t          g d|i           S )a  Set up thread-local state and return a contextmanager for managing it.

  Similar to ``string_state``, except the context manager will accept
  any object, not just a string. Any value passed via command line flag or
  environment variable will be treated as a string.

  Args:
    name: string, converted to lowercase to define the name of the config
      option (and absl flag). It is converted to uppercase to define the
      corresponding shell environment variable.
    default: string, a default value for the option.
    help: string, used to populate the flag help information as well as the
      docstring of the returned context manager.
    update_global_hook: an optional callback that is called with the updated
      value of the global state when it is altered or set initially.
    update_thread_local_hook: an optional callback that is called with the
      updated value of the thread-local state when it is altered or set
      initially.
    validator: an optional callback that is called with the new
      value on any update, and should raise an error if the new value is
      invalid.

  Returns:
    A contextmanager to control the thread-local state value.
  c                    j         S r7   rY   r   s    r,   rl   z(string_or_object_state.<locals>.<lambda>  r   r.   r   r   )r)   r'   r(   r   r   rI   r   r   r   r   rC   r   rd   r   )rO   r   r   r   r   r   r   s         @r,   r#  r#    s    D 
$IdjjllG,,'""4(((Cj
GT-/G ! 
&$!2!2!2!233444D!SBVTNKKK	
(r.   c                  N    e Zd ZU dZded<   ded<   ded<   	 dddZddZddZdS )Flag)r   r4   _update_hookr   r   r   r4   r   r.  NrO   r   update_hookc                L    || _         || _        |                     |           d S r7   )r   r.  r;   )r:   rO   r   r/  s       r,   rK   zFlag.__init__  s)    DJ#DIIgr.   r   r   c                j    t          d                    t          |           j                            r   r   rJ   s    r,   r   zFlag.__bool__   r   r.   r5   c                P    || _         | j        |                     |           d S d S r7   )r4   r.  r9   s     r,   r;   z	Flag._set  s4    DJ$
 %$r.   r7   )rO   r   r   r   r/  r   r   r<   )r=   r>   r?   r   rA   rK   r   r;   r8   r.   r,   r-  r-    s         0)***))),,,, <@    " " " "     r.   r-  
Flag[bool]c                    |                     dd           }t          | ||          }t                              | |t          ||           |S Nr/  )popr-  r   rd   r   rO   r   argskwargsr/  r[   s         r,   	bool_flagr:    sG    

=$//+g{++&D&$f555	-r.   	Flag[int]c                    |                     dd           }t          | ||          }t                              | |t          ||           |S r5  )r6  r-  r   rd   r/   r7  s         r,   int_flagr=    G    

=$//+g{++&D&#tV444	-r.   Flag[float]c                    |                     dd           }t          | ||          }t                              | |t          ||           |S r5  )r6  r-  r   rd   rq   r7  s         r,   
float_flagrA    sG    

=$//+g{++&D&%v666	-r.   	Flag[str]c                    |                     dd           }t          | ||          }t                              | |t          ||           |S r5  )r6  r-  r   rd   r   r7  s         r,   string_flagrD  !  r>  r.   c                    |                     dd           }t          | ||          }t                              | |d||           |S )Nr/  rh   )r6  r-  r   rd   r7  s         r,   	enum_flagrF  (  sG    

=$//+g{++&D&&$777	-r.   c                      e Zd ZU dZded<   dZded<   dZded<   dZded	<   d
Zded<   dZ	ded<   dZ
ded<   dZded<   d
Zded<   d
Zded<   dZded<   dZded<   dS )_GlobalExtraJitContextNr  r   r   
Any | Noner   Fr   r   r   r/   r   r   r   r   xla_profile_versionr   r   r   )r=   r>   r?   r   rA   r   r   r   r   r   r   r   rJ  r   r   r   r8   r.   r,   rH  rH  5  s         %)))))&*****)-----.!&&&&&',,,,,"""""+!&&&&&&&r.   rH  c                 z    t          j                    }|j        pt                      } |j        di | |_        d S Nr8   )r   global_stater   rH  _replace)kwgsr   s      r,   _update_global_jit_staterQ  D  sE    " <$:$<$<'))//B//"r.   c                      e Zd ZU dZdZded<   dZded<   dZded<   dZd	ed
<   dZ	d	ed<   dZ
ded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dS )_ThreadLocalExtraJitContexta\  A namedtuple containing states to add to the cache key.

  Just in time compilation (for jit, pmap, etc) behavior is configurable through
  global and thread-local options, used in the cache key.

  The initialization, which uses both config.py and core.py is done using
  `_update_thread_local_jit_state` in core.py to prevent circular imports.
  NrI  dynamic_trace_stater8   r   r   r   r  r   r   r   zbool | Noner   z
int | Noner   r   r   r   rJ  r   r   )r=   r>   r?   r@   rT  rA   r   r   r   r   r   r   r   r   r   r   rJ  r   r   r8   r.   r,   rS  rS  J  s          %)((((.#%%%%% &*))))&*****)----- $.$$$$#'''''(,,,,,.22222$((((($((((($(((((!+!!!!!!r.   rS  c                      e Zd ZdZd ZdS )_ThreadLocalStateCachea  "A thread local cache for _ThreadLocalExtraJitContext

  The extra_jit_context in jax_jit.thread_local_state() may get updated and thus
  incurring dispatch overhead for comparing this python object during jit calls.
  We want to deduplicate the objects that have the same hash/equality to also
  have the same object ID, since the equality check is much faster if the object
  IDs match.
  c                L     t          j        d          d           | _        d S )N   c                    | S r7   r8   )xs    r,   rl   z1_ThreadLocalStateCache.__init__.<locals>.<lambda>s  s    1 r.   )	functools	lru_cachecanonicalizerJ   s    r,   rK   z_ThreadLocalStateCache.__init__r  s'    0	+C00==Dr.   N)r=   r>   r?   r@   rK   r8   r.   r,   rV  rV  i  s-         > > > > >r.   rV  c                     t          j                    }|j        pt                      } |j        di | }t
                              |          |_        d S rL  )r   r   r   rS  rN  _thread_local_state_cacher]  )rO  r   r   tmps       r,   update_thread_local_jit_statera  y  sZ    "$$# !B%@%B%B'2#3@@EE#r.   "jax2tf_associative_scan_reductionsa  JAX has two separate lowering rules for the cumulative reduction primitives (cumsum, cumprod, cummax, cummin). On CPUs and GPUs it uses a lax.associative_scan, while for TPUs it uses the HLO ReduceWindow. The latter has a slow implementation on CPUs and GPUs. By default, jax2tf uses the TPU lowering. Set this flag to True to use the associative scan lowering usage, and only if it makes a difference for your application. See the jax2tf README.md for more details.)rO   r   r   #jax2tf_default_native_serialization#JAX2TF_DEFAULT_NATIVE_SERIALIZATIONTzSets the default value of the native_serialization parameter to jax2tf.convert. Prefer using the parameter instead of the flag, the flag may be removed in the future. Starting with JAX 0.4.31 non-native serialization is deprecated.jax_serialization_versionJAX_SERIALIZATION_VERSIONz6DEPRECATED: use jax_export_calling_convention_version.%jax_export_calling_convention_version%JAX_EXPORT_CALLING_CONVENTION_VERSION	   a	  The calling convention version number to use for exporting. This must be within the range of versions supported by the tf.XlaCallModule used in your deployment environment. See https://jax.readthedocs.io/en/latest/export/shape_poly.html#calling-convention-versions.'jax_export_ignore_forward_compatibility&JAX_EXPORT_IGNORE_FORWARD_COMPATIBILIYzWhether to ignore the forward compatibility lowering rules. See https://jax.readthedocs.io/en/latest/export/export.html#compatibility-guarantees-for-custom-calls.jax_platformsay  Comma-separated list of platform names specifying which platforms jax should initialize. If any of the platforms in this list are not successfully initialized, an exception will be raised and the program will be aborted. The first platform in the list will be the default platform. For example, config.jax_platforms=cpu,tpu means that CPU and TPU backends will be initialized, and the CPU backend will be used unless otherwise specified. If TPU initialization fails, it will raise an exception. By default, jax will try to initialize all available platforms and will default to GPU or TPU if available, and fallback to CPU otherwise.jax_pjrt_client_create_optionsz}A set of key-value pairs in the format of "k1:v1;k2:v2" strings provided to a device platform pjrt client as extra arguments.jax_enable_checkszBTurn on invariant checking for JAX internals. Makes things slower.jax_debug_key_reuseah  Turn on experimental key reuse checking. With this configuration enabled, typed PRNG keys (i.e. keys created with jax.random.key()) will have their usage tracked, and incorrect reuse of a previously-used key will lead to an error. Currently enabling this leads to a small Python overhead on every call to a JIT-compiled function with keys as inputs or outputs.jax_check_tracer_leaksaM  Turn on checking for leaked tracers as soon as a trace completes. Enabling leak checking may have performance impacts: some caching is disabled, and other overheads may be added. Additionally, be aware that some Python debuggers can cause false positives, so it is recommended to disable any debuggers while leak checking is enabled.jax_debug_nanszAdd nan checks to every operation. When a nan is detected on the output of a jit-compiled computation, call into the un-compiled version in an attempt to more precisely identify the operation which produced the nan.jax_debug_infszAdd inf checks to every operation. When an inf is detected on the output of a jit-compiled computation, call into the un-compiled version in an attempt to more precisely identify the operation which produced the inf.jax_log_compileszLog a message each time `jit` or `pmap` compiles an XLA computation. Logging is performed with `logging`. When this option is set, the log level is WARNING; otherwise the level is DEBUG.jax_explain_cache_misseszEach time there is a miss on one of the main caches (e.g. the tracing cache), log an explanation.. Logging is performed with `logging`. When this option is set, the log level is WARNING; otherwise the level is DEBUG.jax_log_checkpoint_residualszLog a message every time jax.checkpoint (aka jax.remat) is partially evaluated (e.g. for autodiff), printing what residuals are saved.jax_pmap_shmap_mergez/If True, pmap and shard_map API will be merged.)rO   r   r   r   c                L    | t           j                                        _        d S r7   )r   r   rM  r   r+   s    r,   _update_jax_memories_globalry    s    /2#+,,,r.   c                L    | t           j                                        _        d S r7   )r   r   r   r   rx  s    r,   !_update_jax_memories_thread_localr{    s    58#+  ""222r.   jax_enable_memorieszaIf True, will allow fetching memory kinds available on executable and annotate Shardings with it.)r   r   r   r   r   jax_spmd_mode	allow_all	allow_jita  Decides whether Math on `jax.Array`'s that are not fully addressable (i.e. spans across multiple processes) is allowed. The options are: * allow_jit: Default, `pjit` and `jax.jit` computations are allowed     to execute on non-fully addressable `jax.Array`s
* allow_all: `jnp`, normal math (like `a + b`, etc), `pjit`,     `jax.jit` and all other operations are allowed to     execute on non-fully addressable `jax.Array`s.)rO   r   r   r   jax_distributed_debugzEnable logging useful for debugging multi-process distributed computations. Logging is performed with `logging` at WARNING level.jax_random_seed_offsetz?Offset to all random seeds (e.g. argument to jax.random.key()).c                "    t          |           S N)r   rQ  rx  s    r,   rl   rl   @      #;$  $  $  r.   c                "    t          |           S r  ra  rx  s    r,   rl   rl   B      )F*  *  *  r.   )rO   r   r   r   r   jax_legacy_prng_key)allowwarnerrorr  zFSpecify the behavior when raw PRNG keys are passed to jax.random APIs.jax_enable_custom_prngzlEnables an internal upgrade that allows one to define custom pseudo-random number generator implementations.jax_default_prng_impl)threefry2x32rbg
unsafe_rbgr  zaSelect the default PRNG implementation, used when one is not explicitly provided at seeding time.jax_threefry_partitionableaV  Enables internal threefry PRNG implementation changes that render it automatically partitionable in some cases. Without this flag, using the standard jax.random pseudo-random number generation may result in extraneous communication and/or redundant distributed computation. With this flag, the communication overheads disappear in some cases.c                "    t          |           S N)r   r  rx  s    r,   rl   rl   f  s    #;"$$ $$ $$ r.   c                "    t          |           S r  r  rx  s    r,   rl   rl   h  s    )F"*$ *$ *$ r.   )rO   r   r   r   r   r    jax_threefry_gpu_kernel_loweringzOn GPU, lower threefry PRNG operations to a kernel implementation. This makes compile times faster at a potential runtime memory cost.c                "    t          |           S N)r   r  rx  s    r,   rl   rl   q  s    #;%($* $* $* r.   c                "    t          |           S r  r  rx  s    r,   rl   rl   s  s    )F%(** ** ** r.   jax_softmax_custom_jvpzUse a new custom_jvp rule for jax.nn.softmax. The new rule should improve memory usage and stability. Set True to use new behavior. See https://github.com/google/jax/pull/15677c                "    t          |           S N)r   r  rx  s    r,   rl   rl   ~  r  r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     r  r.   )jax_enable_custom_vjp_by_custom_transposezyEnables an internal upgrade that implements `jax.custom_vjp` by reduction to `jax.custom_jvp` and `jax.custom_transpose`.!jax_raise_persistent_cache_errorsaG  If true, exceptions raised when reading or writing to the persistent compilation cache will be allowed through, halting program execution if not manually caught. If false, exceptions are caught and raised as warnings, allowing program execution to continue. Defaults to false so cache bugs or intermittent issues are non-fatal.*jax_persistent_cache_min_compile_time_secsg      ?zThe minimum compile time of a computation to be written to the persistent compilation cache. This threshold can be raised to decrease the number of entries written to the cache.)jax_persistent_cache_min_entry_size_bytesat  The minimum size (in bytes) of an entry that will be cached in the persistent compilation cache: * -1: disable the size restriction and prevent overrides. * Leave at default (0) to allow for overrides. The override will   typically ensure that the minimum size is optimal for the   filesystem being used for the cache. * > 0: the actual minimum size desired; no overrides.-jax_compilation_cache_include_metadata_in_keya  Include metadata, such as file names and line numbers, in the compilation cache key. If false, the cache will still get hits even if functions or files are moved, etc. However, it means that executables loaded from the cache may have stale metadata, which may show up in, e.g., profiles.*jax_hlo_source_file_canonicalization_regexaK  Used to canonicalize the source_path metadata of HLO instructions by removing the given regex. If set, re.sub() is called on each source_file with the given regex, and all matches are removed. This can be used to avoid spurious cache misses when using the persistent compilation cache, which includes HLO metadata in the cache key.(jax_include_full_tracebacks_in_locationszAInclude Python tracebacks in MLIR locations in IR emitted by JAX. jax_traceback_in_locations_limit
   zLimit the number of frames at the Python traceback frames included in MLIR locations. If set to the negative value, traceback will not be limited.'jax_share_autotune_config_between_hostsa  If set to True, the coordinator process will share autotune configs other participants. This will increase overall compilation time, but will lead to equal compiled modules in each process. If both jax_share_binary_between_hosts and jax_share_autotune_config_between_hosts are set, compiled HLO will be shared when it's possible and autotune config sharing will be used as a fallback.jax_share_binary_between_hostszJIf set to True, the compiled module will be shared between hosts directly.)jax_share_binary_between_hosts_timeout_msiO z&Timeout for the compiled module share.jax_enable_pglezIf set to True and the property jax_pgle_profiling_runs is set to greater than 0, the modules will be recompiled after running specified number times with collected data provided to the profile guided latency estimator.c                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    #;#L#L#L r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    )F* * * r.   jax_pgle_profiling_runs   zQAmount of times module should be profiled before recompilation when PGLE is used.c                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    #;$ $ $ r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    )F* * * r.   jax_pgle_aggregation_percentileZ   zPPercentile used to aggregate performance data between devices when PGLE is used.jax_enable_compilation_cachezIf set to False, the compilation cache will be disabled regardless of whether set_cache_dir() was called. If set to True, the path could be set to a default value or via a call to set_cache_dir().jax_compilation_cache_dirzPath for the cache. Precedence: 1. A call to compilation_cache.set_cache_dir(). 2. The value of this flag set in the command line or by default.jax_compilation_cache_max_sizea[  The maximum size (in bytes) allowed for the persistent compilation cache. When set, the least recently accessed cache entry(s) will be deleted once the total cache directory size exceeds the specified limit. Caching will be disabled if this value is set to 0. A special value of -1 indicates no limit, allowing the cache size to grow indefinitely.jax_default_dtype_bits3264zSpecify bit width of default dtypes, either 32-bit or 64-bit. This is a temporary flag that will be used during the process of deprecating the ``jax_enable_x64`` flag.jax_numpy_dtype_promotionstandardstrictzSpecify the rules used for implicit type promotion in operations between arrays. Options are "standard" or "strict"; in strict-mode, binary operations between arrays of differing strongly-specified dtypes will result in an error.c                "    t          |           S N)r   r  rx  s    r,   rl   rl   >  s    S999 r.   c                "    t          |           S r  r  rx  s    r,   rl   rl   @  s    ##>>> r.   )rO   r   r   r   r   r   c                L    | t           j                                        _        d S r7   )r   r   rM  r   rx  s    r,   _update_x64_globalr  C  s    *-#+'''r.   c                L    | t           j                                        _        d S r7   )r   r   r   r   rx  s    r,   _update_x64_thread_localr  F  s    03#+  ""---r.   jax_enable_x64zEnable 64-bit types to be usedx64_enabledc                    t           j        S r7   )r   r4   )r   s    r,   rl   rl   S  s	    *2B r.   c                L    | t           j                                        _        d S r7   )r   r   rM  r   rx  s    r,   _update_default_device_globalr  U  s    .1#++++r.   c                L    | t           j                                        _        d S r7   )r   r   r   r   rx  s    r,   #_update_default_device_thread_localr  Y  s    47#+  ""111r.   c                   | t          | t          j                  sjdt          t	          |                     v r8t
                              dt          |           t	          |                      d S t          d|           d S d S )NDevicez=Allowing non-`xla_client.Device` default device: %s, type: %szWjax.default_device must be passed a Device object (e.g. `jax.devices('cpu')[0]`), got: )	r   r   r  r   r   loggerinforeprr*   rx  s    r,   _validate_default_devicer  ]  s    _ZZ->??_ 3tCyy>>!!kk
I
s))T#YY      f
 ?7:? ? @ @ @ ___r.   jax_default_devicea  Configure the default device for JAX operations. Set to a Device object (e.g. ``jax.devices("cpu")[0]``) to use that Device as the default device for JAX operations and jit'd function calls (there is no effect on multi-device computations, e.g. pmapped function calls). Set to None to use the system default device. See :ref:`faq-data-placement` for more information on device placement.r$  c                L    | t           j                                        _        d S r7   )r   r   rM  r   rx  s    r,   _update_disable_jit_globalr  z  s    +.#+(((r.   c                L    | t           j                                        _        d S r7   )r   r   r   r   rx  s    r,    _update_disable_jit_thread_localr  }  s    14#+  ""...r.   jax_disable_jitz6Disable JIT compilation and just call original Python.jax_numpy_rank_promotion)r  r  raisezXControl NumPy-style automatic rank promotion broadcasting ("allow", "warn", or "raise").c                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    C888 r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    #=== r.   jax_default_matmul_precision)r   highhighestbfloat16tensorfloat32float32aK  Control the default matmul and conv precision for 32bit inputs.

Some platforms, like TPU, offer configurable precision levels for matrix multiplication and convolution computations, trading off accuracy for speed. The precision can be controlled for each operation; for example, see the :func:`jax.lax.conv_general_dilated` and :func:`jax.lax.dot` docstrings. But it can be useful to control the default behavior obtained when an operation is not given a specific precision.

This option can be used to control the default precision level for computations involved in matrix multiplication and convolution on 32bit inputs. The levels roughly describe the precision at which scalar products are computed. The 'bfloat16' option is the fastest and least precise; 'float32' is similar to full float32 precision; 'tensorfloat32' is intermediate.

c                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    <<< r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    #SAAA r.   jax_traceback_filtering)r%   tracebackhideremove_framesquiet_remove_framesautor  ax  Controls how JAX filters internal frames out of tracebacks.

Valid values are:
 * "off": disables traceback filtering.
 * "auto": use "tracebackhide" if running under a sufficiently new IPython, or "remove_frames" otherwise.
 * "tracebackhide": adds "__tracebackhide__" annotations to hidden stack frames, which some traceback printers support.
 * "remove_frames": removes hidden frames from tracebacks, and adds the unfiltered traceback as a __cause__ of the exception.
 * "quiet_remove_frames": removes hidden frames from tracebacks, and adds a brief message (to the __cause__ of the exception) describing that this has happened.
jax_bcoo_cusparse_loweringz&Enables lowering BCOO ops to cuSparse.jax_dynamic_shapesJAX_DYNAMIC_SHAPESzOEnables experimental features for staging out computations with dynamic shapes.c                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    c222 r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    #3777 r.   jax_remat_opt_barrierz9Enables using optimization-barrier op for lowering remat.jax_eager_pmapz9Enable eager-mode pmap when jax_disable_jit is activated."jax_custom_vjp_disable_shape_checkz>Disable the check from #19009 to enable some custom_vjp hacks.*jax_experimental_unsafe_xla_runtime_errorsa  Enable XLA runtime errors for jax.experimental.checkify.checks on CPU and GPU. These errors are async, might get lost and are not very readable. But, they crash the computation and enable you to write jittable checks without needing to checkify. Does not work under pmap/pjit.r   zOptional profile version for XLA compilation. This is meaningful only when XLA is configured to support the remote compilation profile feature.c                "    t          |           S N)rJ  r  rx  s    r,   rl   rl     s    #;$! $! $! r.   c                "    t          |           S r  r  rx  s    r,   rl   rl     s    )F*! *! *! r.   Iterator[None]c               #  |   K   t          j                    } | j        }d| _        	 dV  || _        dS # || _        w xY w)zEIndicates that the current context is an explicit device_put*() call.TN)r   r   explicit_device_putstateprevs     r,   explicit_device_put_scoper    V       
/
1
1%		"$"%%	EEE $EE$$$$   2 	;c               #  |   K   t          j                    } | j        }d| _        	 dV  || _        dS # || _        w xY w)zDIndicates that the current context is an explicit device_get() call.TN)r   r   explicit_device_getr  s     r,   explicit_device_get_scoper  	  r   r  c                   |t          | |d           dS |dk    r"t          | |t          j        j                   dS |dk    r"t          | |t          j        j                   dS |dk    r"t          | |t          j        j                   dS |dk    r"t          | |t          j        j                   dS |dk    r"t          | |t          j        j                   dS J d|             )	z;Applies the transfer guard level within transfer_guard_lib.Nr  logdisallowlog_explicitdisallow_explicitFzInvalid transfer guard level )r   r   TransferGuardLevelALLOWLOGDISALLOWLOG_EXPLICITDISALLOW_EXPLICIT)r  keyr+   s      r,   _update_transfer_guardr    s   [E3
g~~E3*=CDDDDD
e||E3*=ABBBBB
jE3*=FGGGGG
nE3*=JKKKKK
!!!E3*=OPPPPP77#77777r.   !jax_transfer_guard_host_to_device)r  r  r  r  r	  zQSelect the transfer guard level for host-to-device transfers. Default is "allow".c                F    t          t          j                    d|           S Nhost_to_devicer  r   rM  rx  s    r,   rl   rl   /  $    #9'))+;S$B $B r.   c                F    t          t          j                    d|           S r  r  r   r   rx  s    r,   rl   rl   1  $    )?-//1A3*H *H r.   #jax_transfer_guard_device_to_devicezSSelect the transfer guard level for device-to-device transfers. Default is "allow".c                F    t          t          j                    d|           S Ndevice_to_devicer  rx  s    r,   rl   rl   >  s$    #9'))+=s$D $D r.   c                F    t          t          j                    d|           S r  r  rx  s    r,   rl   rl   @  s$    )?-//1CS*J *J r.   !jax_transfer_guard_device_to_hostzQSelect the transfer guard level for device-to-host transfers. Default is "allow".c                F    t          t          j                    d|           S Ndevice_to_hostr  rx  s    r,   rl   rl   M  r  r.   c                F    t          t          j                    d|           S r"  r  rx  s    r,   rl   rl   O  r  r.   c                F    dD ]}t                               ||            d S )N)r  r  r   )r   rP   )r+   rO   s     r,   !_update_all_transfer_guard_globalr&  R  s6    4  d MM$ r.   jax_transfer_guardzSelect the transfer guard level for all transfers. This option is set-only; the transfer guard level for a specific direction should be read using the per-transfer direction option. Default is "allow".)rO   r   r   r   r   r   c              #  z  K   t          j                    5 }|                    t          |                      |                    t	          |                      |                    t          |                      |                    t          |                      dV  ddd           dS # 1 swxY w Y   dS )a
  A contextmanager to control the transfer guard level for all transfers.

  For more information, see
  https://jax.readthedocs.io/en/latest/transfer_guard.html

  Args:
    new_val: The new thread-local transfer guard level for all transfers.

  Yields:
    None.
  N)r   	ExitStackenter_contexttransfer_guard_host_to_devicetransfer_guard_device_to_devicetransfer_guard_device_to_host_transfer_guard)r   stacks     r,   transfer_guardr0  f  s        
	5g>>???	7@@AAA	5g>>???	00111	EEE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   BB00B47B4module_names_strc                    t          j                     | sd S |                     d          }|D ]}t          j        |           d S )N,)r   disable_all_debug_loggingsplitenable_debug_logging)r1  module_namesmodule_names      r,   _update_debug_log_modulesr9  {  s^    *,,,	 
F!'',,,! 5 5k'44445 5r.   jax_debug_log_moduleszyComma-separated list of module names (e.g. "jax" or "jax._src.xla_bridge,jax._src.dispatch") to enable debug logging for.)rO   r   r   r   jax_pmap_no_rank_reductionzCIf True, pmap shards have a the same rank as their enclosing array.jax_use_shardy_partitionerzWhether to lower to Shardy. Shardy is a new open sourced propagation framework for MLIR. Currently Shardy is experimental in JAX. See www.github.com/openxla/shardyc                "    t          |           S N)r   r  rx  s    r,   rl   rl     s    #;"$ $ $ r.   c                "    t          |           S r>  r  rx  s    r,   rl   rl     s    )F"* * * r.   )r   r   r   r   r   r   )r   r   r   r/   r   r/   )rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rO   r   r   r   r   r   r   r   r   r   r   r   r   r   )rO   r   r   r   r   r  r   r   r   r   r   r   r   r  )rO   r   r   r/   r   r   r   r  r   r  r   r  )rO   r   r   rq   r   r   r   r  r   r  r   r  )rO   r   r   r   r   r   r   r   r   r   r   r   )rO   r   r   r  r   r   r   r   r   r   r   r  )rO   r   r   r   r   r   r   r   r   r   r   r   r   r)  )r   r3  )r   r;  )r   r?  )r   rB  )r   r  )r   r   r   r  )r1  r  )
__future__r   collections.abcr   r   r   r   r   r[  r   loggingr'   r   	threadingtypingr   r	   r
   r   r   r   r   jax._srcr   jax._src.libr   r   r   r   	getLoggerr=   r  r   r-   r1   r3   rC   r   r   rR   rP   r   r   r   r   r   localr   r   r   r   r   r  r  r  r  r%  r(  r#  r-  r:  r=  rA  rD  rF  r   rH  rQ  rS  rV  r_  ra  rb  rc  re  rg  #export_ignore_forward_compatibilityrl  rm  enable_checksr   check_tracer_leakspartialchecking_leaks
debug_nans
debug_infslog_compilesexplain_cache_misseslog_checkpoint_residualspmap_shmap_mergery  r{  r   	spmd_modedistributed_debugr   legacy_prng_keyenable_custom_prngdefault_prng_implr   r   r   %enable_custom_vjp_by_custom_transposeraise_persistent_cache_errors&persistent_cache_min_compile_time_secs%persistent_cache_min_entry_size_bytes)compilation_cache_include_metadata_in_keyr   $include_full_tracebacks_in_locationstraceback_in_locations_limit#share_autotune_config_between_hostsshare_binary_between_hosts%share_binary_between_hosts_timeout_msr   r   pgle_aggregation_percentileenable_compilation_cachecompilation_cache_dircompilation_cache_max_sizedefault_dtype_bitsr   r  r  r   rI   remover   r   r  r  r  r   r  r  r   r   r   traceback_filteringbcoo_cusparse_loweringr   r(   r   remat_opt_barrier
eager_pmapcustom_vjp_disable_shape_checkxla_runtime_errorsr   r   r  r  r  r+  r,  r-  r&  r.  r0  r9  pmap_no_rank_reductionr   r8   r.   r,   <module>rp     sH   # " " " " " B B B B B B B B B B B B              				 



     N N N N N N N N N N N N N N N N N N                   + + + + + + # # # # # # # # # # # #		8	$	$WT]]Q Q Q Q(/ / / /

) 
) 
) 
) 
)(2, 
) 
) 
)s* s* s* s* s* s* s* s*l( ( (B 
	4         Y[[
        %io'' Q$ Q$ Q$ Q$ Q$GBK Q$ Q$ Q$jH  )  9=EIL L L L L Lj 8<DH6 6 6 6 6 6~ ?CDH3 3 3 3 3 3v 8<DH, , , , , ,h :>FJ- - - - - -j 8<DH) ) ) ) ) )b 8<DH) ) ) ) ) )` 8<=A.2+ + + + + +\    72;   4                 % ' ' ' ' 'Z ' ' '0 0 0" " " " "* " " ">
> 
> 
> 
> 
>Y_ 
> 
> 
> 3244 F F F &0Z	-	5	& & & " '1j	.H:DAA	K		' 	' 	' # &I	$G/33@	    )2		0
 G;Q??	g) ) ) % '1j	2H=uEE	q	' ' ' # &%				    "7!6	)J"L "L "L  
		MO O O
 *	SU U U  Z	!EG G G  #"#5t<<Z	$& & &
 Z	$& & &
 z	   "z	#*, , ,  &:	'    :		:	< < < 3 3 39 9 9 *2>,. . . J	k*?	
A 
A 
A	 J	     Y	!
K          *	***	    Z	!<	> > >  J	 5551	3 3 3  $	%$ $$ $% % %   *z	+* ** *	 + 	 + 	 +   Z	!C      
! 
! 
!  )3
	4F	)H )H )H % !+
	,! ! !  *5	5A*C *C *C & )2		4B	)D 	)D 	)D % -7J	8	+	
- 
- 
- ) *?)>	5* * * & (2z	3K	( ( ( $  )y	+		       '1j	2		' ' ' # (Z	)		    )2		4	1) ) ) % j	
 ML     i	"	      (i	*
    &:	'    .-	$M    'Y	)'
 
 
   Z	!t8	: : :  #
	$X&,: :? ?@ @ @ . . .4 4 4 Z		))57 7 7
   # #$4 5 5 5 xx(B(BCC D D D2 2 28 8 8
@ 
@ 
@ ('		N 5@&( ( (/ / /5 5 5 j	
B1=? ? ? "z	#***+9 9> >	? 	? 	?  /.	'VVVI = =B B-C C C 2 !j$  
   * $	%
25 5 5  	D/44553 38 89 9 9 J	 
EH H H  Z		D	F F F
 ",	-	I	"K "K "K   Z	5"    $)	"	! !! !    % % % % % % % %8 8 8" !4 3	,  
  B BH H!I !I !I  #6"5	.  
  D DJ J#K #K #K  !4 3	,  
  B BH H!I !I !I    &%	  
   9: : : 
 
 
 
(5 5 5 5 	  12 2 2 2 $	%M	    $	%	(       r.   