
    Vpf                    l    d dl mZ d dlmZ d dlZd dlmZ  ej        e          Z	 G d d          Z
dS )    )annotations)SequenceN)running_in_cloud_tpu_vmc                       e Zd ZU dZg Zded<   dZded<    fdZedd            Z	edd            Z
edd            Zedd            Zedd            Zed d            Z xZS )!
ClusterEnva  Interface for defining a cluster environment.

  To enable auto bootrapping (aka :func:`jax.distributed.initialize()`),
  cluster environments need to derive from :class:`ClusterEnv` and implement
  :func:`is_env_present`, :func:`get_coordinator_address`,
  :func:`get_process_count`, and :func:`get_process_id`.
  :class:`ClusterEnv` subclasses are automatically detected when imported.
  zlist[type[ClusterEnv]]_cluster_typesFboolopt_in_only_methodc                n     t                      j        di | | j                            |            d S )N )super__init_subclass__r   append)clskwargs	__class__s     Y/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/clusters/cluster.pyr   zClusterEnv.__init_subclass__$   s=    EGG'''''c"""""    coordinator_address
str | Nonenum_processes
int | None
process_idlocal_device_idsSequence[int] | Nonecluster_detection_methodinitialization_timeoutreturn?tuple[str | None, int | None, int | None, Sequence[int] | None]c                .   t          d ||||fD                       r||||fS ut          fd| j        D             d           }|t                              d d           nR|                                st                              d d           nt          d | j        D             d           }|rt                              d|j                   ||                    |          }||	                                }||
                                }|0t          s)|                                |                                g}n=t                              d	d
                    d | j        D                                  ||||fS )Nc              3     K   | ]}|d uV  	d S Nr   ).0ps     r   	<genexpr>zBClusterEnv.auto_detect_unset_distributed_params.<locals>.<genexpr>5   s6       % %Q1D= % % % % % %r   c              3  2   K   | ]}|j         k    |V  d S r"   )name)r#   envr   s     r   r%   zBClusterEnv.auto_detect_unset_distributed_params.<locals>.<genexpr>=   s0      ]]3D\8\8\38\8\8\8\]]r   z6Automatic Distributed initialization can not proceed: z is not supported.z5 is supported but not functional in this environment.c              3  X   K   | ]%}|j         d k    |                                !|V  &dS )FN)r
   is_env_present)r#   r(   s     r   r%   zBClusterEnv.auto_detect_unset_distributed_params.<locals>.<genexpr>E   sB      pp#s7MQV7V7V[^[m[m[o[o7V#7V7V7V7Vppr   z/Initializing distributed JAX environment via %s)timeout_secsz[Could not find a known environment for initializing distributed JAX. Known environments: %sz, c              3  $   K   | ]}|j         V  d S r"   )__name__)r#   es     r   r%   zBClusterEnv.auto_detect_unset_distributed_params.<locals>.<genexpr>]   s$      +S+S1AJ+S+S+S+S+S+Sr   )allnextr   loggererrorr*   debugr-   get_coordinator_addressget_process_countget_process_idr   get_local_process_idjoin)r   r   r   r   r   r   r   r(   s        `  r   $auto_detect_unset_distributed_paramsz/ClusterEnv.auto_detect_unset_distributed_params)   s$     % %#6"#$ % % % % %  !=*   
  +]]]]#"4]]]_ceec	 F1F F F 	G 	G 	G 	G!!## j i1i i i 	j 	j 	j pp!3ppprvwwc  UllDclSSS		$!99G]9^^		--//		''))
 
"+B
"

"
"
$
$
044667ll !"&))+S+S@R+S+S+S"S"SU U U
<LMMr   c                     t          d          )zDReturns True if process is running in this cluster environment.
    z3ClusterEnv subclasses must implement is_env_presentNotImplementedErrorr   s    r   r*   zClusterEnv.is_env_presenta   s     S
T
TTr   r+   strc                     t          d          )ax  Returns address and port used by JAX to bootstrap.

    Process id 0 will open a tcp socket at "hostname:port" where
    all the processes will connect to initialize the distributed JAX service.
    The selected port needs to be free.
    :func:`get_coordinator_address` needs to return the same hostname and port on all the processes.

    Returns:
      "hostname:port"
    z<ClusterEnv subclasses must implement get_coordinator_addressr;   )r   r+   s     r   r4   z"ClusterEnv.get_coordinator_addressg   s     \
]
]]r   intc                     t          d          )Nz6ClusterEnv subclasses must implement get_process_countr;   r=   s    r   r5   zClusterEnv.get_process_countu   s    
V
W
WWr   c                     t          d          )Nz3ClusterEnv subclasses must implement get_process_idr;   r=   s    r   r6   zClusterEnv.get_process_idy   s    
S
T
TTr   c                    dS )a   Get index of current process inside a host.

    The method is only useful to support single device per process.
    In that case, each process will see a local device whose ID is
    the same as its local process ID.
    If None, JAX will not restrict the visible devices.
    Nr   r=   s    r   r7   zClusterEnv.get_local_process_id}   s	     4r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r	   )r+   r   r   r>   )r   r@   )r   r   )r-   
__module____qualname____doc__r   __annotations__r
   r   classmethodr9   r*   r4   r5   r6   r7   __classcell__)r   s   @r   r   r      s>          ,..----"""""# # # # #
 3N 3N 3N ;3Nl U U U ;U
 ^ ^ ^ ;^ X X X ;X U U U ;U    ;    r   r   )
__future__r   collections.abcr   loggingjax._src.cloud_tpu_initr   	getLoggerr-   r1   r   r   r   r   <module>rO      s    # " " " " " $ $ $ $ $ $  ; ; ; ; ; ;		8	$	$o o o o o o o o o or   