o
    * iH                     @   s<   d dl Z d dlmZmZ g Z	d
ddZdd Zdd	 ZdS )    N)get_clusterlogger  c              
      s  t d}|dusJ dt d}|dusJ dt d}|dus'J dtt d}|dus6J d	|d
}t|}t|}| dkrZ| d
|krZtd|  d| d t d}	|	du r|}
|dkrztt dd}|t|kr||krtd| d |}
W n ty } z
t	| W Y d}~nd}~ww |
du rd}
t
t|
|
t| }g }	|D ] |	 fdd|D  qn'|	d
}g }	|| t|ksJ t|D ]}|	||| |d |   qtd| d| d| d|	  t|||	||\}}||j| fS )za
    args_node_ips:string, device_mode:DeviceMode(Int), device_per_proc:list, args_port: int
    PADDLE_TRAINERSNz"PADDLE_TRAINERS should not be NonePOD_IPzPOD_IP should not be NonePADDLE_TRAINER_IDz$PADDLE_TRAINER_ID should not be NoneTRAINER_PORTS_NUMz$TRAINER_PORTS_NUM should not be None,z	127.0.0.1zPlease NOTE: When using paddlecloud, cluster_node_ips is automatically got from PADDLE_TRAINERS(multi nodes) or POD_IP(single node).Your input cluster_node_ips: z doesn't equals to IPs: z from paddlecloud environment.ZDISTRIBUTED_TRAINER_ENDPOINTS   ZPADDLE_PORT zUse Cloud specified port:.r   c                    s   g | ]	}  d | qS ): ).0portipr   p/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/paddle/distributed/fleet/cloud_utils.py
<listcomp>M   s    z%get_cloud_cluster.<locals>.<listcomp>zparsed from args: node_ips:z         node_ip:z node_rank:z trainer_endpoints:)osgetenvintsplitlenjoinr   warning	Exceptionprintlistrangeappenddebugr   Zpods)Zargs_node_ipsZdevice_modeZdevices_per_procZ	args_portnode_ipsnode_ip	node_rankpaddle_ports_numZ	num_nodesZtrainer_endpointsZstarted_portZpaddle_porteZportsZtrainer_endpoints_oriiZclusterZpodr   r   r   get_cloud_cluster   s~   




	

r(   c                  C   sP   t d} t d}t d}t d}| d u s$|d u s$|d u s$|d u r&dS dS )Nr   r   r   r   FT)r   r   )r"   r#   r$   r%   r   r   r   use_paddlecloudd   s   



r)   c                   C   s   t tddS )NZPADDLE_TRAINERS_NUM1)r   r   r   r   r   r   r   get_trainers_numt   s   r+   )r   )r   Z%paddle.distributed.fleet.launch_utilsr   r   __all__r(   r)   r+   r   r   r   r   <module>   s   
N