U
    Jc                     @   s   d dl Z d dlZd dlmZmZmZ d dlmZmZm	Z	 d dl
mZmZ d dlmZ eeZdZG dd deZeed	d
dZdS )    N)TuplecastOptional)StoreTCPStorePrefixStore)RendezvousHandlerRendezvousParameters)parse_rendezvous_endpointiX  c                   @   s   e Zd ZdZeeeeeedddZedddZee	eef ddd	Z
d
d Zdd Zdd ZedddZedddZdS )StaticTCPRendezvousz
    Static rendezvous that is a wrapper around the TCPStore.
    Creates TCPStore based on the input parameters with the
    listener on the agent with group_rank=0
    )master_addrmaster_portrank
world_sizerun_idtimeoutc                 C   s6   || _ || _|| _|| _|| _tj|d| _d | _d S )N)seconds)	r   r   r   r   r   datetime	timedeltar   _store)selfr   r   r   r   r   r    r   ^/tmp/pip-unpacked-wheel-gikjz4vx/torch/distributed/elastic/rendezvous/static_tcp_rendezvous.py__init__   s    	zStaticTCPRendezvous.__init__)returnc                 C   s   dS )NZstaticr   r   r   r   r   get_backend0   s    zStaticTCPRendezvous.get_backendc                 C   sT   t d | js8| jdk}t| j| j| j|| jdd| _t	| j
| j}|| j| jfS )Nz3Creating TCPStore as the c10d::Store implementationr   T)Zmulti_tenant)loginfor   r   r   r   r   r   r   r   r   )r   Z	is_masterstorer   r   r   next_rendezvous3   s    

z#StaticTCPRendezvous.next_rendezvousc                 C   s   dS )NFr   r   r   r   r   	is_closedB   s    zStaticTCPRendezvous.is_closedc                 C   s   d S Nr   r   r   r   r   
set_closedE   s    zStaticTCPRendezvous.set_closedc                 C   s   dS )Nr   r   r   r   r   r   num_nodes_waitingH   s    z%StaticTCPRendezvous.num_nodes_waitingc                 C   s   | j S r"   )r   r   r   r   r   
get_run_idK   s    zStaticTCPRendezvous.get_run_idc                 C   s   dS )NTr   r   r   r   r   shutdownN   s    zStaticTCPRendezvous.shutdownN)__name__
__module____qualname____doc__strintr   r   r   r   r    r!   r#   r$   r%   boolr&   r   r   r   r   r      s   r   )paramsr   c                 C   s   d| j krtd| j }|s(tdt|d\}}|dkrNtd| d| j}tt| j d}| j	}d| j krt| j d }nt
}t||||||S )Nr   zMrank is absent in RendezvousParameters.Try add --node_rank to the cmd requestzdendpoint is absent in RendezvousParametersTry add --master_port and --master_addr to the cmd requestzPort is absent in endpoint: z". Try launching with --master_portr   )config
ValueErrorendpointstripr
   Z	max_nodesr   r,   getr   _default_timeout_secondsr   )r.   r2   r   r   r   r   r   r   r   r   r   create_rdzv_handlerR   s8    



     r6   )r   loggingtypingr   r   r   Ztorch.distributedr   r   r   Z$torch.distributed.elastic.rendezvousr   r	   Z*torch.distributed.elastic.rendezvous.utilsr
   	getLoggerr'   r   r5   r   r6   r   r   r   r   <module>
   s   
: