
    uki#                   b   U d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	m
Z
 d dlmZ d dlZd dlZd dlZd dlmZmZmZ d dlZd dlZd dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ  d dlm!Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z= d dl>m?Z? d dl;m@Z@ d dl;mAZA d d l;mBZB d d!l;mCZC d d"lDmEZE d d#lFmGZH d d$lImJZJ d d%lImKZL d d&lMmNZN d d'lOmPZP d d(lQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ d d)l]m^Z^m_Z_m`Z`maZa d d*lbmcZc d d+ldmeZe d d,lfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZpmqZq d d-lrmsZs d d.ltmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZ evecZZewecZZ e(j                  e       eeSeXeVf   ZeeSeVf   ZeeReXeVf   ZeeReVf   Z ej                  e      Z G d/ d0e      Zdd1Zd2 Z	 	 	 	 dd3ZeLj"                  j%                  d45      ZeLj"                  j%                  d45      Zdd6Zdd7Zeedd8       Zeed9        Zeed:        Zd; Zd< Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd=Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd>Z G d? d@e      Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddAZ G dB dC      Ze*j                  	 	 	 	 	 	 	 	 	 	 	 	 ddD       Z	 	 	 	 	 	 	 	 	 	 ddEZ	 	 	 	 	 	 	 	 	 	 ddFZ	 	 ddGZ G dH dIe'jJ                        Z eeedJK      eWeWdddddLdddLdf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddM       ZdN ZdO ZdP ZdQ Z G dR dS      Z e*jZ                  dTdLU      	 	 ddV       Z e       ZdWedX<   	 	 	 	 	 	 	 	 ddYZ	 	 	 	 	 	 	 	 	 	 ddZZ ee jZ                  e[      	 	 	 	 	 	 	 	 	 	 dd]       Z e*jZ                  dTdLU      	 	 dd^       Z ejl                         Zdd_Zdd`Zda Z e	dbc       G dd d\             Z	 d	 	 	 	 	 	 	 ddeZ	 	 	 	 ddfZ ej|                  dg      Zdh e_        dbe_        dbe_        ddiZee_        dj Zee_        dk Zdl Z	 	 ddmZdn Zdo Z	 	 ddpZ	 	 	 	 ddrZ ejl                         Z e	dbc       G ds dt             Z e*jZ                  dTdLU      du        Zdv Z	 	 ddwZe{dx        ZddyZej                  eԫ       e{	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddz       Zd{ Zee=j                  e<   d| Zd} Zee=j                  e<   dd~Zd Zeej                  e<   d Zej                  e߫       	 	 	 	 	 	 ddZ	 	 ddZ eBj                  eedL       ddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZeeAj                  e<   	 	 	 	 	 	 ddZd Zee@j                  e<   d Zee@j                  e<   	 	 ddZee=j                  e<   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ ee=j                  dqe      e=j                  e<   d Ze{d        Zee@j                  e<   e{	 	 	 	 	 	 dd       Z	 	 ddZee=j                  e<   	 	 	 	 	 	 ddZeej                  e<   ddZddZd Zd Zd Z ej|                  d      Zej                  e        e@j                   ed        d Zej                  e       d Z eBj                  ee       d ZeeAj                  e<   d eAj
                  e<   d Z ej|                  d      Zdbe_        d Zej                  e       d Z	ej                  e	       d Z
 e@j                   ee
       d Zee@j                  e<   d Z eBj                  ee       d ZeeAj                  e<   d eAj
                  e<   	 d	 	 	 ddZddddddZd ZddddddZd Zd Z ej|                  d      Zej                  d         e@j                   ed        d Zej                  e       d Z eBj                  ee       d ZeeAj                  e<   d eAj
                  e<   ddZy)    )annotations)defaultdict)CallableSequenceIterable)	dataclassreplace)partialN)
NamedTupleAnyUnion)api)api_util)config)core)dispatch)dtypes)effects)linear_utilmesh)op_shardings)profiler)sharding_impls)source_info_util)stages)traceback_util)	tree_util)util)
xla_bridge)typeofcur_qdd)
argnums_partial_exceptflatten_axesflatten_fun3donation_vectorcheck_callableresolve_argnumsargnames_partial_except
debug_infocheck_no_aliased_ref_args"_check_no_aliased_closed_over_refs)partial_eval)PartitionSpec)ad)batching)mlir)pxla)ir)func)jax_jit)
xla_client)AbstractMesh)Sharding)NamedShardingGSPMDShardingSingleDeviceShardingPmapShardingAUTOUNSPECIFIEDUnspecifiedValueprepare_axis_resourcesparse_flatten_op_shardingcanonicalize_sharding_internal_use_concrete_mesh)FormatLayout
AutoLayoutget_layout_for_vmap)	RefEffect)api_boundary)
tree_flattentree_unflattentreedef_is_leaftree_structuretreedef_childrenprefix_errorskeystr	PyTreeDefnone_leaf_registrytree_map)	ArrayLike)HashableFunctionsafe_mapsafe_zipwrapsdistributed_debug_log
split_listweakref_lru_cachemerge_lists	subs_listfun_namefun_qual_namec                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   d
ed<   ded<   d
ed<   ded<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded <   d! Zd" Zy#)$PjitInfozThings that we know about a jit instance before it is called.

  In other words, this structure contains arguments to jit()/pjit(),
  preprocessed and validated.
  strfun_sourceinfozinspect.Signature | Nonefun_signaturebooluser_specified_in_shardingsrQ   in_shardings_treedeftuple[Any, ...]in_shardings_leavesout_shardings_treedefout_shardings_leavesin_layouts_treedefin_layouts_leavesout_layouts_treedefout_layouts_leavestuple[int, ...]static_argnumstuple[str, ...]static_argnamesdonate_argnumsdonate_argnamesxc.Device | Nonedevice
str | Nonebackendkeep_unusedinlineuse_resource_envtuple[tuple[str, Any], ...]compiler_options_kvsc                    t        |       S N)idselfs    H/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/pjit.py__hash__zPjitInfo.__hash__~   s    d8O    c                
    | |u S r    r   others     r   __eq__zPjitInfo.__eq__   s    5=r   N)__name__
__module____qualname____doc____annotations__r   r   r   r   r   ra   ra   _   s    
 ))  $#!!&&""''$$  %%!!""!!""

,33r   ra   c                   t        | |||      \  }}|D ]  }t        j                  |        	 t        j                         rt
        j                  j                  sm|j                  d   j                  j                  sJt        t        j                  |      }t        j                  |       t        |i |j                  \  }}}	}
n%t        j                   |i |j                  }d }d }	g }
tW        |jX                        }|||jX                  ||j                  d   	
fS # t"        j$                  $ rs}|j&                  \  }t)        | dt)        | dt+        |                   }t        t,        |      }t#        j.                  |||d|j0                        }t3        |      d d }~wt4        j6                  $ r}|j0                  dgt9        |      z  n|j0                  }|j                  d   j:                  rt=        |j&                  d         |t?        |||j@                        D ]d  \  }}}	 t5        jB                  |       # t4        j6                  $ r2}t=        d| d|jE                          d	tG        |       d
      |d }~ww xY w tI        d      |d }~wtJ        jL                  $ rV}t)        | dd      r&tO        d|jP                   d| jR                         d tK        jT                  || ||       Y d }~d }~ww xY w)Njaxprr   r   jit r   z
Argument 'z' of shape z	 of type z is not a valid JAX type.Unreachable_apply_primitiveFzinvalid value (z) encountered in )-_infer_paramsr   	check_argr   trace_state_cleanr   debug_key_reusevalueparamsr   is_highmap
full_lowercheck_eval_args_pjit_call_impl_pythonjit_pbindr   DeviceAssignmentMismatchErrorargsgetattrrb   convert_to_metaty!_device_assignment_mismatch_error	arg_names
ValueErrorr   InvalidInputExceptionlenconsts	TypeErrorzipin_avalscanonicalize_value	str_shorttypeAssertionErrorr   InternalFloatingPointErrorFloatingPointErrortyr   maybe_recursive_nan_checkrK   out_tree)funjit_infor   kwargsp	args_flatargout_flatcompiledr   
const_argsefailsr^   	arg_typesmsgr   nameaval_outss                        r   _python_pjit_helperr      s   sHdF;,!Y cs%= )?)?)E)E!''//dooy1i
9%1G2"2".h(J Y3!((3hhhj8 


H	-$
!**i
((7
Xx
= =9 
	-	- $VVFEsNGCSX,NOH%y1I

2
2%E1;;8C
S/t#		%	% 1)*)<s9~%!++IxxaffQi a' IqzzB ?/#tT	?

#
#C
(++ 	?4&DNN,<+= >s)578=>?	?? =)q0		,	, =s&.6GHXHXGYZ[aee&&q#tV<<=sW   C D& &L9A.F''L=A7J 5I
J J-JJJ  L6ALLc                T    | d uxr# | j                         xr | j                          S r   )
is_enabledis_fdo_consumed)pgle_profilers    r   _need_to_rebuild_with_fdor      s3    
t
# 2(@(@(B 2//113r   c                   | t        | t        j                        rt        | j                  t        j                        r| j                  j
                  s| j                  j                  sjt        d |D              sXt        j                  j                  rt        d g |||D              s%t        |      st        j                  j                  ry t        j                  ||      \  }}t        d |D              sy |D 	cg c]  }	|	j                   }
}	|D 	cg c]  }	|	j                    }}	t#        t%        |      t%        |      z         D cg c]  }|| j&                  v  }}t)        | j*                  | j,                        D cg c]]  \  }}|t.        j0                  urDt3        j4                  |j6                  t2        j8                        rt;        j<                  ||      n|_ }}}t        j>                  | j@                  ||| jB                  |
||| jD                  |	      S c c}	w c c}	w c c}w c c}}w )Nc              3  <   K   | ]  }t        |t                y wr   )
isinstancerH   ).0r   s     r   	<genexpr>z%_get_fastpath_data.<locals>.<genexpr>   s     7!Z9%7   c              3     K   | ]@  }t        |d       xr. t        j                  |j                  t        j                         B yw)dtypeN)hasattrr   
issubdtyper   prng_key)r   r   s     r   r   z%_get_fastpath_data.<locals>.<genexpr>   s>      /C 	WO&"3"3CIIv"OO/Cs   AAc              3  P   K   | ]  }t        |t        j                           y wr   )r   xc	ArrayImpl)r   xs     r   r   z%_get_fastpath_data.<locals>.<genexpr>   s     BQZ2<<(B   $&)#r   r2   MeshExecutableunsafe_callExecuteReplicatedordered_effectshas_unordered_effectsanyr   r   r   r   no_executionreflatten_outputs_for_dispatchallr   
_committedranger   _kept_var_idxr   _in_shardingsr   r   abstract_tokenr   r   r   extendedr   physical_shardingMeshExecutableFastpathDataxla_executable_out_shardings_dispatch_in_layouts)
executabler   r   r   r   consts_for_constvarsr   r   out_reflattenedo	out_avalsout_committedikept_var_bitvecsain_shardingss                    r   _get_fastpath_datar      s   
 
D$7$78
..0F0FG				/	/				5	5	7w7	7

 
 
&
&3 /CAYAA,@A/C ,C 
#=	1				"	""AA(HU/8	B/B	B./!qvv/)/)89A1<<9-9$S_s9~%EFH *222 H/ H j..
0C0CD	 !Q 
$%%	%&*;*;AGGV__*U &&q!,,  
	(	(<M?%%z
3 3 09Hs   H2!H7H<A"Ii    )capacityc                    | rt         S t        S r   )#_cpp_pjit_cache_explicit_attributes_cpp_pjit_cache_fun_only)contains_explicit_attributess    r   _get_cpp_global_cacher     s    !..##r   c                    t          fd       }t        j                  j                  j                  j
                  j                  j                  j                  j                  j                  j                  j                  j                  j                  j                        }t         j"                  j%                  t'                |j(                  j*                  |t,        j.                  t        j0                  t3        |j4                        	      } t7               |      } |_        |_        t=        |      }t>        |_         tB        |_"        tF        |_$        tJ        |_&        |S )Nc            
        t         j                  j                  rt        dj                   d      t        g| i |\  }}}}}}}}	t        |||||j                  |j                  ||	      }
||
t        |      fS )Nre-tracing function # for `jit`, but 'no_tracing' is set)
r   
no_tracingr   RuntimeErrorrc   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   maybe_fastpath_datar   r   s              r   
cache_missz_cpp_pjit.<locals>.cache_miss   s     /0G0G/H I: : ; ; /B	h/)/)!'/),T8Xy%
 -Hi5==%,,
 $&?&NNNr   )rt   ru   rw   ry   rg   ri   rj   rk   rl   rm   rn   ro   r~   )'rI   r2   JitGlobalCppCacheKeysrt   ru   rw   ry   rg   ri   rj   rk   rl   rm   rn   ro   r~   r   _xlapjitr^   rq   rs   r   dispatch_registrycc_shard_argr  r  rX   _fun	_jit_infor   jit_evict_fnclear_cache	jit_lowerlower	jit_tracetracejit_eval_shape
eval_shape)r   r   r  	cache_key
cpp_pjit_fcpp_pjitted_fcpp_jitted_f_classs   ``     r   	_cpp_pjitr"     sD   O O$ ((,,..__h&6&6#88"66$::#88!44 22"66!44#88:) ww||smS*h&=&=	9+F+F
IBBC	E* %*Z(--$-M*#/ &&"0	r   c                    t        | j                  | j                  ||      \  }}t        t        |      }t        j                  ||j                  |j                  |j                  |j                        S r   )r   r  r  r   r   r   Tracedr   in_treer   r   )jit_funcr   r   r   r   r   s         r   r  r  -  sT    x}}h.@.@$O,!Y#Y/)	y!((AIIqzz188	LLr   c                <    t        | g|i |j                         S r   )r  r  r&  r   r   s      r   r  r  3  s     	8	-d	-f	-	3	3	55r   c                4    t        | g|i |j                  S r   )r  out_infor(  s      r   r  r  7  s    	8	-d	-f	-	6	66r   c                    | j                          t        j                  | j                         t        j                          y r   )_clear_cache_create_pjit_jaxprevict_functionr  _infer_params_cachedcache_clearr   s    r   r  r  ;  s,    ##DII.""$r   c                   t        | d       \  }}g g }}|D ]  }t        |t              r7|j                  |j                         |j                  |j
                         Jt        |t        t        f      rt        d|       |j                  d        |j                  |        t        |      t        |      k(  sJ t        ||      t        ||      fS )Nc                
    | d u S r   r   r   s    r   <lambda>z,_split_layout_and_sharding.<locals>.<lambda>B  s
    !t) r   )is_leafz`jax.jit` does not accept device-local layouts directly. Create a `Format` instance wrapping this device-local layout and pass that to `jit` instead. Got )rJ   r   rD   appendlayoutshardingrE   rF   r   r   rK   )entriesentries_flattreedeflayouts	shardingsr   s         r   _split_layout_and_shardingr>  A  s    &w8KL,29' a!VnnQXXqzz"	A
+	,(()s,- -
 nnTq 
WY	''	'		)>'9+M	MMr   c                  t        |        |	|it        j                  dt               ||	t	        d|d|	      |t        |t              st	        d      |t        |t              st	        d      t        |t              rt        |      }t        |      \  }}t        |      \  }}t        |d      }t        |dd	
      }|duxr t        |t               }t        j                  |      \  }}t        j                  |      \  }}t        j                  |      \  }}t        j                  |      \  }}t        j                  |       }t        j                  |       }t!        | |||||      \  }}}}|dnt        |j#                               }t%        di d|d|d|d|dt        |      d|dt        |      d|dt        |      d|dt        |      d|d|d|d|d|d|	d|d|
d|d |S )!zParses the arguments to jit/pjit.

  Performs any preprocessing and validation of the arguments that we can do
  ahead of time before the jit()-ed function is invoked.
  Nzbackend and device argument on jit is deprecated. You can use `jax.device_put(..., jax.local_devices(backend="cpu")[0])` on the inputs to the jitted function to get the same behavior.z>can't specify both a device and a backend for jit, got device=z and backend=zTIf backend or device is specified on jit, then in_shardings should not be specified.zUIf backend or device is specified on jit, then out_shardings should not be specified.r   out_shardingsTallow_unconstrained_dimsr   rc   rd   rf   rg   ri   rj   rk   rl   rm   rn   ro   rq   rs   rt   ru   rw   ry   rz   r{   r|   r~   )r'   warningswarnDeprecationWarningr   r   r?   listtupler>  r@   none_lrflattenr   rc   rd   r(   itemsra   )r   r   r@  rq   rs   rt   ru   rz   rw   ry   r{   compiler_optionsr|   
in_layoutsout_layoutsrf   ri   rg   rk   rj   rm   rl   ro   rn   rc   rd   r~   s                              r   _parse_jit_argumentsrN  V  s    F.MM	C 		 g1 &$YnG:7 8 8
<AQ(R ? @ @ MCS)T @ A A d# &L7E*l9-H+}'nE,(BFH- ".T!9 "P%/>N%O!O  /6ool.K++070N--*1//**E'',3OOK,H))**3/.((--ET	=./>FB./>? !1 8" 0 6 6 89 	 
3%
3#
3 %@
3 2	
3
 ""56
3 4
3 ##78
3 .
3   12
3 0
3 !!34
3 &
3 (
3 9G
3 (
3 17
3 AH
3  
3 )/
3  *!
3" 2#
3 3r   c               J    t        | |||||||||	|
||      }t        | |      S )z8jit() and pjit() are thin wrappers around this function.r   r@  rq   rs   rt   ru   rz   rw   ry   r{   rK  r|   )rN  r"  )r   r   r@  rq   rs   rt   ru   rz   rw   ry   r{   rK  r|   r   s                 r   make_jitrQ    s=     ",m%%))+( 
3	!!r   c                  J    e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
ed<   y)
PjitParamszlist[ArrayLike]r   dict[str, Any]r   tuple[core.AbstractValue, ...]r   rQ   r%  r   rr   r   N)r   r   r   r   r   r   r   rS  rS    s*      **r   rS  c                &	  %& t        j                  d|        t        |      }|r|j                  rt	        d      j
                  s#|j                  s|j                  rt	        d      t        j                  | |      }t        ||j                  |d      \  }}	~t        ||j                  |      \  }}
~t        |	|
f      \  }}t        ||      \  }&|j                   s|j"                  r<t$        j&                  j(                  s"t+        |j                   |j"                  |      }ndt-        |      z  }t        |j                  xs |j                        }|r@t/        |j                  |j                        }t        |      \  }}t1        |      x}}|x}}nf|j2                  rdnd	%t1        %fd
|j4                  D              }t1        %fd|j6                  D              }|j8                  }|j:                  }d |vsJ d |vsJ |}t1        d t=        ||      D              }|J t?        |||j@                  |jB                  |||jD                  ||	      \  }}tG        ||      }tI        |||tK        |jL                              \  }}}t$        jN                  j(                  rtQ        |g |jR                  ||       tU        |||||jV                  d t-        |              tY        |||jZ                  |j\                  t_        &fdd      t1        |      |j`                  jb                  |      \  }}t-        |      t-        |      cxk(  rt-        |      k(  sJ  J |} t-        |      }!td        f|!z  |z   }d|!z  |z   }d|!z  |z   }t-        |      t-        |      cxk(  r*t-        |      cxk(  rt-        |      t-        |       z   k(  sJ  J  &       \  }"}#t1        d |#D              }#|jD                  jg                  |#      |j`                  _1        ti        ||||||tk        |      |jl                  |jL                  |jn                        }$tq        ||$|||"|js                  t-        |                  | fS )Nzpjit._infer_params_implz<pjit does not support kwargs when in_shardings is specified.zpMesh context manager should not be used with jit when backend or device is also specified as an argument to jit.r*   T)allow_invalidFr  r   c              3  :   K   | ]  }t        |d         yw)r   N_create_sharding_for_arrayr   r   api_namectx_meshs     r   r   z%_infer_params_impl.<locals>.<genexpr>  s$       ) 	#8QI )   c              3  :   K   | ]  }t        |d         yw)r@  Nr[  r]  s     r   r   z%_infer_params_impl.<locals>.<genexpr>  s$      !* 	#8QJ!*r`  c              3  |   K   | ]4  \  }}|j                   rt        j                  |t        |            n| 6 y wr   )has_qddr   AvalQDDr"   )r   r   r   s      r   r   z%_infer_params_impl.<locals>.<genexpr>  s;      B!Q 23$,,q'!*- Bs   :<c                              d   S )Nr   r   )out_tree_and_result_pathss   r   r4  z$_infer_params_impl.<locals>.<lambda>!  s    6O6QRS6T r   r   closurer   c              3  L   K   | ]  }d t        j                  |         yw)resultN)lu_clean_keystr_arg_names)r   paths     r   r   z%_infer_params_impl.<locals>.<genexpr>0  s+      1   : :4 @AB 1s   "$)result_pathsr   r   r@  rL  rM  donated_invarsr_  r   rz   r{   r~   ):r   
test_eventre   rf   r   emptyry   rw   rk  	wrap_initr#   rq   r)   rs   rJ   r%   rt   ru   r   
debug_nansr   r&   r   $_create_sharding_with_device_backendrG  r|   ri   rk   rg   rj   r   _process_in_axis_resourcesrl   rm   r*   _qdd_cache_indexr-  	IgnoreKeyr{   mutable_array_checksr,   r   _qdd_cache_updatein_aval_qdds%_check_and_canonicalize_out_shardingsrn   ro   rU   r   _debug_infor>   _replacedictr_   rz   r~   rS  safe_arg_names)'r   jir_  dbgr   r   r   have_kwargsfdyn_args
dyn_kwargsexplicit_argsr%  flat_funrp  device_or_backend_setr8  leavesr;  ri   rk   rg   rj   in_typein_shardings_flatin_layouts_flat	qdd_tokenr   r   r   out_shardings_flatout_layouts_flatr   num_extra_argsr   rn  r   r^  rf  s'     `                                  @@r   _infer_params_implr    s    //+S1V+R33
FH H 
RZZ299
	:; ; 	ll33'!&q"*;*;TQUV+!X
)!R-?-?H-!Z':(>?-(4Q(@%(%2--v7H7H7N7N$R%6%68J8JGTNM 22N
 rzz6RYY73BIIrzzJH"8,OFG16v>.3::0,,v%H  )'' ) ) ! !*((!* * 2244	(	((	(	)	))	) ' B%(-%@B B'			'A/R11,,.C[(R$_
 x1)/Ibii$8:%   &&&s,Dell,DV,DmTHgy&&&|F46 *O123I3I-.T^`aI//1F*H&&
 
]	s#45	M_9M	MM	MM	M)v;."n~58IIn,>/n,~=.

 C$8 >
n
>!$Vs9~!=> ? > ? > 56(L 1#/1 1,!,,55<5P%++$& "#"..YY22& VVXh(:(:3x=(IK

 r   c                  (    e Zd ZU dZdgZded<   d Zy)InferParamsCacheEntryz.Mutable value object for _infer_params_cached.pjit_paramszPjitParams | Nonec                    d | _         y r   )r  r   s    r   __init__zInferParamsCacheEntry.__init__K  s
    Dr   N)r   r   r   r   	__slots__r   r  r   r   r   r  r  G  s    6o)  r   r  c                    t               S r   )r  )r   r   	signaturer   r_  s        r   r/  r/  T  s     
	  r   c                X   |j                   rpt        j                  j                  j                  }t        |      5  t        j                  |j                        5  t        | |||      cd d d        cd d d        S t        | |||      S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY wr   )	r|   mesh_libthread_resourcesenvphysical_meshrC   use_abstract_meshabstract_mesh_infer_params_internal)r   r  r   r   	phys_meshs        r   r   r   _  s     ))--;;I
%i
0 ;

$
$Y%<%<
=;#CT6:; ; ; "#r488	; ; ; ; ;s#    B B*	B B	B  B)c           	     d    t        j                         } fd}t        j                  t	        j                               t	        j                               j                  j                  t        j                        \  }}t         ||      }t         |||      }	|	j                  W |       }
t         ||
|      \  }}|j                  d   j                   j"                  r||j$                  |z   fS ||	_        |	j                  |	j                  j$                  |z   fS )Nc            
     z    t        d j                  j                  j                  j                        S )Nr   )rq   rs   
sourceinfor  )r*   rq   rs   rc   rd   )r   r   r  r   s   r   r4  z(_infer_params_internal.<locals>.<lambda>o  s7    :S$r/@/@((R5F5F  " r   )r   r   )r  get_concrete_meshr5   parse_argumentsrG  valueskeysrq   rs   r   default_registry_infer_input_typer/  r  r  r   r   r   r   )r   r  r   r   r_  dbg_fnr  dynargsavalsentryr  r   r   s   ````         r   r  r  k  s    '')("&
 ..
E&--/"E&++-$8":K:K)446)W C
1%
sB	5(
C%

(C%R3fu>LAyxx&&9$$$E			E--44w>	>>r   c           
         g }	 t        |      D ])  \  }}|j                  t        j                  |             + 	 t        j                  j                  rt        |||       t        |      S # t        $ r8  |       }d|j
                  |j
                     nd }t	        d| d      d t        $ rG  |       }d|j
                  |j
                     nd }t        d|  dt               d| d	      d w xY w)
Nzargument path is unknownzUAn overflow was encountered while parsing an argument to a jitted computation, whose .zpath zError interpreting argument to z8 as an abstract array. The problematic value is of type z# and was passed to the function at z.
This typically means that a jit-wrapped function was called with a non-array argument, and this argument was not marked as static using the static_argnums or static_argnames parameters of jax.jit.)	enumerater6  r   shaped_abstractifyOverflowErrorr   r   r   r   ry  r   r+   rG  )	r   r  r  r  r   r   r  arg_patharg_descriptions	            r   r  r    s0   
%-( /1ll4**1-./(   &&fe];	u) 
 
(C"s}}7P3==#3V_"`aH
$:Q(  
 

(C#--2KcmmA.QZ[\O
'u -++/7) 4)* +BB 
s   7A. .BC=c                      e Zd Zd ZddZy)
JitWrappedc                    t         )zSee ``jax.eval_shape``.NotImplementedErrorr   r   r   s      r   r  zJitWrapped.eval_shape  s    
r   c                    t         r   r  r  s      r   r  zJitWrapped.trace  s    
r   Nreturnzstages.Traced)r   r   r   r  r  r   r   r   r  r    s    r   r  z	pjit.pjit)repro_api_nameFc                2    t        | |||||||||	|
|d      S )zG`jax.experimental.pjit.pjit` has been deprecated. Please use `jax.jit`.TrP  )rQ  )r   r   r@  rq   rs   rt   ru   rz   rw   ry   r{   rK  s               r   r  r    s2      
	M#_#_fgf'$
@ @r   c                ^    t        |       \  t              t        fdf      S )Nc                     t               S r   )rK   )r;  valss   r   r4  z!hashable_pytree.<locals>.<lambda>  s    .$"? r   rg  )rJ   rG  rU   )pytreer;  r  s    @@r   hashable_pytreer    s1    v&-$	t$	?#*D/
3 3r   c                D   |5|dk(  s| j                   rt        S t        j                  | t	                     S t        |t        t        t        f      r|S | j                   rt        | d| d| d      t        |t              sJ |       t        j                  | |      S )Nr   zM requires a non-empty mesh in context if you are passing `PartitionSpec`s to z`. You can define a context mesh via `jax.set_mesh(mesh)`. Alternatively, provide `Sharding`s to z3 and then the mesh context manager is not required.)
rr  r>   r   cached_named_shardingr.   r   r=   r?   r8   r  )r   r   r   r^  s       r   r\  r\    s    Y5DJJ//moFFD*H56H	ZZ
*   $v &6D	FG G
 
A}	%(q(	%		-	-dA	66r   c                    | |J t        |       }nA|4| J t        t        j                  |      j                         d         }nt	        d      d|_        |S )Nr   zUnreachable!T)r;   xbget_backendlocal_devicesr   _device_backend)rw   ry   outs      r   ru  ru    se    ??
v
&C>>
r~~g6DDFqI
JC

((#	*r   c           
     F   	 t        t        | |||            S # t        $ r Y nw xY wt        t	        |            rJ |rt        |      t         us%t        |      t        |j                               k7  r|  d|  d}t        |      t         ur|d|  dt        |       dz  }nTt        |      t        |j                               k7  r/|d|  dt        |       dt        |j                                d	z  }t        |j                               d
k(  r;t        | ||f       |d|  dz  }t        |      # t        $ r Y t        |      w xY wt        |      |}t        |t               g|j                  z        }t        ||      }|r|d   } ||       J d       )Ntupled_argszW specification must be a tree prefix of the positional arguments tuple. In particular, zn must either be a Sharding, a PartitionSpec, or a tuple of length equal to the number of positional arguments.z But z is not a tuple: got z	 instead.z4 is the wrong length: got a tuple or list of length z for an args tuple of length r     z> Given the corresponding argument being passed, it looks like z/ might need to be wrapped in a singleton tuple.r   zPlease open a bug report!)rG  r$   r   rL   rM   r   r   childrenrK   
PytreeLeaf
num_leavesrO   )	whattreer=  r  r   	axis_tree
dummy_treeerrorsr   s	            r   flatten_axis_resourcesr    s   	dD)MNN	 		
 ^I677	7 d9oU2)nDMMO(<< V ..2V 4##C Ie#	uTF/Y/@	JJc	Y3t}}/	/	dVOY  =T]]_%&a) *c 4==?q dYL1 	 ))- /%& 	' S/  S/  S/) dZ\NT__$DE*J/&q	A
D'M ,++s    	&&D9 9	EEc                      e Zd Zd Zy)r  c                     y)Nzpytree leafr   r   s    r   __repr__zPytreeLeaf.__repr__   s    ]r   N)r   r   r   r  r   r   r   r  r    s    *r   r  i   )max_sizetrace_context_in_keyc	           	        |st        |      \  }}	t        | |      }
t        |
t              r|
ft	        |      z  }nt        d||
d      }t        ||      }||ft	        |      z  }nt        d||d      }t        || |j                  t	        |            dd       t        || |j                  t	        |            d       ||fS )	Nzpjit in_shardingsTr  zpjit in_layoutszpjit argumentsFallow_uneven_shardingzjit arguments)	rN   rK   r   r?   r   r  pjit_check_aval_shardingr  check_aval_layout_compatibility)rg   ri   rl   rm   r   r%  r*   r  kwsr   orig_in_shardingsr  rL  r  s                 r   rv  rv  #  s    
 
!'*JGQ$%9;NO !#34*,s8}<.W&7TK 02CD*!mc(m3O,7JDBO ,h4:44S]C+5J "xjH.A 
O	++r   zset[str]!callsites_with_tracing_cache_missc                    | \  }}}\  }}}}	|\  }
}}\  }}}}g d!fd}d"d dd# fd}d# fd}d$fd}	 	 d% fd}||
k7  rt        |      t        |
      k7  rd |d	||
       nt        t        ||
            D ]  \  }\  }}|d
   j                  }||k(  r|d
   |d
   k7  r |d| d||       8|dk(  r ||d   d
   |d   d
          S|dk(  r ||d   |d          h|dk(  r ||d   |d          } |d| d|dd |dd         rD cg c]  }d|d
   vs| c}||k7  r
 |d||       ||k7  r
 |d||       ||k7  rs	 |||       ||k7  r
 |d||       |	|k7  rt        |	      t        |      k(  sJ t        t        |	|            D cg c]  \  }\  }}||k7  rd| d| d|  }}}}j	                  ddj                  |      z   dz   t        |      f       s
 |d| |       t        j                  t        d              }|d
   t        |d         fS c c}w c c}}}w )&a0  Explanations of differences between the cache keys, along with diff sizes.

  Result: a pair of a list of explanations for differences, and the total size
    of the differences. The sizes are used to pick the old key with the smallest
    different size for the explanation that is shown to the user.
  c           	     @    j                  d|  d| d| ddf       y )Nz
different z:
    now: z
 != before: zQ.
explanation unavailable! please open an issue at https://github.com/jax-ml/jax.
   )r6  )	key_fieldwhat_kwhat_okdiffss      r   unavailablez,diff_tracing_cache_keys.<locals>.unavailableS  s9    	LLi[VHN7) LB 
B 
	r   c           
         t        t        |       t        |            }t        t        |       t        |            |z
  }|t        d t	        | d | |d |       D              z  }|S )Nc              3  ,   K   | ]  \  }}||k7    y wr   r   )r   e1e2s      r   r   zBdiff_tracing_cache_keys.<locals>.list_diff_size.<locals>.<genexpr>]  s      ?&"bR2X ?s   )minr   maxsumr   )s1s2min_len	diff_sizes       r   list_diff_sizez/diff_tracing_cache_keys.<locals>.list_diff_sizeZ  sh    #b'3r7#GCGSW%/I ?C8G028G-> ? ? ?Ir   Fc           	         | \  }}|\  }}||k7  rj                  d| d| df       ||k7  rMj                  ddj                  d |D               ddj                  d |D                ||      f       y y )Nz0different static_argnums:
  dynamic argnums now  and before r  z&different value of static args:
  now , c              3  F   K   | ]  }t        |j                          y wr   reprvalr   r   s     r   r   zUdiff_tracing_cache_keys.<locals>.explain_transform_argnums_partial.<locals>.<genexpr>n  s     Aad155kA   !c              3  F   K   | ]  }t        |j                          y wr   r  r  s     r   r   zUdiff_tracing_cache_keys.<locals>.explain_transform_argnums_partial.<locals>.<genexpr>o  s     #HADK#Hr  )r6  join)param_kparam_okdyn_argnums_kstatic_args_kdyn_argnums_okstatic_args_okr  r  s         r   !explain_transform_argnums_partialzBdiff_tracing_cache_keys.<locals>.explain_transform_argnums_partialc  s    #* M=%-"NN&ll$$1?,~>NP
 &llIIA=AAB$))#H#HHIK 
79: 'r   c           	        | \  }|\  }t        |j                  j                               D cg c]  \  }}||j                  f }}}t        |j                  j                               D cg c]  \  }}||j                  f }}}||k7  rNj                  ddj	                  d |D               ddj	                  d |D               d ||      f       y y c c}}w c c}}w )Nz)different value of static kwargs:
  now {r  c              3  B   K   | ]  \  }}| d t        |         yw: Nr  r   kvs      r   r   zVdiff_tracing_cache_keys.<locals>.explain_transform_argnames_partial.<locals>.<genexpr>|  s#     Nda1#RQy 1N   z} and before {c              3  B   K   | ]  \  }}| d t        |         ywr  r  r  s      r   r   zVdiff_tracing_cache_keys.<locals>.explain_transform_argnames_partial.<locals>.<genexpr>}  s#     %UDAq2d1gY&7%Ur  })sortedr  rJ  r6  r	  )r
  r  static_kwargs_kstatic_kwargs_okr  r  r  r  s         r   "explain_transform_argnames_partialzCdiff_tracing_cache_keys.<locals>.explain_transform_argnames_partialr  s    O o11779:<da155z <O < /3399;<>tq!AEE
 > >**lliiNoNNO P II%UDT%UUVVXZ *:
;=> +	<>s   C 1C&c                   | j                   |j                   k7  st        |       \  }}t        t        |            }t        |      \  }}t        t        |            }t        |      d t        ||       t        |      d t        ||       k(  rR|j	                         d   }|j	                         d   }	j                  d| d| d| d|	 t        ||z
        f       y t        |       }
t        |
      dk  r|
n|
d d dz   }
t        |      }t        |      dk  r|n|d d dz   }d|
 d| g}t        t        j                  | |            }|D ]M  \  }}}}|^}}d	d
g|j                     }|j                  d| t        t        |             d| d| d| 	       O j                  dj                  |      t        |      f       y )Nr  zBdifferent number of args and kwargs, but same total number.
  now z args and kwargs with keys z

  before I   ...zdifferent input pytree:
  now: z
  before: r   r   z  * at , now r   z, so 
)r  rN   r   r  	node_datar6  absrb   rF  r   equality_errors_pytreedefidxrP   rG  r	  )	in_tree_k
in_tree_okargs_tree_kkwargs_tree_k	nr_args_kargs_tree_okkwargs_tree_ok
nr_args_okkeys_kkeys_okin_tree_k_strin_tree_ok_strdifferrsrm  thing1thing2explanationfstbasedifferent_leaf_countr  s                       r   explain_in_tree_diffz5diff_tracing_cache_keys.<locals>.explain_in_tree_diff  s(   %00J4I4II $4I#> k=&{34i%5j%A"lN'45j
;
'(CY
)C
D
<
()D#i*D
EF((*1- **,Q/ k "!( #$ &")	%
 i'(*	+ 		NM&)-&82&=]',u4 _N(+N(;b(@n("-5 .}o >'(* +D 	33IzJKD-1  )ffkjcDh(d
kkD6&t-.fVHL Q   
LL$))D/3t9-.r   c           	        d} j                   t        |             }d dj                  fdt        ||       D              }t        |      dk  r|n|d d dz   }d| g}d}t        || |      D ]8  \  }}}	||	k(  rd}
t	        |      t	        |	      cxk(  rt
        j                  k(  rn n |       |	      }}|
 |j                  |	j                        z  }
|j                  |	j                  k7  r.|d	|j                   d
z  }|d	|	j                   d
z  }d}|
dz  }
n[|j                  |	j                  k7  rB|j                  dd      }|	j                  dd      }|
dz  }
nt        |      t        |	      }}|t        d|
      z  }|j                  d| d| d|        ; |r|j                  d       j                  dj                  |      |f       y )Nr   c                T    t        | d      r| j                  d      S t        |       S )Nr   T)short_dtypes)r   r   rb   )ats    r   arg_type_to_strzPdiff_tracing_cache_keys.<locals>.explain_args_type_diff.<locals>.arg_type_to_str  s&    	[	!|||..2wr   r  c              3  >   K   | ]  \  }}| d  |         ywr  r   )r   anrA  rB  s      r   r   zJdiff_tracing_cache_keys.<locals>.explain_args_type_diff.<locals>.<genexpr>  s0      A%r2 !TOB$7#89 As   r!  r"  z$different input types:
  types now: Fz{weak_type=r  Tr  )r@  mesh_axis_typesz	    * at r#  r   zwhere weak_type=True often means a Python builtin numeric value, and 
weak_type=False means a jax.Array.
See https://docs.jax.dev/en/latest/type_promotion.html#weak-types.r$  )r  r   r	  r   r   r   ShapedArrayshape	weak_typer8  r   rb   r  r6  )args_kargs_okr  r   
args_k_strr5  add_weak_type_hintr   arg_t_karg_t_okthis_arg_diff_sizer  r  rB  r*   r  r  s                @r   explain_args_type_diffz7diff_tracing_cache_keys.<locals>.explain_args_type_diff  s   I)
))#f+6I
  A),Y)?A AJ":3CR59PJ3J<@AD#&y&'#B @gx	H	h	g$x.	<D,<,<	< )?8+DBnW]]HNNKK 2 22
,w0014
4"
,x112"5
5"#


!
!2!22  dD I"!!tT!J"

!
Ws8}B3q,--i
kkIdV6"\">?'@* 
kkOP 
LL$))D/9-.r   Tzfun_transforms lengthr   zfun_transforms[z] transformr%   r  _argnums_partial_argnames_partialzfun_transforms.z paramsNzfun_transforms._argnums_partial
fun_paramsfun_in_type
arg_inlinez  [z]: now r   zadifferent tracing context, e.g. due to config or context manager.
found differences at positions
z, and
zK
compare to tuple returned by config.trace_context() in jax/_src/config.py.z"something (unexpected empty diffs)c                    | d   S Nr  r   )ds    r   r4  z)diff_tracing_cache_keys.<locals>.<lambda>  s
    AaD r   key)r  rb   )r  r   r  r   r  int)r
  rG  r  rG  )r)  rQ   r*  rQ   )rI  tuple[core.AbstractValue]rJ  r\  )
r   r  r   r   r6  r	  r   unzip2r  r  )!r  oldkr*   fun_transforms_kfun_params_kfun_in_type_karg_in_type_kr   arg_inline_kctx_kfun_transforms_okfun_params_okfun_in_type_okarg_in_type_okarg_inline_okctx_okr  r  r  r=  rP  r   tott_namerX  c_kc_okidxsdiffs_and_sizesr<  r  r  s!     `                           @@@r   diff_tracing_cache_keysrr  E  s    /0,\=#M1lU15/m^%NA}v!#% :>'/R)/&?)/V **
$5 66!)"$57 "#&68I"JK *!Wa17HQ42a5=
s+62
>
^#
qtAw1a
1
''
+AaD"Q%
8
((
,QqT2a5
9
ofXW5qubfE#* O1!B!A$!NQOE]"lM:n$|];n$-A=.9]"lM:
f_u:V$$$"+Cv,>"?P P;C3$; !GC5TF3 PD P	LL
,		

9
9
 
T	 
4a>KKu. AB/
!
c/!"45	66/ PPs   !H;.H;)I c                   t         j                  j                  ry |d   d   j                  ry | j                  }|j
                  }|rt        j                  |      sy g j                  fd}t        j                  t        j                               } d| d|dz  dd       d	}	|r|	d
| z  }	|j                  x}
r|	d|
 z  }	|j                  }|s|sV d| dt        | j                         |	        |t        v r d        |       S t        j!                  |        |       S  d| |	        t#        |j%                               }|D cg c]  }||k7  rt'        |||       }}|sJ d       t)        |d       }|D cg c]  }|d   |d   k(  s|d    }}dddfd}t+        |      dk(  r d        ||d          n d       |D ]
  } ||         |        y c c}w c c}w )N      c                 j    t         j                  t        j                  dj	                               S )Nr$  )loggerlogloggingWARNINGr	  )r   s   r   r4  z,explain_tracing_cache_miss.<locals>.<lambda>  s    GOOTYYs^< r   zTRACING CACHE MISS at z	 costing g     @@z.3fz ms because:r   z defined at :z  never seen function:
    z id=z~  but seen another function defined on the same line; maybe the function is
  being re-defined repeatedly, preventing caching?z  for z:we must find some diffs if key differs from all cache keysc                    | d   S rW  r   )r  s    r   r4  z,explain_tracing_cache_miss.<locals>.<lambda>9  s
    ad r   rY  r  r   c                2    |j                  ddd| z  z         S )Nr$   )r	   )indentr   s     r   indent_subsequent_linesz;explain_tracing_cache_miss.<locals>.indent_subsequent_lines<  s    ;;tTC&L011r   c                8    | D ]  } d d|      z           y )Nz  * key with    r   )r5  rX  r  r   s     r   
p_one_diffz.explain_tracing_cache_miss.<locals>.p_one_diff>  s'     91!Q7789r   zE  all previously seen cache keys are different. Closest previous key:zR  all previously seen cache keys are different. Several previous keys are closest:)r  r[  r   rb   r  rb   )r5  Sequence[str])r   check_tracer_leaksr   r  r*   func_filenamer   is_user_filenamer6  	summarizecurrentfunc_lineno	func_namer   r  r  addrF  r  rr  r  r   )r   unseen_fcacherZ  elapsed_secr*   r  donecallsitesrc_infor  r  
cache_keysokr  min_diffrX  smallest_diffsr  r  r   r   s                      @@@r   explain_tracing_cache_missr  
  s8    $$fVAY]]F~~***-+<<]K	#	jj!	<$''(8(@(@(BC(XJic0A#/FlST (,}o..H***[*!K=!!H"")U$YKtBsuuI;xjIJ44 	= > 6M (++H56MfYKz"# EJJL!*  .3"9 #3J7 .% .	LLLN+("'?Q1Q48A;+>AaD?.?29 	AMN~a ! + , m &+.
 @s   !G=H(H)explainrx  c                X   t        j                  d       ~~t        j                  j                  rt        d| j                   d      t        j                  d| j                  t        j                        5  t        j                  | |      \  }}}d d d        t        j                  j                  rddlm}  |       t!        d D              r+t        j"                  t        j$                              }|}	nt'        j(                  |      }g }	||	fS # 1 sw Y   xY w)	Ncreate_pjit_jaxprr	  r
  zMFinished tracing + transforming {fun_name} for pjit in {elapsed_time:.9f} sec)r^   eventr   )check_key_reuse_jaxprc              3     K   | ]?  }t        |t        j                        xs t        j                  |      j                   A y wr   )r   r   Tracerr!   rc  r   cs     r   r   z%_create_pjit_jaxpr.<locals>.<genexpr>g  s1     N!At{{	#	=t{{1~'='=	=Ns   AA)r   rq  r   r  r   r  r  r   log_elapsed_timer   JAXPR_TRACE_EVENTpetrace_to_jaxpr_dynamicr    jax.experimental.key_reuse._corer  r   close_jaxprconvert_constvars_jaxprr   ClosedJaxpr)
r   r  r  ignored_inliner   global_out_avalsr   r  closed_jaxprfinal_constss
             r   r-  r-  N  s    //%&
-ceeW 5- - . .  U||8#=#=? N ')&?&?W&M#EVN
 !!F%  	NvNN>>""<"<U"CDLL##E62LL	|%5	55%N Ns   ;D  D)c           	        t        | |      }t        |t        t        f      r|ft	        |      z  }	nt        d |       |d      }	t        ||      }
|
|
ft	        |      z  }nt        d |       |
d      }t        |	| |j                  t	        |            dd       t        || |j                  t	        |            d       |	|fS )Nzpjit out_shardingsFr  zpjit out_layoutszpjit outputsr  zjit outputs)	rK   r   r?   r8   r   r  r  safe_result_pathsr  )rj   rk   rn   ro   r   r   r*   r  orig_out_shardingsr  rM  r  s               r   r|  r|  p  s     &&;=QR"%5x$@A,.Y?/hj*< 24FG+#~I6-HJH )"j""3y>2E3 "	"j""3y>2 
-	--r   c                    | j                   | j                   |k(  sJ t        j                  | j                  t	        t
                    }|| j                  | j                  |f   S r   )r  
_seen_qdds
setdefaultr  r   rF  
transformsr   )r   r  r  s      r   _seen_qdds_getr    sR    		w 66	6


{4'8
9%	

G4	55r   c                    t        | |      }t        |      D ],  \  }}|D ]  \  }}t        j                  |      |k7  s ) |c S  t	        |      S r   )r  r  r   r"   r   )r   r  casesr   recordsobjqdds          r   rw  rw    s_    
g
&%e$ ja S	c	c	!5 h	
 
Ur   c                    t        | |      }|t        |      k(  rG|j                  t        ||      D cg c]  \  }}|j                  r||j
                  f! c}}       y y c c}}w r   )r  r   r6  r   rc  r  )r   r  r   r   	aval_qddsr  r  aval_qdds           r   rz  rz    s`    
g
&%#e*_	LLs697M '8%% hll# ' ( 's   $A#
T)frozenc                  $    e Zd ZU ded<   d Zd Zy)rx  r   r  c                ,    t        | j                        S r   )hash	__class__r   s    r   r   zIgnoreKey.__hash__  s    r   c                "    t        |t              S r   )r   rx  r   s     r   r   zIgnoreKey.__eq__  s    eY''r   N)r   r   r   r   r   r   r   r   r   rx  rx    s    
( (r   c                   t        || |      D ]  \  }}}t        |t        t        f      r|rd| nd}	|j                  }
	 |j                  |
       |rH|j                  t        |
            }|J t        j                  ||      \  }}t        |      D ]3  \  }}|
|   |z  dk7  st        d| |	 d| d| d	| d
|
|    d|
 d        y # t        $ r}t        d| |	 d| d|       d }~ww xY w)N with pytree key path r   One of z. is incompatible with its sharding annotation r  r   z was given the sharding of z6, which implies that the global size of its dimension z should be divisible by z, but it is equal to z (full shape: ))r   r   r?   r=   rG  check_compatible_avalr   _to_xla_hlo_shardingr   r   get_num_ways_dim_shardedr  )r=  
flat_avalsnames	what_avalr  allow_partial_manualr   r   r   name_strrG  r   hlo_shardingnum_ways_dim_shardedr   r   sizes                    r   r  r    s^    :y%8 (mdAt!&-.26'v.BHJJE"e$ !++CJ7l%%% , E E
,!.A34 ('!T8d?a	{8* -3 223 5"V#8q
 C#WA	'( ((#(  "I;xj )s"QC!" ""s   C	C5C00C5c                    t        || |      D ]>  \  }}}|t        |t              r|rd| nd}	 |j                  |j                         @ y # t
        $ r}t        d| | d| d|       d }~ww xY w)Nr  r   r  z, is incompatible with its layout annotation r  )r   r   rF   r  rG  r   )	r<  r  r  r  r   lr   r  r   s	            r   r  r    s    :w6 	"mdAtyJq*-26'v.BH"djj)	"  "I;xj )s"QC!" ""s   A	A4A//A4r   c                2    t        | d   j                        S Nr   )re   r   r   s    r   r4  r4    s    D)@)@$A r   c                .    | j                   j                  S r   )r   r   )r   r   __s      r   _is_highr    s    			r   c                0   t        j                  |       \  } }g ||}t        t        |      fi |}| j                  D cg c]  }t        |j                                }}| j                  D cg c]  }t        |j                                }}t        j                  |       }t        |||fi |}t        | j                  |      D 	
cg c]:  \  }}	|j                  r|j                  |	      n|j                  |	      D ]  }
|
 < }}	}}
t        j                  |       }t        j                  |d|i|}t!        ||g      \  }}t        j"                  | ||       t        j$                  | j                  |      S c c}w c c}w c c}
}	}w r  )r  convert_const_himutables_converted_mutables_add_paramsr   r{  lo_tyr   num_himuts_out_lojax_expand_paramsr   rc  
read_loval	lower_vallower_jaxprr   r   rZ   apply_himutraise_lo_outs)r   hi_argsr   closed_over_himutablesr   
lo_nums_inrk  lo_nums_outlo_muts_outr   lo_vallo_argslo_jaxprall_outsout_mutlo_outss                   r   	_to_lojaxr    sx   "$"="=e"D%	/$/w/')#.D*EPP& /4.@.@AdDJJL!A*A).9AQWWY9+9!!%(+
KOO& $'u'9'97#C 5 5a26,,DOOA.!%!25  5V 5' 5
 ^^E"(ZZ;;F;(;-8'7..)			%//7	33 B9
5s    F2 F?Fc               Z    d| z  |z   }t         f| z  |z   }d| z  |z   }t        ||||      S )NrY  r   )rp  r   rL  r>   r  )nrp  r   rL  r   s        r   r  r     sE    a<.0.!#l2,{Z'*	f^,#
% %r   c                   d }	 |	| |      } |	| |      } |	| |      } |	||      } |	||      }t         f|z  |z   }d|z  |z   }t        ||||||      }
|
S )Nc                :    t        d t        | |      D              S )Nc              3  <   K   | ]  \  }}|f|z  D ]  }|   y wr   r   )r   r  r   ys       r   r   z7_lojax_expand_params.<locals>.expand.<locals>.<genexpr>  s&     =tq!QD1H=q==r   rG  r   )nsxss     r   expandz$_lojax_expand_params.<locals>.expand  s    =s2r{===r   r   )rp  r   rL  r@  rM  r  )nums_innums_outmuts_outrp  r   rL  r@  rM  r   r  
new_paramss              r   r  r  	  s    
>'N3.'L3,'J3*(M3-(K3+ .8+m;-("[0+F>!-*"/[J* 
r   c                   t        j                  |      rdt        |      z  S g }t        | |||      D ]L  \  }}}}|j                  }	|j
                  2|j
                  j                  }
t        j                  |
||      rd n|
}nd\  }
}t        |t              xs t        |j                  t              }|:|	r&|r|j                  d        |j                  |       |j                  d        |	rO|sM|
Kt        j                  ||
      s5d}t        |t              rd}t        d| d|
 d|j                    d|       t        |t"              rt        j                  |||      rd n|}|j                  |       O t%        |      S )	Nr   )NNr   a    The layout given to `jax.jit` is `Layout.AUTO` but the corresponding argument passed is a `jax.Array` with a concrete layout. Consider passing a `jax.ShapeDtypeStruct` instead of `jax.Array` as an argument to the jitted function  when using `Layout.AUTO`.zVLayout passed to jit does not match the layout on the respective arg. Got jit layout: z,
arg layout:  for arg type: r  )r2   !check_device_backend_on_shardingsr   rW   	committedformatr7  is_default_layoutr   r?   r8  r<   r6  is_user_xla_layout_equalrF   r   r   rE   rG  )r   jit_in_layoutsresolved_in_shardingsr   resolved_in_layoutsr   jit_in_lrsr   r  
arg_layoutdispatch_arg_layoutis_pmap_sharding	extra_msgs                 r   _resolve_in_layoutsr     s    
++,ABS(((:<!)
N18"= 0+c8RI
 zz::$$j%)%;%;JD%QT",  )3%j%"2'78 ?"3<<> 	

$
$T
*

$
$%8
9""4(
 "$//*E	h
++   --5J 7))3OCHH:Q&K	) * 	*
 %Xv6((2t< BJ   *a0+b 
"	##r   c                   g }t        | ||      D ]d  \  }}}||j                  d        t        |t              r)t	        j
                  |||      r|j                  d        T|j                  |       f t        |      S r   )rW   r6  r   rE   r2   r  rG  )rM  r@  r   new_out_layoutsout_lout_sout_avals          r   _resolve_out_layoutsr  ]  s~    / (mY O $eUH}T"
UF
#

 
 x
8T"U#$ 
	r   c                    t        | t              r| S |rt        | t              rt        S | S t        | t              sJ t        j                  |       rt        S t        d      )NzFHaving uncommitted Array sharded on multiple devices is not supported.)r   r?   r<   r>   r8   r   is_single_device_shardingr  )arg_sr  s     r   finalize_arg_shardingr  i  sb    '(L&ul;[FFx(((		+	+E	2 !E F Fr   c           	        t        j                  |      r|S g }t        | |      D ]  \  }}|j                  |j                  |j                  fnt
        df\  }}t        |t              r|j                  j                  rt
        d}}t        |t              r|j                  t        ||             |j                  r;|j                  s/t        j                          dkD  rt#        d|j$                         t        |t              s|j&                  r|j(                  |j(                  k7  r2t#        d|j(                   d|j(                   d|j$                         |rvt        |t*              sft-        j.                  |j1                  |j2                        |j1                  |j2                              st#        d| d| d|j$                         |j                  |        t5        |      S )	NFr  a  Passing non-trivial shardings for numpy inputs is not allowed. To fix this error, either specify a replicated sharding explicitly or use `jax.make_array_from_process_local_data(...)` to convert your host local numpy inputs to a jax.Array which you can pass to jit. If the numpy input is the same on each process, then you can use `jax.make_array_from_callback(...) to create a `jax.Array` which you can pass to jit. Got arg type: zfMemory kinds passed to jax.jit does not match memory kind on the respective arg. Got jit memory kind: z, arg memory kind: r  z\Sharding passed to jit does not match the sharding on the respective arg. Got jit sharding: z,
arg sharding: )r2   r  r   r8  r  r>   r   r9   r   rr  r?   r6  r  is_np_arrayis_fully_replicatedr  process_countr   r   _is_concretememory_kindr<   r   are_hlo_shardings_equalr  ndimrG  )r   pjit_in_shardingsr  r   	pjit_in_sr  r  s          r   _resolve_in_shardingsr%  w  s    
++,=>.0D"34 (.nc9 :=9Qs}}5)51 E9%'EJJ,<,<$eYe)-.""#8	#JK
//)"?"?



q
 2 36((=	> 		> /0U5G5G   E$5$5577@7L7L6M N""'"3"3!4OCHH:OP P 5,/44..sxx8**38846  009{ ;,,17/#((M N N ""9-Q(.T 
$	%%r   r   c                    t        | |      }t        | |||j                        }t        |||j                        }t        |||||||||	|
||||      S )N)lowering_platformslowering_parametersr   )r%  r  r   r  r   _pjit_lower)r   r   r   r@  rL  rM  rp  r_  r   rz   r{   r'  r(  r   r~   s                  r   _resolve_and_lowerr*    sh    
 't\:,"4\#(>>3*$[-Q+	\=*khk6;O+-!
# #r   c                  d    e Zd ZU ded<   ded<   ded<   ded<   ded<   eZed        Zed	        Zy
)MetaTyr   r   r8  r  re   r  r  c                .    | j                   j                  S r   )r   rG  r   s    r   rG  zMetaTy.shape  s    99??r   c                .    | j                   j                  S r   )r   r"  r   s    r   r"  zMetaTy.ndim  s    99>>r   N)r   r   r   r   r	   propertyrG  r"  r   r   r   r,  r,    sG    )-
+/'   r   r,  c                     t        | ||||      S r   )r,  )r   arg_sharding
arg_formatarg_committedr  s        r   create_meta_tyr4    s    	lJ{	KKr   c                2   t        | t        j                        rt        | j                  d d dd      S t        j
                  |       }t        | dd       }t        | dd       }t        | dd      }t        | t        j                        }t        |||||      S )NTFr8  r  r   )	r   r   r  r4  r   r  r   npndarray)r   r   r1  r2  r3  r  s         r   r   r     s     T[[!#((D$e<<		 	 	%$j$/,sHd+*#|T2-3

++	lJ#
% %r   c                   t        j                  d       i d }}t        j                  j                  rt        j
                  j                  dkD  r| }t        j                  |      }|Ot        j                  t        j
                  j                  t        j                  j                        }|t        |<   |j                         }|||d<   |
t        |j                               z   }
t        t        |      }t!        || |||||||||	d t#        j$                         ||
      }|j'                         }|j(                  ret        j*                  j                  rKt-        j.                  ||j0                  |j2                  | j4                  j6                  |j8                         t        j:                  j                  rd }t=        |j?                         d      r|j?                         j@                  }||jC                         }tE        d|fd|fd|fd	|fd
|fdt        tF        jH                  |      fd|f        |jJ                  g |jL                  | |||jL                  fS )Njit_cpp_cache_missr   fdo_profile)r   r   r@  rL  rM  rp  r_  r   rz   r{   r'  r(  r   r~   fingerprintzRunning pjit'd functionr   r@  rL  rM  zabstract args)'r   rq  r   enable_pgler   pgle_profiling_runs_pgle_profiler_dictgetr   PGLEProfilerpgle_aggregation_percentileconsume_fdo_profilerG  rJ  r   r   r*  r1   LoweringParameterscompile_auto_spmd_loweringenable_checksr2   %check_array_xla_sharding_layout_matchr   _in_layoutsr   r}  r   distributed_debugr   runtime_executabler;  hexrY   r   abstractifyr   r   )r   r   r@  rL  rM  rp  r_  r   rz   r{   r~   r   pgle_compile_optionsr   compilation_target_keyr:  r   computationr   r;  s                       r   r   r     sN    //&'(*D&"<"<"B"BQ"F"'++,BCM++

$
$
*
*

,
,
2
24m 5B01
  335K,7=)-6J6P6P6R0SS #T*)"u<!jnd113!/	+   "( !!f&:&:&@&@..h$$h&:&:!7!79 ## Kx**,m<//1==kOO%k4d;)<8*M:'4(+6*C0@0@$,GH(+68 (


> 6 6
>
>
M;#9#9
; ;r   c                8     t        j                           fdS )Nc                 >     t        j                                |  S r   )r   jaxpr_as_fun)r   r   s    r   r4  z#_get_jaxpr_as_fun.<locals>.<lambda>0  s    1t((148 r   )weakrefrefro  s   `          r   _get_jaxpr_as_funrU  %  s     ++e
%	88r   c                   	
 
	 fd}t         	
      }t        d t              D              }t        j                  |d d d d d d d       }t        j                  j                  ||g g |t        j                  t        j                  t        |j                        	       S )Nc                     t        
	d\  }}}}t        |t        |      |j                  j                  ||      }||t        |      fS Nro  )r   r   rM   r   r   r   )args_kwargs_r   r   r   r   fastpath_datar   r~   r_  rp  rL  r   r{   r   rz   r   rM  r@  s          r   call_impl_cache_missz-_pjit_call_impl.<locals>.call_impl_cache_miss7  sy     5K	U#
+,@5B1Hhz '.*D(u||]M ]$=m$LLLr   c              3  ,   K   | ]  \  }}|s	|  y wr   r   )r   r   rX  s      r   r   z"_pjit_call_impl.<locals>.<genexpr>K  s     G1Q!G   
)rt   ru   rw   ry   rg   ri   rj   rk   rl   rm   rn   ro   )rU  rG  r  r2   r  r   r  r  r   r  r  r  r  )r   r   r@  rL  rM  rp  r_  r   rz   r{   r~   r   r\  r  donated_argnumsr  s   ````````````    r   _pjit_call_implr`  3  s    M M  \=*khk6! G	.(AGG/(($d4\ };@) 

A#RY!!4#4#4IBBC
E GK
L Lr   c               Z    t        j                  | d|||||t        |      |||
|||      S )Nr   )rz   context_meshr~   r'  r(  r   )r2   lower_sharding_computationrG  )r   r   r@  rL  rM  rp  r_  r   rz   r{   r~   r'  r(  r   s                 r   r)  r)  [  s?    " 
	(	(UD,+u^4H/+-!
# #r   c           
        |d   r6t        dt        |d          d|d    dt        j                  |             |d   rt	        d |d   D              rt	        d	 |d
   D              r|t	        d |d   D              rgt	        d |d   D              rR|d   }t        j                  | ||j                  |j                  g| }|D cg c]  }| j                  ||       c}S |d   }t        d |j                  D              rt        j                  |      \  }}|D cg c]  }| j                  ||       }}g |d   t        ft        |      z  z   }	g |d   dt        |      z  z   }
g |d   dt        |      z  z   }t        |||	|
|      }| j!                  t"        g ||||      }|S | j!                  t"        |||      }|S c c}w c c}w )Nr~   zS`compiler_options` can only be passed to top-level `jax.jit`. Got compiler_options=z& specified on a nested jit with name: r   z and source info: r{   c              3  <   K   | ]  }t        |t                y wr   r   r?   r   r   s     r   r   z$pjit_staging_rule.<locals>.<genexpr>  s     	Ja*Q(
)	Jr   r   c              3  <   K   | ]  }t        |t                y wr   rf  r   r   s     r   r   z$pjit_staging_rule.<locals>.<genexpr>  s     	Ka*Q(
)	Kr   r@  c              3  $   K   | ]  }|d u  
 y wr   r   rg  s     r   r   z$pjit_staging_rule.<locals>.<genexpr>  s     	2!t)	2   rL  c              3  $   K   | ]  }|d u  
 y wr   r   ri  s     r   r   z$pjit_staging_rule.<locals>.<genexpr>  s     	3!t)	3rk  rM  r   c              3  P   K   | ]  }t        |t        j                           y wr   )r   r   Refr  s     r   r   z$pjit_staging_rule.<locals>.<genexpr>  s     7QAtxx	 7r   r   rp  rY  )r   r   rL  rp  )source_info)r   r  r   r  r   r  inline_jaxpr_into_tracer   r   to_jaxpr_tracerr   r2   _move_mutable_consts	new_constr>   r   default_process_primitiver   )r  ro  r   r   r   r  r   r   r  r   rL  rp  r  out_tracerss                 r   pjit_staging_rulerv  v  s   "#
	!&)?"@AB C$$*6N#3 4&&{34	67 7 X		J6.3I	JJ		K6/3J	KK		2VL1	22		3VM2	337OE

$
${EKK>8<>C;>?aE!!![1??
/%7%,,77--e4ME67=>!eooa->F>-VN+-V0LLL)6,')Gc&k,AAJ1v./1Hs6{4JJNfE!+NLJ11 2 FK
 
 11tV 2 6K	! @
 ?s   G$Gc           	        t        j                  | j                        }t        |||      D cg c]  \  }}}t	        |t
              r||nd  }}}}|D cg c]  }|d u  }}t        j                  | |      } t        d t        ||      D              }t        d t        ||      D              }| |||fS c c}}}w c c}w )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r   r   r  s      r   r   z#_pjit_forwarding.<locals>.<genexpr>       Dda!Dr^  c              3  ,   K   | ]  \  }}|s	|  y wr   r   ry  s      r   r   z#_pjit_forwarding.<locals>.<genexpr>  rz  r^  )r  _jaxpr_forwardingr   r   r   r?   prune_closed_jaxpr_outputsrG  )	r   r@  rM  in_fwdfwdosolr  keeps	            r   _pjit_forwardingr    s    11%++>&"6=+FH HR b"23
CL H& H#	$!t)	$$	$

'
't
4%Dc-&>DD-Dc+&>DD+	{	22H	$s   !B;Cc                8    d gt        | j                        z  | fS r   )r   outvars)eqns    r   pjit_forwarding_ruler    s    
#ckk"	"C	''r   c                   g }t        | j                  j                        D ci c]  \  }}||
 }}}t        | j                  j                        D ci c]#  \  }}t        |      t        j
                  u r||% }}}| j                  j                  D ]  }|j                  }|j                  |       ! |S c c}}w c c}}w r   )	r  r   invarsr   r   Varr  r   r6  )r   r  r   r  in_idxr   out_idxr   s           r   	_out_typer    s    
#&u{{'9'9:;TQAqD;&;'(:(:; %daQ488# T %' %;; a66DJJt 
* <%s   B<(Cc          	     d    t        j                  | t        |t        ||j                              S )N)
call_jaxpr)r   _check_callr   r  r   )ctx_factoryr   in_atomsr   s       r   _pjit_typecheckr    s+    			+uhv%++>
@ @r   c                x    | j                   rt        j                  |       n| j                  }| j                  |fS r   )	constvarsr   eqn_effectsr   r   )r   r@  r   r   effss        r   _pjit_abstract_evalr    s-    $)OO		%	 $	$	r   c                   t        |      |t        |j                        z   k(  sJ t        |      t        |      k(  sJ t        |      t        |      k(  sJ | j                  }| j                  j                  }d }t	        |t
        j                        r|j                  }n0t	        |t
        j                        r|j                  j                  }t        ||||t        j                  ||      t        j                  ||j                        ||	|
f
}|j                  j!                  |d       }||D cg c]  }t	        |t"              rd n| }}|D cg c]  }t	        |t"              rd n| }}t        |j$                        }t'        j(                  ||||||||d||	      }t        |j$                        |kD  }|rd|j*                  vr||j                  |<   |S c c}w c c}w )NF)num_const_argsr   arg_shardingsresult_shardingsuse_sharding_annotationsarg_layoutsresult_layoutstpu)r   r   module_contextaxis_contextr   r   ShardingContextnum_devicesSPMDAxisContextr   r  r   r2   SemanticallyEqualShardingsr   cached_primitive_loweringsr?  r?   host_callbacksr1   lower_jaxpr_to_fun	platforms)ctxr   r   r  r   r   r   r@  rL  rM  r^  mod_ctxaxis_ctxr  rZ  r4   r   r  r   r  num_callbackshas_callbackss                         r   _pjit_cached_lower_jaxpr_to_funr    s    
X.3u~~+>>	>>	>	X#l+	++	+	X#j/	))	)',,(+.889&&K(N::;--$$K	eWk		(	(x	@		(	(	H	[(	,#
 
	+	+	/	/T	:$	\MYZZ+;<T!CZMZP]^1
1.> ?QF^^
 ../M""ug%#6F!&{<D ../-?ME):)::04g((-	+) [^s   8G$G)c                  t        | j                  j                               }t        t        j
                  | j                        }t	        j                         gt        |      z  |z   }t	        j                  |      }t        j                  |j                        }t        j                  |      \  }}g ||j                  }t!        |      }||z   }t#        |||      }||z   }t%        | ||t        |      |t'        |      ||||d      }|D cg c]  }| j                  j)                  |       }}|D cg c]'  \  }}t	        j*                  || j,                  |      ) }}}g | j.                  |||}t	        j0                  | j2                  d | j4                  j7                  t        j8                  d|            | j:                        5  t=        j>                  |t@        jB                  j)                  |jD                  jF                        t	        jH                  |            }d d d        t	        jJ                  |        t	        jL                  |jN                  |      }tQ        |t        |      g      \  }}| j                  jS                  t	        jT                  tW        ||                  }| jY                  |       |S c c}w c c}}w # 1 sw Y   xY w)Nr   )r^  )const_loweringr   )-rF  	tokens_inr   r   r1   aval_to_ir_type	avals_out
token_typer   flatten_ir_typesr   jaxpr_const_argsr   r   r]  r   const_args_shardingsconst_args_layoutsr  rG  r?  ir_constantr  dim_var_valuessource_info_to_locationr  
name_stackextend	wrap_name	tracebackfunc_dialectCallOpr3   FlatSymbolRefAttrr   r   flatten_ir_valueswrap_compute_type_in_placeunflatten_ir_values_like_typesresultsrZ   update_tokensTokenSetr   set_tokens_out) r  r   r   r   r@  rL  rM  rp  r_  rz   r{   r~   r   r   output_typesflat_output_typesconst_args_and_avalsr   const_arg_avalsr   ca_shardings
ca_layoutsr4   effr  r  r   hoisted_const_valuescall	out_nodestokens
tokens_outs                                    r   _pjit_loweringr    s    &&()'T))3==9,//#$s7|3lB,++L9..u{{; $,@ A*o000(%j1,,,!*o|L*J&*	(	4JGnlZ	
$ 299#s}}  %9)9 *
!T q););$G  
I3	H		H,@	H4	H$##	$	nnDNN5$78#--I & 2//33DIIOODt$&D& !!#t,11$,,M) S\N;&)}}**4==Wf9M+NO*Z 	# :
& &s   "K ,K AK&&K/)	cacheablec                P    t        | t        j                  ft        |       z        S r   )r%  r   r>   r   )r   s    r   r  r  !  s(    	>--/#j/A
C Cr   c                6    t        | dt        |       z  ||      S )Nr   )r  r   )r   r  r=  s      r   r  r  %  s#    
 
'C
O+Y
? ?r   c                   	 t        j                  | |      \  }}t         	fdt        |||j                        D              }t         	fdt        |||j
                        D              }t        d |D              rt        d |D              st        d      t        j                  |||||||	|
|||d}||fS )Nc              3  t   K   | ]/  \  }}}|#t        ||j                  |j                        n| 1 y wr   _pjit_batcher_for_sharding	spmd_namer"  )r   axis_inr   r   	axis_datar_  s       r   r   z _pjit_batcher.<locals>.<genexpr>4  sM      N '1d 
	 !GY-@-@(!%,"#$N   58c              3  t   K   | ]/  \  }}}|#t        ||j                  |j                        n| 1 y wr   r  )r   axis_outr   r   r  r_  s       r   r   z _pjit_batcher.<locals>.<genexpr>9  sM      R (At 
	 !Hi.A.A8!%,#$%Rr  c              3  $   K   | ]  }|d u  
 y wr   r   r   r  s     r   r   z _pjit_batcher.<locals>.<genexpr>?  s     ,Aa4i,rk  c              3  $   K   | ]  }|d u  
 y wr   r   r  s     r   r   z _pjit_batcher.<locals>.<genexpr>@  s     -Aa4i-rk  z1Concrete layouts are not supported for vmap(jit).ro  )
r0   batch_jaxpr2rG  r   r   r   r   r  r   r   )r  vals_indims_inr   r   r@  rL  rM  rp  r_  r   rz   r{   r~   	new_jaxpraxes_outvals_outs   `        `       r   _pjit_batcherr  -  s     !--eYH)X N "'<9K9KL	N N,
  R  #8]I<O<OP	R R- ,,
,
--
-
;= = ZZ
!	-/( 
8	r   c                   t        | t              r| S | j                  |      }|t        j                  |      r| S t        | t
              r]t        | j                  t              rCt        | j                  t        j                  | j                  |t        j                              S |j                         j                         }t        |j                         }|j#                  |d       ||_        t%        | j&                  |      }t        j(                  |gd g| d       d   S t        | t
              rOt        | j                  t              r5t        | j                  t        j                  | j                  ||            S t        | t
              r| j                  }|j*                  rt-        d|       t/        ||      d   }	t        |t        j                  |	||            S )Nr  r   aB  If you are using spmd_axis_name parameter of jax.vmap, please make sure to run your jitted function inside the mesh context manager. Only `jax.lax.with_sharding_constraint` with `jax.sharding.NamedSharding` as an input can be transformed with spmd_axis_name batching rules outside of an explicit mesh context manager scope)r   r?   r  r   is_hlo_sharding_replicatedr9   r   r7   r2   
batch_specspecr.   UNCONSTRAINEDto_protoclonerF  tile_assignment_dimensionsinsertr:   _internal_device_list$_get_out_sharding_from_orig_shardingrr  r   rA   )
r   dimspmd_axis_namer   r"  hlo_snew_optadnew_gsr  s
             r   r  r  W  s    #$H

 
 
&%007h!]#
166<(H
&&$//!&&#}/J/JKM M^^##%F
v00
1CJJsA(+F%122F;F44fXvq$OPQRR!]#
166<(H
&&$//!&&#~>@ @!]#VVdzz
 %!" " %UD1!4DdoodC8: :r   c                   |D cg c]  }t        |      t        j                  u }}t        j                  ||d      \  }}d }t	        ||      }t	        ||      }t        j                  g |  ||      |g | ||      g | ||      g | ||      g | ||      g | ||      ||	|
||d}t        |t        |j                  j                        g      \  }}t        |      t        |j                  j                        k(  sJ t        |      }|t        ||j                        D cg c]'  \  }}|rt        |      nt        j                  |      ) c}}fS c c}w c c}}w )NFinstantiatec                (    d t        | |      D        S )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r   nzr   s      r   r   z3_pjit_jvp.<locals>._filter_zeros.<locals>.<genexpr>  s     1%"abA1r^  )r   is_nz_lr  s     r   _filter_zerosz _pjit_jvp.<locals>._filter_zeros  s    13w?11r   ro  )r   r/   Zero	jvp_jaxprr
   r   r   rZ   r   r   r  iterr   r   next)
primals_intangents_inr   r   r@  rL  rM  rp  r_  r   rz   r{   r~   rk  is_nz_tangents_in	jaxpr_jvpis_nz_tangents_outr
  _filter_zeros_in_filter_zeros_outoutputsprimals_outtangents_outtangents_out_itr  r   s                             r   	_pjit_jvpr  |  s    8CC!tAwbgg-CC"$,,E#3)2],=>m-?@JJ 11$[11C\C$4\$BCGmG&7&FG=:= 0 <=AKA"3K"@AI~I(8(HI/1' )3u{{7J7J3K2LM+|	[	S!4!45	55	5&/	'*+=u'OQ#2t 13tO,E Q 
Q Q3 D2Qs   "E0?,E5c               F   	
+,-./01 t        j                  |       \  }},}1t        |      }t        |j                        |z
  }t        f|z  /d|z  .d|z  -t              t        f|z  z   }t              d|z  z   }t        j                  j                  xr t        j                  |j                         t        j                  j                  xr t        j                  1j                         d }t        j                  |j                        }t        ||g      \  }}t        d |D              sJ t!        |      D cg c]  \  }}}t#        |t$              r||nd  c}}}|z   }~~|D cg c]  }|d u  }}t        j&                  ||      } |||      } |||      }t        ||g      \  }}t)        |      }~~~t        |j                        |z
  }t        |j                  j*                  |g      \  } }!t-        |       D "#ci c]  \  }"}#t/        |#      |" }$}"}#d g|z  |!D #cg c]  }#|$j1                  t/        |#             c}#z   }%|%D cg c]  }|d u  }}t        j&                  ||      } |||      } |||      }~|j                  D &cg c]  }&|&j3                          c}&0+
	 ,-./01fd}'d +t              t        |j4                        k(  sJ t7        j8                  ||||	
d}(t;        |%|(|(      }(t;        |||(      }(t        |(t        |(      |z
  g      \  })}*t;        |g |j<                  ||*      }*|),|*|'fS c c}}}w c c}w c c}#}"w c c}#w c c}w c c}&w )Nr   rY  c                :    t        d t        | |      D              S )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r   r   r  s      r   r   z6_pjit_linearize.<locals>.keep_where.<locals>.<genexpr>       >wq$>r^  r  r  should_keeps     r   
keep_wherez#_pjit_linearize.<locals>.keep_where      >#a"5>>>r   c              3  $   K   | ]  }|d u  
 y wr   r   r   r  s     r   r   z"_pjit_linearize.<locals>.<genexpr>       ,1Q$Y,rk  c                X    |      }t        j                  g | |       z                 z                 z   
	d}t        |      }t              D cg c]'  \  }}|rt	        |      nt        j                  |      ) }}}|S c c}}w rX  )r   r   r  r   r  r/   r  )	residualstangentstangents_nznz_tangents_outnz_tangents_out_r   r  r  r
  r~   r_  rp  rL  r   r{   rz   r   nzsnzs_outrM  r@  res_donatedres_layouts_inres_shardings_intangent_avals_outtangent_jaxprs           r   tangent_funz$_pjit_linearize.<locals>.tangent_fun  s    X.Kjj 3	3 3(5%c<(HH#G];!M#z$BB!';7"]3%GG13O O,%():G%DF!b /1D)*bggdmC FL FFs   5,B&c                :    t        d t        | |      D              S )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r  s      r   r   z9_pjit_linearize.<locals>._filter_zeros.<locals>.<genexpr>  s     6ur126r^  r  r  s     r   r
  z&_pjit_linearize.<locals>._filter_zeros  s    6GQ666r   ro  )r/   linearize_jaxprr   r   r>   rG  r   rF  r   r   check_jaxprr   r  r|  rZ   r   r   r   r?   r}  r  r  r  r   r?  to_tangent_avalr   r   r   r]   r   )2r-  r   r   r@  rL  rM  rp  r_  r   rz   r{   r~   r  primal_jaxprnum_residuals_out
in_fwd_resnum_residuals_innum_primals_outprimal_out_shardingsprimal_out_layoutsr"  r~  in_fwd_primalin_fwd_res_r  r  r  r  r  r   kept_resnum_kept_residualsout_varsres_varsr   r  idx_mapout_fwdr   r4  ans
primal_ansresiduals_ansr
  r.  r/  r0  r1  r2  r3  s2   ` ``````````                               @@@@@@@r   _pjit_linearizerL    s    	$ F,!7J_../2CC/!^&66--.+++}-AR0RR[)G6G,GGE!1!1,2D2D!EF!1!1-2E2E!F?  2 23&)&?2CD-	,,	,,	, ]KG 
"b# ,-"*c$F & =#	$!t)	$$	$..|TB,#$8$?!"4d;4/!23+!X8}
Ho ../2DD/!,"4"4"<"<>OP(H"+H"56$!QRUAX6'6F_$H'MqBqE(:'MM'$	%!t)	%$	%..|TB,#$8$?!"4d;
49OODqq((*D  &7 
\	c,"7"78	88	8

Jl ,!5(1"0$* (<
	># 	'3$#&*c*#(s3x:K/K.LM*mJ(D%,,(D(DmT-	Wm[	88C
 
% 7'M	% Es$   !N	N	&N!N2N6Nc                  |D cg c]  }|j                    }}t        d |D              }t        d |D              }t        j                  ||d      \  }}}}}t        |      }t        d |D              }d } |||      t        ft        |      z  z   } |||      dt        |      z  z   }t        |j                        t        |      z
  }t        j                  |j                        }t        ||g      \  }}t        d |D              sJ t         |||       |||      |      D  cg c]  \  }}} t        |t              r|| nd  c} }}|z   }~~|D !cg c]  }!|!d u  }"}!t        j                  ||"      } |||"      } |||"      }t        |"|g      \  }#}$t        |#      }~"~#~$t        |j                  j                   |g      \  }%}&t#        |%      D '(ci c]  \  }'}(t%        |(      |' })}'}(d g|z  |&D (cg c]  }(|)j'                  t%        |(             c}(z   }*|*D !cg c]  }!|!d u  }"}!t        j                  ||"      } |||"      } |||"      }~"t)        | |||      | |||      | |||      |||	|
|	      }+t        |+d
         t        |+d   j                        k(  sJ t        |+d         t        |+d   j                        k(  sJ |D ,cg c]#  },|,j+                         s|,j-                         % }-},t/        j0                  |-i |+}.t3        |*|.|.      }.t3        ||-|.      }.t        |.t        |.      t        |      z
  g      \  }/}0t5        |0      }1|D !cg c]"  }!|!t7        |1      ng |j8                  |-|!   $ }0}!t7        |1d       J t;        | j<                  |0      }2t        j>                  |dgt        |0      z  dgt        |      z  z         } |||      t        ft        |2      z  z   }3 |||      dt        |2      z  z   }4 |||      dt        |2      z  z   }5t)        ||3|4 |||       |||      |5|||	|
|      }6|D cg c]  }|j                   j+                         r|! }7}|j                  }8|8D 9cg c]6  }9t        j@                  | t        jB                  jE                  |9      d       8 }:}9g |7|2}7t        jF                  | |7|:t.        |6|jH                  tK        jL                               };|:D ]	  }|;|_'         tH        jP                  jS                  |jH                        r/| jT                  jW                  t        jX                  |7|;             t[        ||/|:      S c c}w c c} }}w c c}!w c c}(}'w c c}(w c c}!w c c},w c c}!w c c}w c c}9w )Nc              3  <   K   | ]  }|j                           y wr   )is_known)r   pvs     r   r   z%_pjit_partial_eval.<locals>.<genexpr>  s     5bBKKM5r   c              3  "   K   | ]  }|  	 y wr   r   )r   r  s     r   r   z%_pjit_partial_eval.<locals>.<genexpr>  s     /!e/   Fr  c              3  "   K   | ]  }|  	 y wr   r   )r   uks     r   r   z%_pjit_partial_eval.<locals>.<genexpr>  s     3V3rR  c                :    t        d t        | |      D              S )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r  s      r   r   z9_pjit_partial_eval.<locals>.keep_where.<locals>.<genexpr>  r  r^  r  r   s     r   r"  z&_pjit_partial_eval.<locals>.keep_where  r#  r   r   c              3  $   K   | ]  }|d u  
 y wr   r   r%  s     r   r   z%_pjit_partial_eval.<locals>.<genexpr>  r&  rk  ro  r@  r   rM  TrY  r   r   rL  r@  rM  rp  r_  r   rz   r{   r~   ).pvalrG  r  partial_eval_jaxpr_nounits_fwdr>   r   r   r|  r   rZ   r   r   r   r?   r}  r  r  r  r   r?  r  rO  	get_knownr   r   r]   r  r  r   r   new_instantiated_constmove_binders_to_backJaxprTracer
PartialValr  new_eqn_reciper   r   r  recipepartial_eval_kept_effects	filter_ineffect_handlesr6  EffectHandler\   )<r  r   r   r@  rL  rM  rp  r_  r   rz   r{   r~   
in_tracersrk  in_pvals	known_insunknown_insknown_jaxprunknown_jaxprunknown_outsres_out_avalsr<  
known_outsr"  known_out_shardingsknown_out_layoutsnum_out_primalsr~  rA  rB  r  r  r  r  r  kept_primalsrC  rE  rF  r   r  rG  rH  known_paramsrP  known_inputsall_known_outsknown_out_valsresidual_valsresidual_vals_residual_tracersunknown_in_shardingsunknown_in_layoutsunknown_donated_invarsunknown_paramsunknown_tracers_inunknown_out_avalsr   unknown_tracers_outr  s<                                                               r   _pjit_partial_evalr    s.   
 ))aff)()5H55)/Y//+''{N F+}lM:|$,3l33*? $M:>'>C,>>?!+z: 3}#556 --.]1CC/11+2C2CD&)&?2CD-	,,	,,	, 
]J
/
[*
-}> 
"b# ,-"*c$F
 & [#	$!t)	$$	$--k4@+"#6= !2D9%d_,=>,%/
L( "+"3"3";";o=NO(H"+H"56$!QRUAX6'6F_$H'MqBqE(:'MM'$	%!t)	%$	%--k4@+"#6= !2D9
jy&I'J	2#	:[/1, 
\/*	+s<3H3R3R/S	SS	S	\-(	)Sg1F1P1P-Q	QQ	Q ,4ERr{{}",,.E,E::|<|<.WnnE.V\>B. #n"5M8J"J!KL  .-&.CMO>? ,-94'6%,,66q9: O- O	nd	#	++	+55}E ))dVc-00E7S=M3MMO- %\;?(NS1A-BBC":{;!C(8$99:&~{C&-=)>>?'#}l;[,7+/1. $.GaQVV__5FGG#-- $
 	nnUBMM11$7>  @+?.>?
%!3-('//*224	6# .a3.&&001F1FG	0BC HI	\>3F	GGs *. 
% 7'M	%& FO> HsG   V4!V#V (V%
!V+4V0+V5V58'V:-V?V?#;Wc           
        t        j                  | |d         \  }}	t        j                  | |d         \  }
}	t        j                  ||d         \  }	}t        j                  | |d         \  }}	t        j                  ||d         \  }	}t        |t        |
      g |t        g|z  t        |      g |d g|z  t        |            }t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ t        j                  ||d         \  }	}dg|z  |z   }t        j                  ||d         \  }	}g t        g|z  |}t        j                  ||d         \  }	}t        j                  ||d         \  }	}g d g|z  |}t        j                  ||d         \  }	}t        |t        |      t        |      t        |      t        |      t        |            }t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ t        |d         t        |d   j                        k(  sJ ||fS )	Nrp  r   r@  rL  rM  )r   r@  rL  rM  rp  r   F)r  partition_listr  rG  r>   r   r   r   )unks_ininst_inkept_outs_knownkept_outs_stagednum_res_out
num_res_inparams_knownparams_stageddonated_invars_knownr   in_shardings_knownout_shardings_knownin_layouts_knownout_layouts_knownnew_params_knowndonated_invars_stagedin_shardings_stagedout_shardings_stagedin_layouts_stagedout_layouts_stagednew_params_stageds                        r   (_pjit_partial_eval_custom_params_updaterr    s_    --g|DT7UV++G\.5QRa,,_l?>[\!))'<3MNA**?L<WX!,',-?'@)G*= )G+6-+*E)G%*+;%<&Q(9&QTF[<P&Q)./C)DF 
n-	.#l76K6T6T2U	UU	U	o.	/3|G7L7V7V3W	WW	W	l+	,L4I4R4R0S	SS	S	m,	-\'5J5T5T1U	UU	U  ..wFV8WX! 'J.1FF,,WmN6ST!K;-*4K7JK--.>o@^_!**7M,4OP!@+@.?@++,<mM>Z[!=(-.A(B)./C)D&+,=&>',-?'@*/0E*FH 
~.	/3}W7M7V7V3W	WW	W	/	0Cg8N8X8X4Y	YY	Y	|,	-]75K5T5T1U	UU	U	}-	.#mG6L6V6V2W	WW	W	,	,,r   c                  t        j                  |      \  }}t        || f      \  }}|D cg c]:  }t        |      x}j                  rt        j                  |t        |            n|< }}t        ||g ||      \  }}t        ||      D cg c]"  \  }}t        |t         j                        r!|$ c}}t        | |      D cg c]"  \  }}t        |t         j                        r!|$ c}}z   }t        ||      D cg c]"  \  }}t        |t         j                        r!|$ c}}t        | |      D cg c]"  \  }}t        |t         j                        r!|$ c}}z   }t        ||j                        }t        d t        ||      D              }t        d t        ||      D              }	 t!        j"                  ||t        |      t        |      ||dt%        |      z  |||	|
|d}t        |t        |            D ]1  \  }} t        |t         j                        s!|j9                  |        3 y c c}w c c}}w c c}}w c c}}w c c}}w # t&        j(                  $ rs}t+        d       	 t        j,                  |j.                  d|j0                  ||        t'        j2                  |       n# t4        t6        f$ r}|d d }~ww xY wY d }~d }~ww xY w)Nc              3  Z   K   | ]#  \  }}t        |t        j                        r| % y wr   r   r   AbstractValue)r   r   r   s      r   r   z(_pjit_transpose_fancy.<locals>.<genexpr>  -      DDAq!+At/A/A!B   D   )+c              3  Z   K   | ]#  \  }}t        |t        j                        r| % y wr   r  )r   r   r  s      r   r   z(_pjit_transpose_fancy.<locals>.<genexpr>  r  r  rY  rX  zqInvalid nan value encountered in the backward pass of a jax.jit function. Calling the de-optimized backward pass.F)r/   project_accumsrJ   r!   rc  r   rd  r"   _transpose_jaxpr_fancyr   r   ValAccumr  rK   r   rG  r   r   r   r   r   printbackward_pass3r   r   _raise_no_nan_in_deoptimizedr   ZeroDivisionErroraccum)!cts_inr   r   r@  rL  rM  rp  r_  r   rz   r{   r~   r   primals_ctrefsspecsin_flatr%  r   r   r   trans_jaxprr   r   trans_in_shardingsr  trans_in_layoutscts_out_trans_out_shardingstrans_out_layoutscts_outr   r  cts!                                    r   _pjit_transpose_fancyr    s    ++D1.%!>6":;'7%' 4:!9na-E-Edll1gaj) '( '08uU+x |,NTQJq4MqN/NTQz!RWW7MqNO  z*MTQ*Q2LqM-LTQZ2775KqLM  Hk&;&;<( DC,,G D D DC*,G D D/jj	%8J2K)*:M%hW6M+f13G$ 4':; /ea!R[[!1772;/G'
 ONML 
	,	, 
/	 > ?/UELL$G ++A.  12 D
 /
/sq   ?I"I4I
"I-I"I)I?"I"I;=I   K&3K!?-K,K!KKKK!!K&c                
   	 d 		 fd} j                   j                  j                         }t        j                  t        j                  ||      |      \  }}}t        j                  ||      	j                  fS )Nc                      y r   r   r   r   r   r4  z(_transpose_jaxpr_fancy.<locals>.<lambda>      r   c                 N   t        |       \  }}t        j                  	|      }t        j                  j                  dj
                  ||       |D cg c].  }t        |t        j                        r|j                         nd 0 }}t        |      \  }_
        |S c c}w )NF)rK   r/   unproject_accumsr  r   r   r   r  freezerJ   r   )
r  r  r  r   r   r  cellr%  r   r  s
         r   
transposedz*_transpose_jaxpr_fancy.<locals>.transposed  s    +GW=NFun5Dekk5%,,fEKOPaZ2;;7qxxzTAPGP)'2GT]N Qs   3B"rW  )
r   r*   with_unknown_namesr  r  rk  rs  r   r  r   )
r   r%  r   r  r  r  r  r   r   r  s
   `` `     @r   r  r    sj    	$ 	113#44ll:#.:+q&			+v	.	==r   c                    t        j                  | j                  |      \  }}t        j                  || j
                        |fS r   )r  	dce_jaxprr   r   r  r   )r   used_outputsr  used_inputss       r   _dce_jaxpr_pjitr    s9     <<\B)[			)U\\	2K	??r   c                   t        |       s0t        j                  |      sdgt        |j                        z  d fS t        |j                  d   t        |             \  }}d }|j                  }t        || ||d   |       ||d   |        ||d   |       ||d   |        ||d   |      	      }t        |      st        |       s|j                  s|d fS t        j                  |      }t        j                  t        |j                  |      D 	cg c]
  \  }}	|	s	| c}	}t        |j                  |       D 	cg c]
  \  }}	|	s	| c}	}|j                  |||j                   |j"                        }
||
fS c c}	}w c c}	}w )
NFr   c                :    t        d t        | |      D              S )Nc              3  ,   K   | ]  \  }}|s	|  y wr   r   r  s      r   r   z:dce_jaxpr_pjit_rule.<locals>.keep_where.<locals>.<genexpr>  s     9wq$D9r^  r  )r  keepss     r   r"  z'dce_jaxpr_pjit_rule.<locals>.keep_where  s    9#b%.999r   r   r@  rL  rM  rp  )r   r   r@  rL  rM  rp  )r   r  has_effectsr   r  r  r   rG  r  r   r   r  new_jaxpr_eqnr   r  	primitivero  r  )r  r  
dced_jaxprr  r"  
eqn_paramsr  new_effsr  usednew_eqns              r   dce_jaxpr_pjit_ruler    sm   	\	2>>##67S_$d**+	jj5.0*k: zz*j8+Fz/:LIJ|4kBZ6E
+; <kJ* 
[	#l"3J<N<N
+H  cjj+6?wq$$?ckk<8Awq$DAz8S__cggGG  	@As   
F 
"F 

FFc           	        t        | j                        }|d= t        |d         s|d= t        d |d   D              r|d= t        d |d   D              r|d= t        d |d   D              r|d= t        d	 |d
   D              r|d
= |d   s|d= |d   j                  r|d= |d   s|d= |d   j
                  |j                  vrf|j                  |d   j
                  j                  | j                         |j                  |d   j
                  j                  | j                         |d= t        j                  | ||dgt        |      z         S )Nr{   rp  c              3  <   K   | ]  }t        |t                y wr   rf  r   r   s     r   r   z _pjit_pp_rule.<locals>.<genexpr>	  s     IQA'	(Ir   r   c              3  <   K   | ]  }t        |t                y wr   rf  r  s     r   r   z _pjit_pp_rule.<locals>.<genexpr>!	  s     JQA'	(Jr   r@  c              3  $   K   | ]  }|d u  
 y wr   r   r  s     r   r   z _pjit_pp_rule.<locals>.<genexpr>#	  s     1qd1rk  rL  c              3  $   K   | ]  }|d u  
 y wr   r   r  s     r   r   z _pjit_pp_rule.<locals>.<genexpr>%	  s     2qd2rk  rM  rz   r_  r~   r   r   r  )r  r   r   r   rr  r   shared_jaxprssuggest_same_var_namesr  r  r   _pp_eqnr  )r  contextsettingsr   s       r   _pjit_pp_ruler  	  s^    

&X	V$%	& I&2HII~J&2IJJ1F<011|2F=122}		}Jz	&	'%&G_'"7"77""6'?#8#8#?#?L""6'?#8#8#@#@#++N Vn	c7HfXv5N	OOr   c                    t        | t              sy | j                  j                  t	        fd| j
                  D              st        d| j
                   d d      y )Nc              3     K   | ]\  }|t         j                  urH|Ft        |t              r|n|fD ].  }j                  |   t
        j                  j                  k(   0 ^ y wr   )r.   r  r   rG  _name_to_typer  AxisTypeAuto)r   axesr   r   s      r   r   z+check_shardings_are_auto.<locals>.<genexpr>?	  sn      G]888T=M *4 7dWG  "h&7&7&<&<< G< Gs   A"A%zoThe spec of NamedSharding passed to with_sharding_constraint can only refer to Auto axes of the mesh. Got spec=z
 and mesh=z*. You probably meant to use `reshard` API?)r   r9   r   r  r   r  r   )r   r   s    @r   check_shardings_are_autor  ;	  st    	A}	%
	
		$	 G&&G 
G 	::;&& B@	BC C	
Gr   c                j   | j                   j                  }|j                  j                  | j                        }t        j
                  j                  r t        j                  ||j                        }t        ||      D ]/  \  }}|t        j                  u r||k7  st        d| d| d       y )Nzo`with_sharding_constraint` acts as an assert when all axes of mesh are of type `Explicit`. The array sharding: z& did not match the sharding provided: zQ. Please use `jax.sharding.reshard` to shard your input to the sharding you want.)r8  r  _normalized_spec_for_avalr"  r   #remove_size_one_mesh_axis_from_typer   r   remove_size_one_mesh_axisr   r   r.   r  r   )x_avaluser_shardingx_spec	user_specr   r   s         r   assert_shardings_equalr  H	  s    ??&  ::6;;G)//55..y-:L:LMI&)$ 
daM'''	
aAAG I11: < 	
r   c           
        t        |       \  }}|D  cg c]  } t        j                  |        }} t        |      \  }}t	        |dd      }~t        t        d||            }~t        t        d||            }~t        j                         j                  st        j                         }	nWt        j                         j                  st        j                         }	n$t        j                  j                  j                  }	|D 
cg c]  }
t        |	|
dd       }}
t        ||      D ]*  \  }}t!        |t"        t$        f      st'        d| d       ~|D cg c]'  }t!        |t(              rt+        |      n	t-               ) }}t/        ||d	t1        |      z  d
dd       t3        ||d	t1        |      z  d
       g }t        |||||      D ]  \  }}}}}t        j                         j4                  r0|.t!        |t(              rt7        ||       |j9                  |       Wt;        |       |j9                  t<        j?                  ||||	|              tA        ||      S c c} w c c}
w c c}w )a  Mechanism to constrain the sharding of an Array inside a jitted computation

  This is a strict constraint for the GSPMD partitioner and not a hint. For examples
  of how to use this function, see `Distributed arrays and automatic parallelization`_.

  Inside of a jitted computation, with_sharding_constraint makes it possible to
  constrain intermediate values to an uneven sharding. However, if such an
  unevenly sharded value is output by the jitted computation, it will come out
  as fully replicated, no matter the sharding annotation given.

  Args:
    x: PyTree of jax.Arrays which will have their shardings constrained
    shardings: PyTree of sharding specifications. Valid values are the same as for
      the ``in_shardings`` argument of :func:`jax.experimental.pjit`.
  Returns:
    x_with_shardings: PyTree of jax.Arrays with specified sharding constraints.

  .. _Distributed arrays and automatic parallelization: https://docs.jax.dev/en/latest/notebooks/Distributed_arrays_and_automatic_parallelization.html
  r=  TrA  z"with_sharding_constraint shardingsz with_sharding_constraint layoutswith_sharding_constraintz7One of with_sharding_constraint arguments got sharding zJ which is not allowed. Please only pass `jax.sharding.Sharding` instances.r   z"with_sharding_constraint arguments)r  r  r8  r7  rb  unconstrained_dims)!rJ   r   r  r>  r@   rG  r$   r  r  rr  get_abstract_meshr  r  r  r\  r   r   r?   r=   r   r9   get_unconstrained_dims	frozensetr  r   r  are_all_axes_explicitr  r6  r  sharding_constraint_pr   rK   )r   r=  x_flatr  x_avals_flatr<  user_shardingsuser_shardings_flatuser_layouts_flatrb  r   shardings_flatr   ur  r   xfr  r  uds                       r   r  r  Z	  s   ( a,&$6<=$))!,=,=1)<'9)t=.7~NP5tWEG		#	#	%	+	+--/L%%'----/L,,00>>L 12 /|Q/IK 2. 2 ."56 Oda!&-.CA3 GN NO OO
  "01 &a7 /q1=F[I 1 1 lEC,?$?* t= ""3\"'#.?*@"@"FH 
$!&,"35GI 
"b&!Q""$::qy1m$VQ'
kk"oq!
kk',,
q - ! "
" 
d	##u >,21s   I.
I3,I8c                    | S r   r   r3  s    r   _identity_fnr   	  s    AXr   c           	     N   t        |t              rt        |j                  t              r|j                  sVt        |t              rFt        | d      s:t        j                         }|j                  rJ t        ||j                        }nJt        j                  |       }t        | d      s(t        dt        |        d|j                                t        | j                  t              s2t        dt        | j                         d|j                                | j                  j                  j                   |j                  j                   k7  rTt        d| j                  j                  j                    d|j                  j                    d|j                                t        | j                  j                  |j                        }|! t#        j$                  t&        |      |       S  t#        j$                  t&        t)        ||            |       S )	Nr8  ztTarget sharding contains a `jax.sharding.AbstractMesh` which requires the input passed should be a `jax.Array`. Got z with shape z}The sharding on the input must be a `NamedSharding` since the target sharding has an `AbstractMesh` in it. Got sharding type z for shape zMesh shape of the input z6 does not match the mesh shape of the target sharding r@  )r   r9   r   r7   rr  r   r  r  r  r   r  r   r   r   r8  r   shape_tupler   r   r   rD   )r   r8  r7  rb  r  concrete_meshr   s          r   _sharding_constraint_implr  	  s   =)-:lL#IAz"002m$$$$}hmm<h$$Q'dQ
#QyT^^%5$689 	9 

M2QZZ !T^^-=,>@A 	A 
	$	$(A(A	A&qzz'B'B&C D))*+dnn6F5GIJ 	J qzz>h^8377<x8;;H377<vfh/GHKKr   sharding_constraintc                0    t        j                  | fi |fS r   )r  r   r  r   r   s      r   r4  r4  	  s    '<'A'A"'O'O&Q r   c                   t        |t              r@| j                  | j                  j                  |j                  j
                              S | j                  d       S )Nr   r8  )r   r9   updater8  r   r  )r  r8  r7  rb  r  s        r   "_sharding_constraint_abstract_evalr  	  sT    -(==''X]]-H-H'I  K K		%%r   c                  | j                   \  }| j                  \  }| j                  j                  }t	        |t
              rt        d |j                  j                  D              r|j                  j                  |j                        }	g }
t        |	|j                  j                        D ]  \  }}||
j                  |       t	        |t              r|n|f}|t        j                  u rt         ||
j                  |       [t	        |t              r|
j                  ||z          |
j                  ||fz           |j#                  |
      }t%        j&                  |j(                  t$        j*                        rt-        j.                  |      }t	        |t0        j2                        r-|j4                  r!t7        j8                  |||j                        }t:        j<                  j>                  r|jA                  |j                        }n)|jC                  |j                        jE                         }t7        jF                  | ||||      }|t7        jH                  | ||||      }|gS )Nc              3  $   K   | ]  }|d u 
 y wr   r   ri  s     r   r   z4_sharding_constraint_hlo_lowering.<locals>.<genexpr>	  s     	8A!4-	8rk  r  )unspecified_dims)%avals_inr  r  r  r   r9   r   r8  r  r  r"  r   r6  rG  r.   r  r  r  r   r   r   r   r   physical_avalr   r  manual_axesr1   add_manual_axesr   use_shardy_partitionerr   _to_sdy_shardingr  r  wrap_with_sharding_opwrap_with_layout_op)r  x_noder8  r7  rb  r  in_avalr  r  r  new_specr  	aval_specr  s                 r   !_sharding_constraint_hlo_loweringr  	  s   \\('mm)(,,(=)		8!2!2!7!7	88==227<<@DH #D(*;*;*@*@ A 4	9			"!+Iu!=II<	333#
#
//)
$	5)
//)i/
0
//)yl2
34 H-Hw}}foo6  )G>99:##HhEH""((((6H,,W\\:CCEH""	68X8J	L#

"
"3Xvw
GC
,r   c           	     d   | j                   t        |t              rr|j                  D ch c]  }t        |t              r|n|fD ]  }|   }	}}t        | j                         |	z  r%t        d| j                    d|j                         |\  }
|\  }|D ch c]
  }|||k  z    }}| j                   |j                  |       t        ||| j                   ||
j                        }|rt        |t              rrt        |j                        d g|
j                  t        |j                        z
  z  z   }|D ]  }t        j                  ||<    t        |j                  t        |       }|t        ||      n|}t         j#                  |
|||t%        |            }||fS c c}}w c c}w )Nzvmap spmd_axis_name z> cannot appear in with_sharding_constraint spec, but got spec r  )r  r   r9   r  rG  setr   r  r  r"  rF  r   r.   r  r   rG   r  r   r  )r  r  r  r8  r7  rb  r  r  r  r  r   rX  r  vmapped_shardingr  r  vmapped_layoutr  s                     r   _sharding_constraint_batcherr"  
  s    $Hm)L  ?"&r51bu?  ?A ?D ?
9$&-i.A.A-B CF"--* + + "!"!1CD2a2gDD 1/9&&aff>J'7G$))*dVqvvDTDYDY@Z7Z-[[H 0!//hqk0$}h79 7=6H'62    "#56 ! 8! 
A+=? Es   #F'F-c                     yNr   r   r   s    r   r4  r4  ,
  r  r   c                L   t        |       \  }}t        d||d      }|D cg c]  }t        j                  |       }}g }t	        |||      D ]  \  }}}	t        |	dd      }
|
t        d|	 d      |
j                  |
j                  j                  |j                        	      }
t        |	t              r0t        |	j                  t        j                        r|	j                  nd }|j!                  t"        j%                  ||
|
              t'        ||      S c c}w )Nzreshard out_shardingsTr  reshardF)check_mesh_consistencyziReshard should only be used with out_shardings which are non-None and have a nonempty mesh. Got sharding r  r  dst_shardingr  )rJ   r  r   r  rW   rB   r   r  r  r  r"  r   r9   r   r  Meshr6  	reshard_pr   rK   )r  r@  r  r;  r  r   r  r   r  r   dscmeshs               r   r'  r'  0
  s    $/&')w4I.6<=$))!,=,=(v|^D Mla	q)E	JB	z4453a9  
99&++F	GB"1m4"1668==9 VV 
 OOINN12UNKLM 
	** >s   D!r'  c                   t        | t        j                        sJ | j                  |k(  r| S | j	                  |      S )Nr
  )r   r   rF  r8  r  )r   r*  r  s      r   _reshard_abstract_evalr0  G
  s:    	D$**	++	+	]]l"K	l	++r   c                     fd} |       S t        j                        5   |       cd d d        S # 1 sw Y   y xY w)Nc                 >    t        j                  t               S Nr)  )r   apply_primitiver,  )r  r*  r   s   r   r4  z_reshard_impl.<locals>.<lambda>O
  s    (**]L r   )r   set_mesh)r   r*  r  thunks   ``` r   _reshard_implr7  N
  s@    L%7N		 	 	/ W  s	   :Ac                  t        j                  |      sJ |j                  j                         j                  }t        j                  |j                        5  t        j                  | ||      }|gcd d d        S # 1 sw Y   y xY wr3  )
r/   is_undefined_primalr   to_cotangent_avalr8  r  r  r   r,  r   r  r   r*  r  out_shardingx_bars         r   _reshard_transpose_ruler>  X
  sv    				""	"))+44,!!,"3"34 NN2L)6  8E7  s   B  B	c               >   t        |t        j                        sJ |j                  j	                         j
                  }t        j                  |j                        5  t        j                  | ||      }|j                  |       d d d        y # 1 sw Y   y xY wr3  )r   r/   	GradAccumr   r:  r8  r  r  r   r,  r   r  r;  s         r   _reshard_transpose_fancyrA  a
  s|    	Ar||	$$	$))+44,!!,"3"34 NN2L)6  8EGGEN  s    *BBc                  | j                   \  }| j                  \  }t        j                  |j                  t        j
                        rt        j                  |      }t        j                  j                  r|j                  |j                        n(|j                  |j                        j                         }t        j                   | |||      gS r   )r  r  r   r   r   r   r   r  r   r  r   r  r"  r  r  r1   lower_with_sharding_in_types)r  r  r*  r  aval_inaval_outprotos          r   _reshard_hlo_loweringrG  j
  s    \\('mm)(w}}foo6  )G++11 ((6,,W\\:CCE  
+
+C5
I	JJr   c                x    |\  }|\  }t        j                  | ||      }t        j                  |||      }||fS r3  )r0   get_sharding_for_vmapr,  r   )	r  r  r  r*  r  r   rX  vmapped_dst_shardingr  s	            r   _reshard_batcherrK  u
  sL    "!"!!77q"nnQ%9#0  2!	
A+r   c                     yr$  r   r%  s    r   r4  r4  ~
  r  r   c           	        t        j                         }t        |      \  }}t         j                  }|D ]l  }t	        |t
              s|j                  s7||j                  j                  k7  rt        d| d| d|j                         |j                  j                  }n |j                  r|j                  rt        d| d| d      |j                  s&|j                  s||k7  rt        d| d| d      |}	n7|j                  r|j                  s|}	n|j                  s|j                  sJ |}	| |	j                  } t	        | t              s| f} | D ]n  }
|	j                  |
   t         j                  j                  k(  s.|t         j                  j                  t         j                  j                   hv set#        d	       |	j%                  | D 
ci c]  }
|
| c}
      |	| fS c c}
w )
NzShardings passed to z) should have the same mesh. Got one mesh z and another zContext mesh zY cannot be empty. Please use `jax.set_mesh` API to enter into a mesh context when using `z` API.z) must match the mesh passed to shardings z@. Recommended approach is to use `jax.set_mesh` context manager.zGoing from `Manual` AxisType to `Auto` or `Explicit` AxisType is not allowed. Please file a bug at https://github.com/jax-ml/jax/issues with your use case)r  r  rJ   empty_abstract_meshr   r9   rr  r   r  r   
axis_namesrG  r  r  Manualr  Explicitr  update_axis_types)r  	axis_typer   r=  cur_meshflat_shardingsr   sharding_meshr   mesh_to_user   s              r   _get_new_meshrX  
  s   '')("9-.!..- +a!]#  ]aff6J6J%J"4& )"O=:; 	; ff**m+ X^^

z "F&	  
		X^^ ( $_ --. . K8>>K""x~~55K	\!!D	D%	 7D !a!!!$(9(9(@(@@h'',,h.?.?.H.HII ! !! 
'
't(D!I(D
E
t
 (Ds   
G.)r  r<  c              D    t        ||      | fdS t        | fi S )N)axes_r<  c                    t        | fi S r   )
_auto_axesgr   s    r   r4  zauto_axes.<locals>.<lambda>
  s    Z,V, r   )r  r\  )r  r  r<  r   s      @r   	auto_axesr_  
  s*    d6&Y,,	A	 	  r   c               6     t                fd       }|S )Nc                    
!d|v r|j                  d      }nt        d      
}t        t        j                  j
                  d|      \  }}t        |j                        t        |      k(  r 	| i |S t        j                        5  t        fd|       }t        | |      }  	| i |}d d d        t        |      S # 1 sw Y   xY w)Nr<  z1Missing required keyword argument: 'out_sharding'r_  )r=  c                ~    t        j                  t        j                  |       j                  j                        S r   )r   modify_spec_for_auto_manualget_avalr8  r  )r   new_meshs    r   r4  z/_auto_axes.<locals>.decorator.<locals>.<lambda>
  s,    D$D$D
--

#
#
(
((%4 r   )popr   rX  r  r  r  r  r_  r  rS   r'  )r   r   _out_sharding	prev_meshr  in_specsr  re  rZ  r   r<  s          @r   	decoratorz_auto_axes.<locals>.decorator
  s    	6	!

>2KLL"m -x  %%{m!MHi
93t9,$!&!!		#	#H	- ! 459;hT8$d  c	!
 3&&! !s   $C		CrX   )r   rZ  r<  rj  s   ``` r   r\  r\  
  s!    :' '$ 
r   r  in_shardingc              D    t        ||      | fdS t        | fi S )Nrl  c                    t        | fi S r   )_explicit_axesr]  s    r   r4  zexplicit_axes.<locals>.<lambda>
  s    ^A00 r   )r  rp  )r  r  rm  r   s      @r   explicit_axesrq  
  s*    T{3&Y00		$V	$$r   c               6     t                fd       }|S )Nc                 N   	!d|v r|j                  d      }nt        d      	}t        t        j                  j
                  d      \  }}}t        j                  |      5  t        | |      }  | i |}d d d        t        d       }t        ||      S # 1 sw Y   "xY w)Nrm  z0Missing required keyword argument: 'in_sharding'rq  c                    t        j                  t        j                  |       j                  j                  t        j                               S r   )r   rc  rd  r8  r  r  r  )r   s    r   r4  z3_explicit_axes.<locals>.decorator.<locals>.<lambda>
  s5    4#C#Ca!!&&(B(B(D$F r   )	rf  r   rX  r  r  rQ  r  r'  rS   )
r   r   _in_shardingre  r   r  	out_specsr  r   rm  s
          r   rj  z!_explicit_axes.<locals>.decorator
  s    	&	 zz-0JKK l"4):):)C)C#24NHa		#	#H	- !T<(d  c!  FGJLI3	""! !s   %BB$rk  )r   r  rm  rj  s   ``` r   rp  rp  
  s!    :# #  
r   c           	        t        |       \  }}|D  cg c]  } t        j                  |        }} t        t	        d||            }t        d |D              r%t        d|D cg c]  }t        |       c}       t        ||dt        |      z  d       t        ||      D cg c]  \  }}t        j                  ||       }}}t        ||      S c c} w c c}w c c}}w )Nzwith_layout_constraint layoutsc              3  >   K   | ]  }t        |t                 y wr   )r   rE   r  s     r   r   z)with_layout_constraint.<locals>.<genexpr>
  s     9qZ6"	"9s   zIlayouts passed to `with_layout_constraint` must be of type `Layout`. Got r  z with_layout_constraint argumentsr7  )rJ   r   r  rG  r$   r   r   r   r  r   r   layout_constraint_pr   rK   )	r   r<  r  r  r  layouts_flatr  r  r   s	            r   with_layout_constraintr|  
  s    a,&$6<=$))!,=,=|$Dd$+- .,9L99
	,89q479:	<= = "L%#l*;";(* 6<0
2b! 
"
"2a
"
0 
2$ 
2	d	## > :
2s   C#C
'!C!layout_constraintc                    | S r   r   )r   r   s     r   r4  r4  
  s    Q r   c                0    t        j                  | fi |fS r   )rz  r   r  s      r   r4  r4  
  s    ':'?'?'Mf'M&O r   c                  t        | t        j                        st        dt	        |              | j
                  j                  |k(  r| S  t        j                  t        t        || j                              |       S )NzLwith_layout_constraint in eager mode can only be applied to jax.Arrays. Got r  )r   r   r   r   r   r  r7  r   r   r   rD   r8  )r   r7  s     r   _layout_constraint_implr  
  sj    	Ar||	$
	 G9	&' ' XX__H	HVFAJJ-G	H	KKr   c               n    | j                   \  }| j                  \  }t        j                  | ||||      gS r   )r  r  r1   r  )r  r  r7  r   r  s        r   _layout_constraint_hlo_loweringr  	  s4    
,,%$mm)(

"
"3&$
G	HHr   c                `    |\  }|\  }t        ||      }t        j                  ||      }||fS )Nry  )rG   rz  r   )r  r  r  r7  r   rX  r!  r  s           r   _layout_constraint_batcherr    s:    "!"!&q&1.q8!	
A+r   c                     yr$  r   r%  s    r   r4  r4    r  r   c                h    | j                   J t        d t        | j                         D              S )Nc              3  J   K   | ]  \  }}|t         j                  u r|  y wr   )r.   r  )r   r   r  s      r   r   z)get_unconstrained_dims.<locals>.<genexpr>  s)      ;Dm999  ;s   !#)r  r  r  r
  s    r   r  r    s4    		""	"	 ;Ihmm$< ; 
; ;r   )r   r   r   ra   )r   Sequence[ArrayLike]r  z&pxla.MeshExecutableFastpathData | None)r  re   r  )r   r   r   r   r@  r   rq   int | Sequence[int] | Noners   str | Iterable[str] | Nonert   r  ru   r  rz   re   rw   rv   ry   rx   r{   re   rK  dict[str, Any] | Noner|   re   r  ra   )r   r   r   r   r@  r   rq   r  rs   r  rt   r  ru   r  rz   re   rw   rv   ry   rx   r{   re   rK  r  r|   re   r  r   )r   r   r  ra   r_  mesh_lib.Meshr  core.DebugInfor   rh   r   rT  r   z%tuple[core.AbstractValue, ...] | Noner  tuple[PjitParams, list[Any]])r   r   r   ra   r  zjax_jit.ArgumentSignaturer   rU  r_  r  r  r  )
r   r   r  ra   r   rh   r   rT  r  z#tuple[PjitParams, list[core.Value]])
r   r   r  ra   r   rh   r   rT  r  r  )r   r   r  zCallable[[], core.DebugInfo]r  rU  )r   r   r   r   r@  r   rq   r  rs   r  rt   r  ru   r  rz   re   rw   rv   ry   rx   r{   re   rK  r  r  r  )r*   r  )r  rG  r^  rG  r*   zlu.DebugInfor  ztuple[Sequence[str], int])
r   lu.WrappedFunr  re   r  r  rZ  rG  r  float)
r   r  r  z-core.InputType | Sequence[core.AbstractValue]r  r[  r  rx  r  zCtuple[core.ClosedJaxpr, list[core.Value], list[core.AbstractValue]])r  rF  )r  r[  rY  )r  r  r  rb   r  re   r  re   )r  r  r  rb   )r  re   )r  $Sequence[Layout | AutoLayout | None])r#  Sequence[PjitSharding]r  r  )r   core.ClosedJaxprr  pxla.MeshComputation)r   r  )r   r  rL  pxla.MaybeLayoutrM  r  r   rb   rz   re   r{   re   r~   r}   r'  tuple[str, ...] | Noner(  zmlir.LoweringParametersr   zprofiler.PGLEProfiler | Noner  r  )r   r  r  zlist[core.AbstractValue])r  mlir.LoweringRuleContextr   rb   r   r  r  r[  )r  r  r   rb   r   r  )r   r  r  r  )r   r  r  zSequence[core.AbstractValue]r=  r  r  r  )r  rp   r   r  )r  r[  r  r  r"  r[  )r  zpe.JaxprTracer   r  )r  Sequence[bool]r  r  r  r  r  r  r  r[  r  r[  r  r  r  r  r  ztuple[dict, dict])r   r  r  ztuple[bool, ...]r  z#tuple[core.ClosedJaxpr, list[bool]])r  z
list[bool]r  core.JaxprEqnr  z'tuple[list[bool], core.JaxprEqn | None])r  r  r  zcore.JaxprPpContextr  zcore.JaxprPpSettingsr  zcore.pp.Doc)r   r8   r  None)r  r9   r   )r  str | tuple[str, ...] | NonerS  zmesh_lib.AxisTyper   rb   )r  r  )r8  r9   (  
__future__r   collectionsr   collections.abcr   r   r   dataclassesr   r	   	functoolsr
   inspectry  rS  typingr   r   r   rC  numpyr6  jax._srcr   r   r   r   r   r   r   r   rk  r   r  r   r   r   r   r   r   r   r   r    r  jax._src.corer!   r"   jax._src.api_utilr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   jax._src.interpretersr-   r  jax._src.partition_specr.   r/   r0   r1   r2   jax._src.lib.mlirr3   jax._src.lib.mlir.dialectsr4   r  jax._src.libr5   r6   r   jax._src.meshr7   jax._src.shardingr8   jax._src.sharding_implsr9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   jax._src.layoutrD   rE   rF   rG   jax._src.state.typesrH   jax._src.traceback_utilrI   jax._src.tree_utilrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rH  rS   jax._src.typingrT   jax._src.utilrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r   
unsafe_mapr   
unsafe_zipregister_exclusion__file__PjitShardingPjitShardingMinusUnspecifiedMeshShardingMeshShardingMinusUnspecified	getLoggerr   rw  ra   r   r   r   r  PjitFunctionCacher  r  r  r"  r  r  r  r  r>  rN  rQ  rS  r  r  r/  r   r  r  Wrappedr  r  r  r\  ru  r  r  r  rv  r  r  r   rr  r  r-  r|  WeakKeyDictionaryr  r  rw  rz  rx  r  r  	Primitiver   is_effectfulmultiple_resultsskip_canonicalizationr  r   r  to_lojaxr  r  r  r  r  r%  r*  r>  r,  r4  r   r   rU  r`  def_implr)  rv  custom_staging_rulesr  r  forwarding_rulesr  r  custom_typechecksr  def_effectful_abstract_evalr  r  register_loweringr  r  r  fancy_primitive_batchersr  r  primitive_jvpsrL  primitive_linearizationsr  custom_partial_eval_rulesr  $closed_call_partial_eval_custom_rulepartial_eval_jaxpr_custom_rulesr  r  fancy_transposesr  r  	dce_rulesr  pp_eqn_rulesr  r  r  r   r  r  
deflinear2r  def_abstract_evalr  r"  skippable_batchersr'  r,  r0  r7  r>  rA  rG  rK  rX  r_  r\  rq  rp  r|  rz  r  r  r  r  r   r   r   <module>r     sz   # # 8 8 *     ) )          & % !  # %  #   % )A A A 5 1 $ * & &   ;   ) & &! ! ! !
 L K * 0- - - &   
 CZCZ ! ! !( +]$4d:;$]D%89 ]$4d:;$]D%89 			8	$#z #L/=d3'32'3 
0'3\ 7744d4C  ')gg&?&?&?&N #$1f M M
 6 6 7 7%N*S3(+S3)CS3 +ES3 *D	S3
 +ES3 '+S3 5ES3 #-S3 7;S3 ,AS3 ,0S3 5=S3j""  " 8	"
 9" 8" 9" " &" !" "  5"  $" ),"2
 
s	ss s 
	s
 s s 4s "sl  !	!! )! -	!
 ! ! !	9		9	9'6	9@N	9*	9?	??'6?@N?#?0(F:  	k2 $$15261526#.2@	@@ @ /	@
 0@ /@ 0@ @ @ @ @ ,@ @ 3@.37"
4,l+ + T6,>L, 7,> /2e !8 3B7B7B7'3B78QB7JA		A	"&A	/3A		A	"A	H 	566	6:6 6 	6
 I6 76B T6. . 7.< 'W&&(
6
( $( ( ( "'("/((+/( (>" -":="  	uA  " 4. %.;$%I;$z
 F5&55&p#!# 2	#  0g//1  $  " T6L 7L%=;=;~ 
9 
9#LJ   ## !	#
 "# # # # 6# /# 1# 0# 5I# #4!D "3   3( 2  E 
@ !0  u   ! !"5 6+*-+6F+47+\(*(Z   un >C?#?'? &? 
.	?%*%)%N ,9 ! !% (":":!7":":JQ> %  % Y9v &5  E "~H.~H@ '9  U #,-,-&4,-#,-7E,- ,- #&,- 6:,- KO,- 	,-^ B33W46  " "5 )
*/X > > 3  E @@+;@(@ @ D > *U P.P0P5@P< )  % 
C$O$b  LF ''<=    8 9 #QS&  ' '(J K&N   ,8:"F <X ! !"7 85A  1 2+( DNN9%	"&	 ,
 
  2 3 
  = ! i0 1 ":  I K   y"7 8 0@ ! !) ,)5  I &
 FJ+.+69+Z!!.%T"%,$  %dnn%89   % %&6 7 !OQL   4 5I   *68 :T ! !"5 63?  / 0;r   