a
    þdb	  ã                   @   s:   d dl Z d dlZd dlmZ e  e¡ZG dd„ deƒZdS )é    N)ÚClusterEnvironmentc                   @   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 )ÚKubeflowEnvironmentzÖEnvironment for distributed training using the `PyTorchJob`_ operator from `Kubeflow`_

    .. _PyTorchJob: https://www.kubeflow.org/docs/components/training/pytorch/
    .. _Kubeflow: https://www.kubeflow.org
    )Úreturnc                 C   s   dS )NT© ©Úselfr   r   úw/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lightning_fabric/plugins/environments/kubeflow.pyÚcreates_processes_externally   s    z0KubeflowEnvironment.creates_processes_externallyc                 C   s
   t jd S )NÚMASTER_ADDR)ÚosÚenvironr   r   r   r   Úmain_address"   s    z KubeflowEnvironment.main_addressc                 C   s   t tjd ƒS )NÚMASTER_PORT©Úintr   r   r   r   r   r   Ú	main_port&   s    zKubeflowEnvironment.main_portc                  C   s.   h d£} h d£}t j ¡ }|  |¡o,| |¡S )zOReturns ``True`` if the current process was launched using Kubeflow PyTorchJob.>   ÚRANKr   Ú
WORLD_SIZEZKUBERNETES_PORTr
   >   Z
GROUP_RANKZLOCAL_WORLD_SIZEZ
LOCAL_RANK)r   r   ÚkeysÚissubsetÚ
isdisjoint)Zrequired_env_varsZexcluded_env_varsZenv_varsr   r   r   Údetect*   s    
zKubeflowEnvironment.detectc                 C   s   t tjd ƒS )Nr   r   r   r   r   r   Ú
world_size3   s    zKubeflowEnvironment.world_sizeN)Úsizer   c                 C   s   t  d¡ d S )Nz^KubeflowEnvironment.set_world_size was called, but setting world size is not allowed. Ignored.©ÚlogÚdebug)r   r   r   r   r   Úset_world_size6   s    z"KubeflowEnvironment.set_world_sizec                 C   s   t tjd ƒS )Nr   r   r   r   r   r   Úglobal_rank9   s    zKubeflowEnvironment.global_rank)Úrankr   c                 C   s   t  d¡ d S )Nz`KubeflowEnvironment.set_global_rank was called, but setting global rank is not allowed. Ignored.r   )r   r   r   r   r   Úset_global_rank<   s    z#KubeflowEnvironment.set_global_rankc                 C   s   dS )Nr   r   r   r   r   r   Ú
local_rank?   s    zKubeflowEnvironment.local_rankc                 C   s   |   ¡ S )N)r   r   r   r   r   Ú	node_rankB   s    zKubeflowEnvironment.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   Z9lightning_fabric.plugins.environments.cluster_environmentr   Ú	getLoggerr#   r   r   r   r   r   r   Ú<module>   s   
