
    VpfBf                       d Z ddlmZ ddlZddlZddlmZmZmZ ddl	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mZm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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&ddl'Z( e(j)        dddii          Z*dZ+dZ, ej-                    Z.dZ/dZ0ddgZ1ddddddgZ2 G d de3          Z4dZ5 ej6        e7          Z8dbd%Z9d& Z:d' Z;dcd*Z<ddded.Z=dfd2Z> G d3 d4          Z?dgd8Z@de*dddfdhd?ZAd@ ZBdidEZCddde*d+fdjdNZD	 	 	 dkdldYZEdmd[ZF G d\ d]ejG                  ZH G d^ d_          ZI G d` daeIeH          ZJdS )nz(Array serialization and deserialization.    )annotationsN)	AwaitableCallableSequence)partial)AnyOptional)array)config)distributed)sharding)sharding_impls)LayoutDeviceLocalLayout)typing)util)xla_extensionfile_io_concurrencylimit   zValue removedcheckpoint_write_successfileziPlease initialize the distributed system via `jax.distributed.initialize()` at the start of your program.gs://zs3://gcs)driver
path_regexs3c                      e Zd ZdS )BarrierTimeoutExceptionN)__name__
__module____qualname__     r/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/experimental/array_serialization/serialization.pyr   r   ;   s        $r$   r   zSuggestions for possible fixes:
* Check the logs to see if one or more processes failed.
* Make sure the training and checkpointing endpoints are close geographically.
* Try increasing the timeout you pass to GlobalAsyncCheckpointManager.global_shapearray.Shapeinp_shardingjax.sharding.Shardingdata_callback9Callable[[array.Index, jax.Device], Awaitable[jax.Array]]c                   K   |                     |           |j        }fd|D             }t          j        |  d {V }t	          j        | ||          S )Nc                4    g | ]} |         |          S r#   r#   ).0dr*   device_to_index_maps     r%   
<listcomp>z4create_async_array_from_callback.<locals>.<listcomp>N   s;     , , , !=!4Q!7;; , , ,r$   )devices_indices_map_addressable_device_assignmentasynciogatherr
   $make_array_from_single_device_arrays)r&   r(   r*   addressable_dafuture_arraysdbsr0   s     `   @r%    create_async_array_from_callbackr:   G   s      
 %88FF>., , , , ,*, , ,-nm,,,,,,,#		3L#
' 
' 'r$   c                    |                      d          j        }ddi| j        t          j        t          j        d|                    dS )Nr   idzstd   )
compressorshapechunks)addressable_datar@   npr
   maximum)arrlocal_shapes     r%   _get_metadatarG   U   sL    $$Q''-+6NyA{3344
 
 r$   c                    t          | t                    sdS d| v p*t          d |                                 D                       S )NFmetadatac              3  :   K   | ]\  }}t          |          V  d S N)_spec_has_metadata)r.   _subtrees      r%   	<genexpr>z%_spec_has_metadata.<locals>.<genexpr>a   sH       #B #B&0a!!#B #B #B #B #B #Br$   )
isinstancedictanyitems)trees    r%   rL   rL   ^   sd    	D$		 5	t	 
Bs #B #B48JJLL#B #B #B  B  B Br$   	ckpt_pathstrc                    t          j        d| t           j                  }|t          d|            |                    d          }|                    d          }d||dS )Nz^gs://([^/]*)/(.*)$zWThe ckpt_path should contain the bucket name and the file path inside the bucket. Got: r>      r   )r   bucketpath)re	fullmatchDOTALL
ValueErrorgroup)rU   m
gcs_bucketpath_without_buckets       r%   _get_kvstore_for_gcsrc   d   sw    l()RY??!Y
 G;DG G H H Hwwqzz*

Z9L	M	MMr$   Focdbtboolc                   t           j                            |                               dd          } |                     d          }di d}|r|s1t           j                            |           st          d|            t           j                            |           }d|r|nt           d| t           j        	                    |           d|d	<   n"|rt          |           |d	<   nt          | d
|d	<   |S )Nzgs:/r   zarr)r   kvstorez(Checkpoint path should be absolute. Got rd   z://)r   baserZ   rh   )r   rZ   )osrZ   normpathreplace
startswithisabsr^   dirname_DEFAULT_DRIVERbasenamerc   )rU   rd   is_gcs_pathspec	base_paths        r%   get_tensorstore_specru   m   s    gy))11&'BB)$$W--+r	*	*$
 G Orw}}Y77 OM)MMNNN	**I(P		.P.PY.P.P  ++ DOO  G,Y77d9oo#2IFFd9o	+r$   tspecdict[str, Any] | strreturnc                x   t          | t                    r5t          j        dd                    t
                     d|           rdS dS dD ]}|| v rt          | |                   c S d| v rKt          D ]C}| d         |d         k    r/|d          dS t          j        |d         | d
                   r dS DdS )zDetect if user is using cloud storages.

  This can detect common defines and unable to detect some corner cases such as
  using gcsfuse.
  z^(|)TF)ri   rh   r   r   NrZ   )rP   rV   r[   matchjoin_REMOTE_URL_PREFIXESis_remote_storage_REMOTE_DRIVER_VALIDATIONS)rv   keyrules      r%   r   r      s     s 	x7chh344777?? TU  + +c
e||uSz*****  *  	xDN	*	*% 8D&f66 		r$   c                  $    e Zd ZdZd Zd Zd ZdS )_LimitInFlightByteszDLimits in-flight bytes when reading/writing checkpoints per process.c                x    || _         || _        t          j        t          j                              | _        d S )N)lock)
_max_bytes_available_bytesr4   	ConditionLock_cv)self	num_bytess     r%   __init__z_LimitInFlightBytes.__init__   s0    DO%D glnn555DHHHr$   c                @   K    j         k    rt          d d j                     j        4 d {V   j                             fd           d {V   xj        z  c_         j        dk    sJ 	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nz1Requested more bytes than we reserved space for: z > c                     j          k    S rK   )r   )requested_bytesr   s   r%   <lambda>z4_LimitInFlightBytes.wait_for_bytes.<locals>.<lambda>   s    d&;o&M r$   r   )r   r^   r   wait_forr   r   r   s   ``r%   wait_for_bytesz"_LimitInFlightBytes.wait_for_bytes   sv     (( @)@ @.2o@ @ A A Ax ( ( ( ( ( ( ( (HMMMMMNNNNNNNNN
."a'''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   AB
BBc                   K   | j         4 d {V  | xj        |z  c_        | j        | j        k    sJ | j                                          d d d           d {V  d S # 1 d {V swxY w Y   d S rK   )r   r   r   
notify_allr   s     r%   release_bytesz!_LimitInFlightBytes.release_bytes   s
     x        
."do5555
h                             s   <A
A),A)N)r    r!   r"   __doc__r   r   r   r#   r$   r%   r   r      sG        LL6 6 6
( ( (    r$   r   shardarray.Shard
np.ndarrayc                  K   | j         }t          d | j                                        D                       }t          j        j        r>|r<t          j        	                    | j        d          }t          j
        ||          }n|                                 t          j        d           d {V  t          j        |d          S )Nc              3  ,   K   | ]}|j         d k    V  dS )pinned_hostN)kind)r.   r`   s     r%   rO   z)transfer_shard_to_host.<locals>.<genexpr>   sB       L L"#afL L L L L Lr$   r   )memory_kindr   F)copy)datarR   deviceaddressable_memoriesr   enable_memoriesvaluejaxr   SingleDeviceSharding
device_putcopy_to_host_asyncr4   sleeprC   r
   )r   r   has_pinned_hostr   s       r%   transfer_shard_to_hostr      s      	$ L L',|'H'H'J'JL L L L L/! o |00! 1 # #H>$))DDa 
$U	#	#	##r$   primary_host
int | None
replica_idinttransactionOptional[ts.Transaction]c                &   K   t           t          j                  r=t          j                    dk    r& j        rt          d|d         d          d          t          |          st                     |d<   d|vr!t          j
         j
                  j        |d<   |t          j                    |k    rbt          j        t          j        |          d	d	||
          }-t          t                     sJ                     |           n| d{V  t          j        t          j        |          d	d	||           d{V  fd} j        }	t          j                            ||	          }
t+          j        |
  d{V S )a[  Serialize an array using TensorStore.

  Args:
    arr_inp: The array to serialize.
    tensorstore_spec: The tensorstore spec to use.
    commit_future: A list of futures that will be appended to. The futures can
      be awaited asynchronously. If None, the futures will be awaited
      synchronously by this method.
    context: ts.Context instance.
    primary_host: Primary host, which indicates the host that will be treated as
      the "leader". If None, all hosts are treated as the primary. DO NOT USE
      unless you are sure you know what you are doing.
    replica_id: Allows overriding the shard replica id that will be saved. DO
      NOT USE unless you are sure you know what you are doing.
    transaction: TensorStore transaction to use for opening and writing the
      array.  If not specified, a non-transactional write will be used.
  r>   zPassing fully addressable arrays to a multiprocess serialization is not allowed, as this may lead to a race condition between processes. Serialization have failed for the array with the path "rh   rZ   z".rI   dtypeNT)createopencontextr   )r   assume_metadatar   r   c                b  K   | j         k    rt          |            d {V }| j                                     |t	          t
          j                            }@t	          t                    sJ                     |j	                   |j
         d {V  d S |j	         d {V  d S d S )N)&can_reference_source_data_indefinitely)r   r   indexwriterP   r
   	ArrayImpllistappendcommitr   )r   r   write_futurearr_inpcommit_futurer   ts      r%   _write_arrayz%async_serialize.<locals>._write_array  s      :%%)%00000000du{^))
 2<u2 2 * 
 
l 
	"-.....\0111!!!!!!!!!!% &%r$   )rP   r
   r   r   process_countis_fully_addressabler^   rL   rG   jnpr   nameprocess_indextsr   Specr   r   addressable_shards	tree_utiltree_mapr4   r5   )r   tensorstore_specr   r   r   r   r   open_futurer   local_shardsfuture_write_stater   s   ` `  `     @r%   async_serializer      s     4 %/** >s/@/B/BQ/F/F" 0G
	= &i08	= 	= 	=> > > 
,	-	- :#0#9#9Z  $$$ #	'- 8 8 =W S.00L@@'
 !!  K  t,,,,,;'''' Gg        !" " " " " " " "* +,}--lLII~12	2	2	2	2	2	22r$   c                N      fd}t          j         |                       d S )Nc                 |   K   t           j                            t                    } t	          j        |   d {V S rK   )r   r   r   r   r4   r5   )future_writerarraystensorstore_specss    r%   _run_serializerz*run_serialization.<locals>._run_serializer4  s@      M**?FDUVVM////////r$   r4   run)r   r   r   s   `` r%   run_serializationr   3  sB    0 0 0 0 0 0 
+oo     r$   r   ts.TensorStoredomaints.IndexDomainc                   | j         }| j        j        j        }| j        j        }|| j        }|j        }|j        }|j        }|j        }t          |          D ]}	||	         j
        s|j        |z  c S t          |          D ]G}	||	         }
||	         }||	         }|
|z
  }|
||	         z   |z
  }||z  |z  }| |z   |z  }|||z
  z  }H|S rK   )rankr   numpy_dtypeitemsizechunk_layoutread_chunk_templater   originr@   rangefinitesize)r   r   r   r   chunk_templater   r@   chunk_originchunk_shapeiorigin_valuechunk_origin_value
chunk_sizelowerupperlower_alignedupper_aligneds                    r%   estimate_read_memory_footprintr   :  s   	
$g!*)>5.^XF=&
,%&,$+
 ;; % %a!# %[9$$$$% ;; 1 1a!9L%aQJ--E58#&88EZ'*4Mf
*+j8M--/0II	r$   user_in_shardingjax.sharding.Sharding | Layoutr   ts.Spec | dict[str, Any]Sequence[int] | Nonebyte_limiter_LimitInFlightBytes | Noner   c                  	
K   t          | t                    r| j        n| }t          |t          j        j                  st          d|           t          | t                    r| j        nd 	t          j        |d||           d {V |j	        n||
                    t                              
d		
fd}t          t                    ||           d {V S )
Nzqsharding passed to deserialization should be specified, concrete and an instance of `jax.sharding.Sharding`. Got T)r   r   r   r   array.Indexr   
jax.Devicec           	       K   t          j                  |          j        }j                            |          }t	          |          }                    |           d {V  t          j        
j        j	                  }t          j
        |          t           j        d d          j        |j                          |                             |                    d {V  	|                    	          }|j        t           j        k    rt!          j        |          }t'          j        |t+          t&          j                            |                              }                    |           d {V  |S )N)input_shape)r   )r   IndexTransformr   	intersectr   r   rC   zerosr   r   r
   r/   translate_tor   r   astyper   int4asarrayr   r   r   r   r   r   )r   r   requested_domainrestricted_domainr   outresultr   dllr   new_shard_shaper@   r   s          r%   cbzasync_deserialize.<locals>.cbu  s     (U;;;EBI**+;<<4Q8IJJO''888888888 (?!'*=
>
>
>C
(3--QQQ,-=-DE
F 5#4!5667 7 7 7 7 7 7 JJuc
 yCHKc^VC::6BBCCE EF &&777777777Mr$   )r   r   r   r  )rP   r   r   r   Shardingr^   device_local_layoutr   r   r@   shard_shapetupler:   )r   r   r&   r   r   r   r   in_shardingr  r  r  r@   r   s      ``    @@@@r%   async_deserializer  [  sj      /88O!**>N 	K!6	7	7 G
	F8C	F 	FG G G '00
;		-	-6: G%	        ! ")!''|%++E%LL99/% % % % % % % % % % %N 0ek2NN	N	N	N	N	N	NNr$       	shardings$Sequence[sharding.Sharding | Layout]r   Sequence[dict[str, Any]]global_shapesSequence[array.Shape] | Nonedtypes!Sequence[typing.DTypeLike] | Noneconcurrent_gbc                `     |dz   fd}t          j         |                      S )Ni ʚ;c            
       K   t                    } t          j                            t	          t
          |           d gt                    z  nd gt                    z  n          }t          j        |  d {V S )N)r   )	r   r   r   r   r   r  lenr4   r5   )r   r8   concurrent_bytesr  r  r  r   s     r%   _run_deserializerz.run_deserialization.<locals>._run_deserializer  s      &'788LM**!===$+8+@&''''m+1>&''''v	G GM
 ////////r$   r   )r  r   r  r  r   r%  r$  s   ````  @r%   run_deserializationr&    s]    
 #U*	0 	0 	0 	0 	0 	0 	0 	0 	0 
&&((	)	))r$   r   c                    d|  S )Ntensorstore_checkpoint_r#   )r   s    r%   _get_keyr)    s    	(3	(	((r$   c                      e Zd ZdZej        d             Zej        d             Zej        dd            Zej        	 	 ddd            Z	dS ) GlobalAsyncCheckpointManagerBasea&  Interface for checkpointing GDAs asynchronously.

  This class manages the state of an ongoing asynchronous checkpoint.

  For example, say a checkpoint happens on every step. If you checkpoint on
  step 1 and after some computation the model is on checkpoint 2. But step 1's
  checkpoint hasn't finished committing to the storage layer yet. So until that
  is finished, checkpoint for step 2 will need to be blocked. Maintaining a
  class allows to maintain that state.

  Examples:

  Below is a simplified training loop:

  ```
  # Call this at the start of your program.
  jax.distributed.initialize()

  manager = GlobalAsyncCheckpointManager()

  # Restore checkpoint if available or initialize the train_state from
  # init_fn().
  train_state = manager.deserialize(...)

  while ...:
    if step % num_steps_between_checkpoints == 0:
      manager.serialize(train_state, temp_checkpoint_dir=...,
                        final_checkpoint_dir=...)
      train_state = train_step(train_state, input)
      # This is a non-blocking call.
      manager.check_for_errors()

  manager.serialize(train_state, temp_checkpoint_dir=...,
                    final_checkpoint_dir=...)
  # Wait before the end of the program for the checkpoint to finish. This is a
  # blocking call.
  manager.wait_until_finished()
  ```
  c                    dS )zChecks if any errors have been raised in the child thread.

    This is a non-blocking call that can be called in the main thread.
    Nr#   r   s    r%   check_for_errorsz1GlobalAsyncCheckpointManagerBase.check_for_errors        r$   c                    dS )z(Blocks until serialization has finished.Nr#   r-  s    r%   wait_until_finishedz4GlobalAsyncCheckpointManagerBase.wait_until_finished  r/  r$   on_commit_callbackCallable[[], None]c                   dS )zSerializes GDAs to TensorStore.Nr#   )r   r   r   r2  s       r%   	serializez*GlobalAsyncCheckpointManagerBase.serialize  r/  r$   Nr  Sequence[sharding.Sharding]r   r  r  r  r  r  c                    dS )z#Deserializes GDAs from TensorStore.Nr#   )r   r  r   r  r  s        r%   deserializez,GlobalAsyncCheckpointManagerBase.deserialize  r/  r$   )r2  r3  )NN)r  r6  r   r  r  r  r  r  )
r    r!   r"   r   abcabstractmethodr.  r1  r5  r8  r#   r$   r%   r+  r+    s        & &P    3 3 3 * * * *  AE>B. . . . . . .r$   r+  c                  <    e Zd ZddZd Zd Zd Zd Zd Zdd
Z	dS )AsyncManager,  c                <   || _         | j         dz  | _        d | _        d | _        d | _        t          j                    dk    r%t          j        j	        t          t                    t          j                    dk    rt          j        j	        | _        d | _        d S )Ni  r>   )_timeout_secs_timeout_in_ms_commit_futures_thread
_exceptionr   r   r   global_stateclientr^   _DISTRIBUTED_SYSTEM_MSG_client_count)r   timeout_secss     r%   r   zAsyncManager.__init__  s    %D,t3DDDLDO
Q;#;#B#J.///
Q -4dlDKKKr$   c                    | j         5| j                                         rt                              d           d S d S d S )NzPlease add `.wait_until_finished()` in the main thread before your program finishes because there is a possibility of losing errors raised if the this class is deleted before writing is completed.)rB  is_aliveloggerwarningr-  s    r%   __del__zAsyncManager.__del__  sV    |DL$9$9$;$;nn K L L L L L  r$   c                   	 t          j                    }t          j                    }t                              d|           t          j                    }| j        D ]}|                                 t                              d|           |dk    rkt          | j	                  }t                              d||           | j
                            || j                   t                              d|           |dk    ro|                                  t                              d           |dk    r;| j
                            |t                     t                              d|           t           j                            d	t          j                    |z
             d S # t$          $ r}|| _        Y d }~d S d }~ww xY w)
Nz/Starting commit to storage layer by process: %sz3Finished committing to storage layer by process: %sr>   z)Key used for barrier is %s for process %sz*Finished waiting at barrier for process %sr   z$on_commit_callback successfully ran!z1Process 0 successfully set key %s in the kv storez//jax/checkpoint/write/async/thread_duration_sec)r   r   r   rL  infotimerA  r  r)  rH  rG  wait_at_barrierr@  _on_commit_callbackkey_value_set_CHECKPOINT_SUCCESS
monitoringrecord_event_duration_secs	ExceptionrC  )r   current_processr   thread_start_timefuturekey_for_barrieres          r%   _thread_funczAsyncManager._thread_func  s   ")++o'))mkkC"$ $ $)++(  &kkG"$ $ $ 
		 #4;//?#_	6 	6 	6$$_d6IJJJ@#	% 	% 	% 
A		  """:;;;1
,
$
$_6I
J
J
J
++I%' ' ' 
n//
;
)++)
)+ + + + +    dooooooos   F'F+ +
G5GGc                    t          t                    | _        || _        t	          j        | j                  | _        | j                                         d S )N)target)	next_module_unique_countrH  rS  	threadingThreadr^  rB  start)r   r2  s     r%   _start_async_commitz AsyncManager._start_async_commit4  sL    +,,DK1D#4+<===DLLr$   c                    | j         q| j         }d | _         t          |t          j                  rGdt	          |          v r6t          d                    t	          |          t          g                    |d S )Nz$DEADLINE_EXCEEDED: Barrier timed out
)rC  rP   xeXlaRuntimeErrorrV   r   r}   _BARRIER_TIMED_OUT_MSG)r   	exceptions     r%   r.  zAsyncManager.check_for_errors;  s|    "/ido
Y 2
3
3 A
0C	NN
B
B%IIs9~~'=>??A A 	Ao #"r$   c                   | j         :| j                                          d | _         t                              d           |                                  t                              d           t          j                    dk    rX| j        St          | j                  }| j	        
                    || j                   t                              d|           d S d S d S )NzThread joined successfullyz!Error check finished successfullyr>   z<blocking_key_value_get on key %s was successfully completed.)rB  r}   rL  rP  r.  r   r   rH  r)  rG  blocking_key_value_getr@  )r   get_keys     r%   r1  z AsyncManager.wait_until_finishedF  s    |
ldlkk.///
KK3444
Q4;#: %%g
l))'43FGGGkk  ') ) ) ) ) #:#:r$   futuresSequence[asyncio.Future]c                    || _         d S rK   )rA  )r   rp  s     r%   _add_futureszAsyncManager._add_futuresW  s    "Dr$   N)r=  )rp  rq  )
r    r!   r"   r   rN  r^  rf  r.  r1  rs  r#   r$   r%   r<  r<    s           L L L# # #J  	 	 	) ) )"# # # # # #r$   r<  c                  N    e Zd ZdZddddZddddZ	 	 	 dddZ	 	 	 dddZdS )GlobalAsyncCheckpointManagerz1Responsible for serializing GDAs via TensorStore.N)r   r   r   c               
   t                               d           |                                  g fd}t          j         |                       |                                |                     |           dS )a  Serializes Arrays or Arrays via TensorStore asynchronously.

    TensorStore writes to a storage layer in 2 steps:
    *  Reading/copying from the source after which the source can be modified.
         * Returns a copy future.
    *  Writing/committing to the storage layer.
         * Returns a commit future.

    In asynchronous mode, the serialization waits for the commit future to
    finish in a separate thread allowing other computation to proceed.

    Args:
      arrays: Arrays or Arrays that should be serialized.
      tensorstore_specs: TensorStore specs that are used to serialize GDAs or
        Arrays.
      on_commit_callback: This callback will be executed after all processes
        have finished writing their checkpoints to disk. Filesystems where
        atomic rename operations are supported, you can rename from the
        temporary directory to the final directory. On GCS, you write to the
        final directory directly and in `on_commit_callback` you write a success
        file indicating that the serialization was successful because GCS does
        not support atomic rename operations.
      transaction: Optional TensorStore transaction to use.
    z-Waiting for previous serialization to finish.c                 z   K   t           j                            fd          } t          j        |   d {V S )Nc                *    t          | |          S )N)r   r   )r   )r   r   commit_futuresr   s     r%   r   zQGlobalAsyncCheckpointManager.serialize.<locals>._run_serializer.<locals>.<lambda>  s"    O*%	- - - r$   )r   r   r   r4   r5   )r   r   ry  r   r   s    r%   r   z?GlobalAsyncCheckpointManager.serialize.<locals>._run_serializer  s`      m,,     
	 	m >=11111111r$   N)rL  rP  r1  r4   r   rs  rf  )r   r   r   r2  r   r   ry  s    `` ` @r%   r5  z&GlobalAsyncCheckpointManager.serialize^  s    @ KK?@@@&(N2 2 2 2 2 2 2 2 K!!"""n%%% 	/00000r$   r   Sequence[jax.Array]pathsSequence[str]c                   t           j                            t          |          }|                     ||||           d S )N)r2  r   )r   rT   mapru   r5  )r   r   r{  r2  r   tspecss         r%   serialize_with_pathsz1GlobalAsyncCheckpointManager.serialize_with_paths  sK     X\\.66FNN-	      r$   r  r  r  r   r  r  r  r  r  r   r   c                P    |                                   t          |||||          S rK   )r1  r&  )r   r  r   r  r  r   s         r%   r8  z(GlobalAsyncCheckpointManager.deserialize  s7    
 	y*;,fmE E Er$   r6  c                ~    t           j                            t          |          }|                     |||||          S rK   )r   rT   r~  ru   r8  )r   r  r{  r  r  r   r  s          r%   deserialize_with_pathsz3GlobalAsyncCheckpointManager.deserialize_with_paths  s=     X\\.66FIv}f)+ + +r$   )r   r   )r   rz  r{  r|  r   r   NNr  
r  r  r   r  r  r  r  r  r   r   )
r  r6  r{  r|  r  r  r  r  r   r   )r    r!   r"   r   r5  r  r8  r  r#   r$   r%   ru  ru  [  s        99 /381 81 81 81 81 81@ /3     $ AE>B')	E E E E E 5926+ + + + + + +r$   ru  )r&   r'   r(   r)   r*   r+   )rU   rV   )F)rU   rV   rd   re   )rv   rw   rx   re   )r   r   rx   r   )r   r   r   r   r   r   )r   r   r   r   rx   r   )
r   r   r   r   r&   r   r   r   r   re   r  r  )r   r   )Kr   
__future__r   r9  r4   collections.abcr   r   r   	functoolsr   	itertoolsloggingrj   r[   rc  rQ  r   r   r	   r   jax._srcr
   r   r   r   r   jax._src.layoutr   r   DLLr   jax._src.libr   ri  	jax.numpynumpyr   rC   tensorstorer   Context
TS_CONTEXT_REMOVED_VALUErU  countrb  rp   rF  r~   r   rX  r   rk  	getLoggerr    rL  r:   rG   rL   rc   ru   r   r   r   r   r   r   r  r&  r)  	StrictABCr+  r<  ru  r#   r$   r%   <module>r     sd   / . " " " " " " 



  9 9 9 9 9 9 9 9 9 9            				 				                      



                               # # # # # # < < < < < < < <             , , , , , ,               RZ.#?@@
 0 &y(( C   ) D))4(( 
    i   M  
	8	$	$' ' ' '  B B BN N N N    0   >       0$ $ $ $,  ,0a3 a3 a3 a3 a3H! ! !   H *.
/3!AO AO AO AO AOL GKDH-/	* * * * *() ) ) )>. >. >. >. >.t~ >. >. >.B`# `# `# `# `# `# `# `#F^+ ^+ ^+ ^+ ^+<1Q ^+ ^+ ^+ ^+ ^+r$   