
    vhK                    F   d Z ddlmZ ddlZddlmZmZ ddlZddlZddl	Z	ddl
Z
ddlZddlmZmZ ddlZddlmZ ddlmZ ddlmZmZmZ dd	lmZ eecZZeZeZ d
 Z! G d de      Z" edd      d%d       Z# G d dejH                        Z%d Z&d&dZ'd&dZ( G d d      Z)i Z* G d de)ejV                        Z, e" e, ejZ                  de.      d            Z/ G d dej`                        Z1 e1       Z2 G d de)      Z3d  Z4 e3dd      Z5 G d! d"      Z6e6Z7d# Z8d'd$Z9y)(z$Definitions of Mesh and ResourceEnv.    )annotationsN)HashableSequence)Any
NamedTuple)config)
xla_bridge)safe_zipcachetuple_delete)
xla_clientc                D    dj                  t        d | D                    S )N, c              3  (   K   | ]
  }d | d   yw)`N .0as     H/opt/face_recognition/venv/lib/python3.12/site-packages/jax/_src/mesh.py	<genexpr>zshow_axes.<locals>.<genexpr>)   s     1qAaS(1s   )joinsorted)axess    r   	show_axesr   (   s    	61D11	22    c                  j    e Zd ZU ded<   d
dZedd       Zedd       Zed        Zed        Z	d Z
y	)ResourceEnvMeshphysical_meshc                    t        |j                        | j                  t        | j                  j                        z
  z  }|rt	        dt        |             | j                  |      S )NzfCannot update the mesh of the current resource environment. The new mesh shadows already defined axes )r    )set
axis_namesresource_axesr    
ValueErrorr   _replace)selfmeshoverlaps      r   	with_meshzResourceEnv.with_mesh/   sj    $//"d&8&83t?Q?Q?\?\;]&]^G Q#G,-/ 0 0 ==t=,,r   c                @    t        | j                  j                        S N)r"   r    r#   r'   s    r   physical_resource_axesz"ResourceEnv.physical_resource_axes7   s    t!!,,--r   c                    | j                   S r,   )r.   r-   s    r   r$   zResourceEnv.resource_axes;   s    &&&r   c                .    | j                   j                  S r,   )r    shaper-   s    r   r1   zResourceEnv.shape?   s    ###r   c                B    | j                   j                  j                  S r,   )r    
local_meshr1   r-   s    r   local_shapezResourceEnv.local_shapeC   s    ((...r   c                    dj                  d | j                  j                  j                         D              }d| dS )Nr   c              3  2   K   | ]  \  }}d | d|   yw'z': Nr   r   kvs      r   r   z'ResourceEnv.__repr__.<locals>.<genexpr>H   s'      D!Q!A3c!D   zResourceEnv(mesh=Mesh(z)))r   r    r1   items)r'   	mesh_reprs     r   __repr__zResourceEnv.__repr__G   sD    		 D"&"4"4":":"@"@"BD DI#I;b11r   N)r(   r   )returnzset[ResourceAxisName])__name__
__module____qualname____annotations__r*   propertyr.   r$   r1   r4   r?   r   r   r   r   r   ,   sb    - . . ' ' $ $ / /2r   r      F)max_sizetrace_context_in_keyr   c                   | j                   r| S  t        j                  fdt        g      | j                        }g }t        | j                  j                        D ]  }t        t        t        | j                  j                              |      }|j                  |d      }t        j                  |      }t        t        j                  |            t        t        j                  |            }	}|j                  t        ||	dz                 t        |      }
||
   j!                         st#        d      t%        | j                  |
   | j&                        S )Nc                "    | j                   k(  S r,   )process_index)drK   s    r   <lambda>z!_get_local_mesh.<locals>.<lambda>R   s    =0 r   otypesF)keepdims   zWhen passing host local inputs to pjit, devices connected to a single host must form a contiguous subcube of the global device mesh)emptynp	vectorizebooldevicesrangendimr   tupleanyflatnonzerointminmaxappendsliceallr%   r   r#   )global_meshrK   is_local_devicesubcube_indicesaxis
other_axeslocal_slicesnonzero_indicesstartendsubcube_indices_tuples    `         r   _get_local_meshrl   M   s;   ABLL0$AALATATV//K'',,- 2deE+*=*=*B*B$CDdKJ #&&zE&BLnn\2ORVVO,-s266/3J/K3E5a012  0
 
.	/	3	3	5
	I  
k!!"78+:P:P	QQr   c                  x    e Zd Z ej                         Z ej                         Z ej                         Zd Zy)AxisTypec                    | j                   S r,   namer-   s    r   r?   zAxisType.__repr__o   s    99r   N)	rA   rB   rC   enumautoAutoExplicitManualr?   r   r   r   rn   rn   j   s.    	$TYY[(499;&r   rn   c                *   |t         j                  ft        |       z  n|}t        |t              s|f}t        d |D              s$t        d| d| dt	        d |D                     t        |       t        |      k7  rt        d|  d|       |S )Nc              3  <   K   | ]  }t        |t                y wr,   )
isinstancern   r   s     r   r   z(_normalize_axis_types.<locals>.<genexpr>x   s     9Z8$9s   zaxis_types passed to z. must be of type `jax.sharding.AxisType`. Got z	 of type c              3  2   K   | ]  }t        |        y wr,   )typer   s     r   r   z(_normalize_axis_types.<locals>.<genexpr>{   s     *Gq47*Gr<   zKNumber of axis names should match the number of axis_types. Got axis_names=z and axis_types=)rn   rt   lenry   rY   ra   	TypeErrorr%   )r#   
axis_typesrq   s      r   _normalize_axis_typesr   r   s    %  3z?2+5 	J	&J	9j9	9

v &|9U*GJ*G%G$H	JK K 	_J'
	!l"2:,	@A A 
r   c                2    | syt        fd| D              S )NFc              3  (   K   | ]	  }|k(    y wr,   r   r   ttys     r   r   z'all_axis_types_match.<locals>.<genexpr>        )Q"W)   )ra   r~   r   s    `r   all_axis_types_matchr          		)j)	))r   c                2    | syt        fd| D              S )NFc              3  (   K   | ]	  }|k(    y wr,   r   r   s     r   r   z'any_axis_types_match.<locals>.<genexpr>   r   r   )rZ   r   s    `r   any_axis_types_matchr      r   r   c                  "   e Zd ZU ded<   ded<   ded<   edd       Zej                  dd       Zej                  dd	       Z	ej                  dd
       Z
ej                  dd       Zej                  dd       Zej                  dd       Zej                  dd       Zej                  dd       Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zy)	_BaseMeshtuple[MeshAxisName, ...]r#   ztuple[tuple[str, int], ...]shape_tupletuple[AxisType, ...]_axis_typesc                    | j                   S r,   )r   r-   s    r   r~   z_BaseMesh.axis_types   s    r   c                J    t        | j                  t        j                        S r,   )r   r   rn   rv   r-   s    r   _are_all_axes_manualz_BaseMesh._are_all_axes_manual        0 0(//BBr   c                J    t        | j                  t        j                        S r,   )r   r   rn   rt   r-   s    r   _are_all_axes_autoz_BaseMesh._are_all_axes_auto        0 0(--@@r   c                J    t        | j                  t        j                        S r,   )r   r   rn   ru   r-   s    r   _are_all_axes_explicitz _BaseMesh._are_all_axes_explicit        0 0(2C2CDDr   c                T    | j                   syt        d | j                   D              S )NFc              3  l   K   | ],  }|t         j                  k(  xs |t         j                  k(   . y wr,   rn   rt   rv   r   r   s     r   r   z9_BaseMesh._are_all_axes_auto_or_manual.<locals>.<genexpr>   2      * HMM!9Q(//%99 *   24)r   ra   r-   s    r   _are_all_axes_auto_or_manualz&_BaseMesh._are_all_axes_auto_or_manual   .     *((* * *r   c                J    t        | j                  t        j                        S r,   )r   r   rn   rv   r-   s    r   _any_axis_manualz_BaseMesh._any_axis_manual   r   r   c                J    t        | j                  t        j                        S r,   )r   r   rn   rt   r-   s    r   _any_axis_autoz_BaseMesh._any_axis_auto   r   r   c                J    t        | j                  t        j                        S r,   )r   r   rn   ru   r-   s    r   _any_axis_explicitz_BaseMesh._any_axis_explicit   r   r   c                T    | j                   syt        d | j                   D              S )NFc              3  l   K   | ],  }|t         j                  k(  xs |t         j                  k(   . y wr,   r   r   s     r   r   z5_BaseMesh._any_axis_auto_or_manual.<locals>.<genexpr>   r   r   )r   rZ   r-   s    r   _any_axis_auto_or_manualz"_BaseMesh._any_axis_auto_or_manual   r   r   c                b    t        d t        | j                  | j                        D              S )Nc              3  L   K   | ]  \  }}|t         j                  k(  r|  y wr,   )rn   rt   r   nr   s      r   r   z&_BaseMesh.auto_axes.<locals>.<genexpr>   s'      (tq!&  (   "$rY   r
   r#   r   r-   s    r   	auto_axesz_BaseMesh.auto_axes   s,     (x9I9IJ ( ( (r   c                b    t        d t        | j                  | j                        D              S )Nc              3  L   K   | ]  \  }}|t         j                  k(  r|  y wr,   )rn   ru   r   s      r   r   z*_BaseMesh.explicit_axes.<locals>.<genexpr>   s)      ,tq!***  ,r   r   r-   s    r   explicit_axesz_BaseMesh.explicit_axes   s,     ,x9I9IJ , , ,r   c                b    t        d t        | j                  | j                        D              S )Nc              3  L   K   | ]  \  }}|t         j                  k(  r|  y wr,   )rn   rv   r   s      r   r   z(_BaseMesh.manual_axes.<locals>.<genexpr>   s'      *tq!(  *r   r   r-   s    r   manual_axesz_BaseMesh.manual_axes   s,     *x9I9IJ * * *r   c                .   | j                   si S t        j                  t              }t	        | j                   | j
                        D ]  \  }}||   j                  |        |j                         D ci c]  \  }}|t        |       c}}S c c}}w r,   )	r#   collectionsdefaultdictlistr
   r   r_   r=   rY   )r'   rL   r   r   s       r   _axis_types_dictz_BaseMesh._axis_types_dict   sw    ??i%A$*:*:; 1dkk!n$%GGI.DAqAuQxK...s   7Bc                T    t        t        | j                  | j                              S r,   )dictr
   r#   r   r-   s    r   _name_to_typez_BaseMesh._name_to_type   s    $*:*:;<<r   N)r@   r   )r@   rU   )rA   rB   rC   rD   rE   r~   	functoolscached_propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s   &&**##  C C A A E E * * C C A A E E * * ( ( , , * * / / = =r   r   c                  N    e Zd ZU dZded<   ded<   dd	 	 	 d! fdZd	 Zd
 Zd Z fdZ	d Z
d Zej                  d        Zej                  d        Zed"d       Zed        Zed        Zej                  d        Zed        Zd Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zd Zej                  d        Zd Zej                  d        Zej                  d         Z  xZ!S )#r   a  Declare the hardware resources available in the scope of this manager.

  See the Distributed arrays and automatic parallelization tutorial
  (https://docs.jax.dev/en/latest/notebooks/Distributed_arrays_and_automatic_parallelization.html)
  and Explicit sharding tutorial (https://docs.jax.dev/en/latest/notebooks/explicit-sharding.html)

  Args:
    devices: A NumPy ndarray object containing JAX device objects (as
      obtained e.g. from :py:func:`jax.devices`).
    axis_names: A sequence of resource axis names to be assigned to the
      dimensions of the ``devices`` argument. Its length should match the
      rank of ``devices``.
    axis_types: and optional tuple of :class:`jax.sharding.AxisType` entries corresponding to
      the ``axis_names``. See `Explicit Sharding`_ for more information.

  Examples:

    >>> from jax.sharding import Mesh
    >>> from jax.sharding import PartitionSpec as P, NamedSharding
    >>> import numpy as np
    ...
    >>> # Declare a 2D mesh with axes `x` and `y`.
    >>> devices = np.array(jax.devices()).reshape(4, 2)
    >>> mesh = Mesh(devices, ('x', 'y'))
    >>> inp = np.arange(16).reshape(8, 2)
    >>> arr = jax.device_put(inp, NamedSharding(mesh, P('x', 'y')))
    >>> out = jax.jit(lambda x: x * 2)(arr)
    >>> assert out.sharding == NamedSharding(mesh, P('x', 'y'))

  .. _Explicit Sharding:  https://docs.jax.dev/en/latest/notebooks/explicit-sharding.html
  z
np.ndarrayrV   r   r#   Nr~   c               0   t        |t        j                        st        j                  |      }t        |t              r|f}t        |      }t        d |D              rt        d|       |j                  t        |      k7  r%t        d|j                   dt        |       d      t        ||d      }||j                  t        |j                        |f}t        j                  |d       }||S t        | A  |       }|j#                         |_        d|j$                  j&                  _        ||_        ||_        |j$                  j                  r-t/        j0                  |j                  j3                               nd|_        |t        |<   |S )	Nc              3  $   K   | ]  }|d u  
 y wr,   r   )r   is     r   r   zMesh.__new__.<locals>.<genexpr>  s     
)19
)s   z%Mesh axis names cannot be None. Got: zMesh requires the ndim of its first argument (`devices`) to equal the length of its second argument (`axis_names`), but got devices.ndim == z and len(axis_names) == .r   Fr   )ry   rS   ndarrayarraystrrY   rZ   r%   rX   r|   r   r1   flat_mesh_object_dictgetsuper__new__copyrV   flags	writeabler#   r   mathprodvalues_size)clsrV   r#   r~   keyvalr'   	__class__s          r   r   zMesh.__new__   s\    grzz*!g*c"=jz"J

)j
))>zlKLL||s:&$\\N +  #J034 4 'z:vFJw}}eGLL&9:
FC


T
*C
j7?3D<<>DL#(DLL  DO!D37<<3D3D4::,,./!DJ!cKr   c                b    t        |       | j                  | j                  fd| j                  ifS )Nr~   )r{   rV   r#   r   r-   s    r   
__reduce__zMesh.__reduce__"  s0    Jt74++,. .r   c                *   | |u ryt        |t              sy| j                  |j                  k(  xrc | j                  j                  |j                  j                  k(  xr4 | j
                  |j
                  k(  xr | j                  |j                  k(  S NTF)ry   r   r#   rV   r1   r   _internal_device_listr'   others     r   __eq__zMesh.__eq__&  s     u}eT"OOu/// FLL%--"5"55F 1 11F &&%*E*EEGr   c                    t        | d      sFt        | j                  | j                  | j                  j
                  | j                  f      | _        | j                  S )N_hash)hasattrhashr#   r   rV   r1   r   r   r-   s    r   __hash__zMesh.__hash__2  sM    4!??D668J8Jdj ::r   c                |    t        | |      rt        | |      |k(  ry t        d| d      t        |   ||       y )NzCannot reassign attributes (z) of immutable mesh objects)r   getattrRuntimeErrorr   __setattr__)r'   rq   valuer   s      r   r   zMesh.__setattr__9  sL    tT	t		% 	(.I
J  
Ge$r   c                b   t         j                  j                  rt        d      t        j
                  d   j                  |       }t        j
                  j                  |       |t        _        t         j                  j                  t        d t        j
                  D                     | S )Nz!Mesh context manager is disabled.c              3  `   K   | ]&  }|j                   j                  s|j                    ( y wr,   r    rR   r   s     r   r   z!Mesh.__enter__.<locals>.<genexpr>K  (      ,!__** oo ,   ,.)
jax_configdisallow_mesh_context_managerr   r   thread_resourcesstackr*   r_   envmesh_context_manager	set_localrY   )r'   new_envs     r   	__enter__zMesh.__enter__D  s    //55<==$$R(2248G!!'*"##-- ,'7'='= , 	,- Kr   c                    t         j                  j                          t         j                  d   t         _        t        j
                  j                  t        d t         j                  D                     y)Nr   c              3  `   K   | ]&  }|j                   j                  s|j                    ( y wr,   r   r   s     r   r   z Mesh.__exit__.<locals>.<genexpr>S  r   r   F)r   r   popr   r   r   r   rY   r'   exc_type	exc_value	tracebacks       r   __exit__zMesh.__exit__O  s\     +11"5##-- ,'7'='= , 	,- r   c                    t        j                  d t        | j                  | j                  j
                        D              S )Nc              3  *   K   | ]  \  }}||f  y wr,   r   r   rq   sizes      r   r   zMesh.shape.<locals>.<genexpr>Y  s"      #ID$ 
t#I   )r   OrderedDictr
   r#   rV   r1   r-   s    r   r1   z
Mesh.shapeW  s;    "" #I"4??DLL4F4FG#I I Ir   c                v    t        d t        | j                  | j                  j                        D              S )Nc              3  *   K   | ]  \  }}||f  y wr,   r   r	  s      r   r   z#Mesh.shape_tuple.<locals>.<genexpr>_  s"      ID$ 
tIr  )rY   r
   r#   rV   r1   r-   s    r   r   zMesh.shape_tuple]  s5     I"4??DLL4F4FGI I Ir   c                .    | j                   j                  S r,   )rV   r1   r-   s    r   
axis_sizeszMesh.axis_sizesc  s    <<r   c                    | j                   S r,   r   r-   s    r   r
  z	Mesh.sizeg      ::r   c                     | j                   dk(  S Nr   r
  r-   s    r   rR   z
Mesh.emptyk      99>r   c                Z    | j                   j                  t        | j                        k7  S r,   )rV   r
  r|   local_devicesr-   s    r   is_multi_processzMesh.is_multi_processq  s"    <<D$6$6 777r   c                H    | j                  t        j                               S r,   )_local_meshxbrK   r-   s    r   r3   zMesh.local_meshu  s    B,,.//r   c                    t        | |      S r,   )rl   )r'   rK   s     r   r  zMesh._local_meshy  s    4//r   c                x    | j                   rJ  t        j                  d t        g      | j                        S )Nc                    | j                   S r,   )id)rL   s    r   rM   z!Mesh.device_ids.<locals>.<lambda>  s
    !$$ r   rN   )rR   rS   rT   r\   rV   r-   s    r   
device_idszMesh.device_ids|  s,    zz>52<<u5dllCCr   c                ,    t        | j                        S r,   )r"   r  r-   s    r   _local_devices_setzMesh._local_devices_set  s    t!!""r   c                @    t        | j                  j                        S r,   )rY   rV   r   r-   s    r   _flat_devices_tuplezMesh._flat_devices_tuple  s    ""##r   c                @    t        j                  | j                        S r,   )xc
DeviceListr&  r-   s    r   r   zMesh._internal_device_list  s    ==1122r   c                @    t        | j                  j                        S r,   )r"   rV   r   r-   s    r   _flat_devices_setzMesh._flat_devices_set  s    t||  !!r   c                    dj                  d | j                  j                         D              }d| j                   }d| | dS )Nr   c              3  2   K   | ]  \  }}d | d|   ywr7   r   r9   s      r   r   zMesh.__str__.<locals>.<genexpr>  s      F41a1QCs1#Fr<   , axis_types=zMesh())r   r1   r=   r   )r'   mesh_stratrs      r   __str__zMesh.__str__  sI    yyF4::3C3C3EFFH$**+
,C8*SE##r   c                x    | j                   ryd| j                   }d| j                  d| j                  | dS )Nz"Mesh(device_ids=[], axis_names=())r.  zMesh(device_ids=z, axis_names=r/  )rR   r   r"  r#   )r'   r1  s     r   _reprz
Mesh._repr  sE    zz1$**+
,Cdoo0doo=PQTPUUVWWr   c                    | j                   S r,   )r4  r-   s    r   r?   zMesh.__repr__      ::r   c                    | j                   j                  D cg c]+  }|j                  |j                  j                         k(  r|- c}S c c}w r,   )rV   r   rK   client)r'   rL   s     r   r  zMesh.local_devices  sD    ||(( <!!(("8"8"::  < < <s   0Ac                Z    t        | j                  | j                  | j                        S )Nr   )AbstractMeshr  r#   r   r-   s    r   abstract_meshzMesh.abstract_mesh  s$    #'#3#35 5r   )rV   z np.ndarray | Sequence[xc.Device]r#   zstr | Sequence[MeshAxisName]r~   ztuple[AxisType, ...] | None)r@   tuple[int, ...])"rA   rB   rC   __doc__rD   r   r   r   r   r   r   r  r   r   r1   r   rE   r  r
  rR   r  r3   r  r"  r$  r&  r   r+  r2  r4  r?   r  r;  __classcell__)r   s   @r   r   r      s   @ && 9= 6 5 D.
G	%	 I I
 I I
      
 8 8 0 00 D D # # $ $ 3 3 " "$
 X X < < 5 5r   r   )dtypec                      e Zd Zd Zy)_ThreadResourcesLocalStatec                D    t         g| _        | j                  d   | _        y )Nr   )	EMPTY_ENVr   r   r-   s    r   __init__z#_ThreadResourcesLocalState.__init__  s    DJzz"~DHr   N)rA   rB   rC   rD  r   r   r   rA  rA    s    r   rA  c                  0   e Zd ZdZdd	 ddZd Zd Zd Zed        Z	e
j                  d	        Ze
j                  d
        Zed        Zed        Zed        ZddZed        Zed        Zed        Zed        Zed        Zd Zd Zedd       Zy)r:  a  AbstractMesh contains only axis names and axis sizes.

  It does not contain concrete devices compared to `jax.sharding.Mesh`. You
  should use this as an input to the sharding passed to with_sharding_constraint
  and mesh passed to shard_map to avoid tracing and lowering cache misses when
  your mesh shape and axis names stay the same but the devices change.
  See the description of https://github.com/jax-ml/jax/pull/23022 for more
  details.

  Args:
    axis_sizes: A tuple of integers specifying the size of each resource axis.
    axis_names: A tuple of resource axis names to be assigned to the
      dimensions of the ``devices`` argument. Its length should match the
      rank of ``devices``.
    axis_types: and optional tuple of :class:`jax.sharding.AxisType` entries corresponding to
      the ``axis_names``. See `Explicit Sharding`_ for more information.

  .. _Explicit Sharding:  https://docs.jax.dev/en/latest/notebooks/explicit-sharding.html
  Nr   c                  || _         || _        | j                   rt        j                  | j                         nd| _        t        | j                  |d      | _        t        | j                   | j                  | j                  f      | _        y )Nr   r:  )	r  r#   r   r   r   r   r   r   r   )r'   r  r#   r~   s       r   rD  zAbstractMesh.__init__  se     DO DO/34??+ADJ,^5Dt9I9IJKDJr   c                    | j                   S r,   )r   r-   s    r   r   zAbstractMesh.__hash__  r6  r   c                    | |u ryt        |t              sy| j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r   )ry   r:  r  r#   r   r   s     r   r   zAbstractMesh.__eq__  s`    u}e\*OOu/// 2OOu///2 1 113r   c                    | j                   r"dj                  d | j                   D              nd}d| j                   }d| | dS )Nr   c              3  2   K   | ]  \  }}d | d|   ywr7   r   )r   r   r;   s      r   r   z(AbstractMesh.__repr__.<locals>.<genexpr>  s      FTQQqcQC=Fr<   z()r.  zAbstractMesh(r/  )r   r   r   )r'   r>   r1  s      r   r?   zAbstractMesh.__repr__  sS    $$ FT5E5EFF*. $**+
,C9+cU!,,r   c                    | j                   S r,   r  r-   s    r   r
  zAbstractMesh.size  r  r   c                @    t        j                  | j                        S r,   )r   r  r   r-   s    r   r1   zAbstractMesh.shape  s    ""4#3#344r   c                b    t        d t        | j                  | j                        D              S )Nc              3  *   K   | ]  \  }}||f  y wr,   r   r	  s      r   r   z+AbstractMesh.shape_tuple.<locals>.<genexpr>  s"      FD$ 
tFr  )rY   r
   r#   r  r-   s    r   r   zAbstractMesh.shape_tuple  s/     F"4??DOODF F Fr   c                     y r,   r   r-   s    r   r   z"AbstractMesh._internal_device_list  s    r   c                     | j                   dk(  S r  r  r-   s    r   rR   zAbstractMesh.empty  r  r   c                    | S r,   r   r-   s    r   r;  zAbstractMesh.abstract_mesh  s    Kr   c                    t        fdt        | j                  | j                        D              }t	        | j
                  | j                  |      S )Nc              3  :   K   | ]  \  }}|v r|   n|  y wr,   r   )r   r   r   name_to_types      r   r   z1AbstractMesh.update_axis_types.<locals>.<genexpr>  s/      O#q! /0<.?<?QF Os   r   )rY   zipr#   r   r:  r  )r'   rT  new_axis_typess    ` r   update_axis_typeszAbstractMesh.update_axis_types   sJ     O'*4??D<L<L'MO ON#13 3r   c                    t        d       y )NrV   _raise_value_errorr-   s    r   rV   zAbstractMesh.devices  s
    y!r   c                    t        d       y )Nr"  rY  r-   s    r   r"  zAbstractMesh.device_ids
  
    |$r   c                    t        d       y )Nr  rY  r-   s    r   r  zAbstractMesh.is_multi_process  s    )*r   c                    t        d       y )Nr  rY  r-   s    r   r  zAbstractMesh.local_devices  s
    'r   c                    t        d       y )Nr3   rY  r-   s    r   r3   zAbstractMesh.local_mesh  r\  r   c                    t        d       y )Nr   rY  r-   s    r   r   zAbstractMesh.__enter__  s
    {#r   c                    t        d       y )Nr  rY  r  s       r   r  zAbstractMesh.__exit__  s
    z"r   c                D    t         j                  j                  |       }|S r,   )r   abstract_mesh_context_manager
swap_local)r(   prevs     r   '_extremely_unsafe_enter_tracing_contextz4AbstractMesh._extremely_unsafe_enter_tracing_context   s    33>>tDDKr   )r  r<  r#   ztuple[str, ...]r~   z&AxisType | tuple[AxisType, ...] | None)rT  zdict[MeshAxisName, AxisType]r(   r:  )rA   rB   rC   r=  rD  r   r   r?   rE   r
  r   r   r1   r   r   rR   r;  rW  rV   r"  r  r  r3   r   r  staticmethodrf  r   r   r   r:  r:    s9   * HLLDL3-   5 5 F F
      3 " " % % + + ( ( % %$#  r   r:  c                    t        d|        )Nz AbstractMesh does not implement )r%   rp   s    r   rZ  rZ  (  s    5dV<==r   c                  (    e Zd ZddgZddZd Zd Zy)UseAbstractMeshContextManagerr(   re  c                `    t        |t              st        dt        |             || _        y )Nz=Expected mesh of type `jax.sharding.AbstractMesh`. Got type: )ry   r:  r%   r{   r(   )r'   r(   s     r   rD  z&UseAbstractMeshContextManager.__init__0  s5    dL)4j\  DIr   c                `    t         j                  j                  | j                        | _        y r,   )r   rc  rd  r(   re  r-   s    r   r   z'UseAbstractMeshContextManager.__enter__7  s    88CCDIINDIr   c                V    t         j                  j                  | j                         y r,   )r   rc  r   re  r  s       r   r  z&UseAbstractMeshContextManager.__exit__:  s    ,,66tyyAr   Nrg  )rA   rB   rC   	__slots__rD  r   r  r   r   r   rk  rk  -  s    v)OBr   rk  c                 J    t         j                  j                  } | t        S | S r,   )r   rc  r   empty_abstract_mesh)r   s    r   get_abstract_meshrr  ?  s#    0066# #	44r   c                 6    t         j                  j                  S r,   )r   device_contextr   r   r   r   get_concrete_meshru  C  s    		"	"	(	((r   )rb   r   rK   r\   r@   r   )r   rn   r@   rU   )r@   zMesh | None):r=  
__future__r   r   collections.abcr   r   
contextlibrr   r   r   	threadingtypingr   r   numpyrS   jax._srcr   r   r	   r  jax._src.utilr
   r   r   jax._src.libr   r(  rU  
unsafe_zipMeshAxisNameResourceAxisNamer   r   rl   Enumrn   r   r   r   r   r   ContextDecoratorr   rR   objectrC  localrA  r   r:  rZ  rq  rk  use_abstract_meshrr  ru  r   r   r   <module>r     sC   + "  .      "  ) % 7 7 )CZ 32* 2B %0R 1R8tyy  *
*I= I=X  L59j11 L5^ XRXXb7<=	  ./ m9 md> #2r* B B  2 5)r   