a
    þdÛ
  ã                   @   sN   d dl Z d dlZd dlZd dlmZ d dlmZ e  e	¡Z
G dd„ deƒZdS )é    N)ÚClusterEnvironment)Úrank_zero_warnc                   @   s°   e Zd ZdZeedœdd„ƒZeedœdd„ƒZee	dœdd„ƒZ
eedœd	d
„ƒZe	dœdd„Ze	ddœdd„Ze	dœdd„Ze	ddœdd„Ze	dœdd„Ze	dœdd„ZdS )ÚTorchElasticEnvironmentzgEnvironment for fault-tolerant and elastic training with `torchelastic <https://pytorch.org/elastic/>`_)Úreturnc                 C   s   dS )NT© ©Úselfr   r   ú{/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lightning_fabric/plugins/environments/torchelastic.pyÚcreates_processes_externally   s    z4TorchElasticEnvironment.creates_processes_externallyc                 C   s<   dt jvrtdƒ dt jd< t dt jd › ¡ t jd S )NZMASTER_ADDRzAMASTER_ADDR environment variable is not defined. Set as localhostz	127.0.0.1zMASTER_ADDR: )ÚosÚenvironr   ÚlogÚdebugr   r   r   r	   Úmain_address!   s
    

z$TorchElasticEnvironment.main_addressc                 C   s@   dt jvrtdƒ dt jd< t dt jd › ¡ tt jd ƒS )NZMASTER_PORTz=MASTER_PORT environment variable is not defined. Set as 12910Z12910zMASTER_PORT: )r   r   r   r   r   Úintr   r   r   r	   Ú	main_port)   s
    

z!TorchElasticEnvironment.main_portc                   C   s   t j ¡ ot j ¡ S )zTReturns ``True`` if the current process was launched using the torchelastic command.)ÚtorchZdistributedZis_availableZis_torchelastic_launchedr   r   r   r	   Údetect2   s    zTorchElasticEnvironment.detectc                 C   s   t tjd ƒS )NZ
WORLD_SIZE©r   r   r   r   r   r   r	   Ú
world_size8   s    z"TorchElasticEnvironment.world_sizeN)Úsizer   c                 C   s   t  d¡ d S )NzbTorchElasticEnvironment.set_world_size was called, but setting world size is not allowed. Ignored.©r   r   )r   r   r   r   r	   Úset_world_size;   s    z&TorchElasticEnvironment.set_world_sizec                 C   s   t tjd ƒS )NZRANKr   r   r   r   r	   Úglobal_rank>   s    z#TorchElasticEnvironment.global_rank)Úrankr   c                 C   s   t  d¡ d S )NzdTorchElasticEnvironment.set_global_rank was called, but setting global rank is not allowed. Ignored.r   )r   r   r   r   r	   Úset_global_rankA   s    ÿz'TorchElasticEnvironment.set_global_rankc                 C   s   t tjd ƒS )NZ
LOCAL_RANKr   r   r   r   r	   Ú
local_rankF   s    z"TorchElasticEnvironment.local_rankc                 C   s   t tj dd¡ƒS )NZ
GROUP_RANKr   )r   r   r   Úgetr   r   r   r	   Ú	node_rankI   s    z!TorchElasticEnvironment.node_rank)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚboolr
   Ústrr   r   r   Ústaticmethodr   r   r   r   r   r   r   r   r   r   r	   r      s   r   )Úloggingr   Ztorch.distributedr   Z9lightning_fabric.plugins.environments.cluster_environmentr   Z$lightning_fabric.utilities.rank_zeror   Ú	getLoggerr   r   r   r   r   r   r	   Ú<module>   s   
