Ë
      çi¤  ã                   ó†   — d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ  ej                  e«      Z G d„ de«      Zy)é    N)ÚAny)Úoverride)Ú_XLA_AVAILABLEÚ_XLA_GREATER_EQUAL_2_1ÚXLAAccelerator)ÚClusterEnvironmentc                   óì  ‡ — e Zd ZdZdededdfˆ fd„Zeedefd„«       «       Z	eede
fd„«       «       Zeedefd	„«       «       Zeedefd
„«       «       Ze ej"                  d¬«      defd„«       «       Zededdfd„«       Ze ej"                  d¬«      defd„«       «       Zededdfd„«       Ze ej"                  d¬«      defd„«       «       Ze ej"                  d¬«      defd„«       «       Zˆ xZS )ÚXLAEnvironmenta  Cluster environment for training on a TPU Pod with the `PyTorch/XLA <https://pytorch.org/xla>`_ library.

    A list of environment variables set by XLA can be found
    `here <https://github.com/pytorch/xla/blob/master/torch_xla/core/xla_env_vars.py>`_.

    ÚargsÚkwargsÚreturnNc                 ó`   •— t         st        t        t         «      «      ‚t        ‰| �  |i |¤Ž y ©N)r   ÚModuleNotFoundErrorÚstrÚsuperÚ__init__)Úselfr   r   Ú	__class__s      €ú~/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning_fabric/plugins/environments/xla.pyr   zXLAEnvironment.__init__"   s(   ø€ ÝÜ%¤c¬.Ó&9Ó:Ð:Ü‰Ñ˜$Ð) &Ó)ó    c                  ó   — y)NF© ©r   s    r   Úcreates_processes_externallyz+XLAEnvironment.creates_processes_externally'   s   € ð r   c                 ó   — t         ‚r   ©ÚNotImplementedErrorr   s    r   Úmain_addresszXLAEnvironment.main_address,   ó
   € ô "Ð!r   c                 ó   — t         ‚r   r   r   s    r   Ú	main_portzXLAEnvironment.main_port2   r    r   c                  ó*   — t        j                  «       S r   )r   Úis_availabler   r   r   ÚdetectzXLAEnvironment.detect8   s   € ô ×*Ñ*Ó,Ð,r   é   )Úmaxsizec                 ól   — t         rddlm} |j                  «       S ddlmc m} |j                  «       S )znThe number of processes across all devices and hosts.

        The output is cached for performance.

        r   ©ÚruntimeN)r   Ú	torch_xlar*   Ú
world_sizeÚtorch_xla.core.xla_modelÚcoreÚ	xla_modelÚxrt_world_size©r   ÚxrÚxms      r   r,   zXLAEnvironment.world_size=   s+   € õ "Ý/à—=‘=“?Ð"ç-Ð-à× Ñ Ó"Ð"r   Úsizec                 ó.   — t         j                  d«       y )NzYXLAEnvironment.set_world_size was called, but setting world size is not allowed. Ignored.©ÚlogÚdebug)r   r4   s     r   Úset_world_sizezXLAEnvironment.set_world_sizeN   s   € ä�	‰	ÐmÕnr   c                 ól   — t         rddlm} |j                  «       S ddlmc m} |j                  «       S )z‡The rank (index) of the currently running process across all host and devices.

        The output is cached for performance.

        r   r)   N)r   r+   r*   Úglobal_ordinalr-   r.   r/   Úget_ordinalr1   s      r   Úglobal_rankzXLAEnvironment.global_rankR   s,   € õ "Ý/à×$Ñ$Ó&Ð&ç-Ð-à�~‰~ÓÐr   Úrankc                 ó.   — t         j                  d«       y )Nz[XLAEnvironment.set_global_rank was called, but setting global rank is not allowed. Ignored.r6   )r   r>   s     r   Úset_global_rankzXLAEnvironment.set_global_rankc   s   € ä�	‰	ÐoÕpr   c                 ól   — t         rddlm} |j                  «       S ddlmc m} |j                  «       S )z†The rank (index) of the currently running process inside of the current host.

        The output is cached for performance.

        r   r)   N)r   r+   r*   Úlocal_ordinalr-   r.   r/   Úget_local_ordinalr1   s      r   Ú
local_rankzXLAEnvironment.local_rankg   s.   € õ "Ý/à×#Ñ#Ó%Ð%ç-Ð-à×#Ñ#Ó%Ð%r   c                 óˆ   — t         rddlm} |j                  «       S ddlmc m} ddlm}  ||j                  t        d«      S )zxThe rank (index) of the host on which the current process runs.

        The output is cached for performance.

        r   r)   N)Ú	getenv_as)r   r+   r*   Ú
host_indexÚtorch_xla.core.xla_env_varsr.   Úxla_env_varsÚtorch_xla.utils.utilsrF   ÚHOST_ORDINALÚint)r   r2   ÚxenvrF   s       r   Ú	node_rankzXLAEnvironment.node_rankx   s4   € õ "Ý/à—=‘=“?Ð"ß2Ð2Ý3á˜×*Ñ*¬C°Ó3Ð3r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   Úboolr   r   r   rL   r"   Ústaticmethodr%   Ú	functoolsÚ	lru_cacher,   r9   r=   r@   rD   rN   Ú__classcell__)r   s   @r   r
   r
      sº  ø„ ñð*˜cð *¨Sð *°Tõ *ð
 Øð¨dò ó ó ðð Øð"˜cò "ó ó ð"ð Øð"˜3ò "ó ó ð"ð Øð-�Dò -ó ó ð-ð Ø€Y×Ñ Ô#ð#˜Cò #ó $ó ð#ð ðo 3ð o¨4ò oó ðoð Ø€Y×Ñ Ô#ð ˜Sò  ó $ó ð ð ðq Cð q¨Dò qó ðqð Ø€Y×Ñ Ô#ð&˜Cò &ó $ó ð&ð Ø€Y×Ñ Ô#ð4˜3ò 4ó $ó ô4r   r
   )rV   ÚloggingÚtypingr   Útyping_extensionsr   Ú!lightning_fabric.accelerators.xlar   r   r   Ú9lightning_fabric.plugins.environments.cluster_environmentr   Ú	getLoggerrO   r7   r
   r   r   r   Ú<module>r_      s=   ðó Û Ý å &ç dÑ dÝ Xà€g×Ñ˜Ó!€ôm4Ð'õ m4r   