§
    “©ºjj  ã                  óš   — d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZmZ d d
lmZ  G d„ de¦  «        ZdS )é    )Úannotations)ÚAnyN)ÚModule)Úoverride)ÚAccelerator)ÚCheckpointIO)Ú	Precision)ÚStrategyÚ
TBroadcast)Ú_DEVICEc                  óú   ‡ — e Zd ZdZ	 	 	 	 d)d*ˆ fd„Zeed+d„¦   «         ¦   «         Zeed,d„¦   «         ¦   «         Zed-d„¦   «         Z	ed.d„¦   «         Z
ed/d0d!„¦   «         Zed1d"„¦   «         Zed2d3d(„¦   «         Zˆ xZS )4ÚSingleDeviceStrategyz7Strategy that handles communication on a single device.ÚcpuNÚdevicer   ÚacceleratorúAccelerator | NoneÚcheckpoint_ioúCheckpointIO | NoneÚ	precisionúPrecision | Nonec                óä   •— t          ¦   «                              |||¬¦  «         t          |t          j        ¦  «        st          j        |¦  «        }|| _        d| _        d| _        d| _        d S )N)r   r   r   r   é   )	ÚsuperÚ__init__Ú
isinstanceÚtorchr   Ú_root_deviceÚglobal_rankÚ
local_rankÚ
world_size)Úselfr   r   r   r   Ú	__class__s        €úy/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_fabric/strategies/single_device.pyr   zSingleDeviceStrategy.__init__    sj   ø€ õ 	‰Œ×Ò [ÀÐYbÐÑcÔcÐcÝ˜&¥%¤,Ñ/Ô/ð 	*Ý”\ &Ñ)Ô)ˆFØ"ˆÔØˆÔØˆŒØˆŒˆˆó    Úreturnútorch.devicec                ó   — | j         S ©N)r   ©r!   s    r#   Úroot_devicez SingleDeviceStrategy.root_device/   s   € ð Ô Ð r$   Úboolc                ó   — dS )NT© r)   s    r#   Úis_global_zeroz#SingleDeviceStrategy.is_global_zero4   s	   € ð ˆtr$   Úmoduler   ÚNonec                ó:   — |                      | j        ¦  «         d S r(   )Útor*   )r!   r/   s     r#   Úmodule_to_devicez%SingleDeviceStrategy.module_to_device9   s   € à�	Š	�$Ô"Ñ#Ô#Ð#Ð#Ð#r$   ÚtensorúAny | torch.TensorÚargsr   Úkwargsc                ó   — |S )aœ  Reduces a tensor from several distributed processes to one aggregated tensor. As this plugin only operates
        with a single device, the reduction is simply the identity.

        Args:
            tensor: the tensor to sync and reduce
            *args: ignored
            **kwargs: ignored

        Return:
            the unmodified input as reduction is not needed for single process operation

        r-   )r!   r4   r6   r7   s       r#   Ú
all_reducezSingleDeviceStrategy.all_reduce=   s	   € ð ˆr$   Fútorch.TensorÚgroupú
Any | NoneÚ
sync_gradsc                ó   — |S )z*Perform a ``all_gather`` on all processes.r-   )r!   r4   r;   r=   s       r#   Ú
all_gatherzSingleDeviceStrategy.all_gatherM   s	   € ð ˆr$   c                ó   — d S r(   r-   )r!   r6   r7   s      r#   ÚbarrierzSingleDeviceStrategy.barrierR   s   € àˆr$   r   Úobjr   ÚsrcÚintc                ó   — |S r(   r-   )r!   rB   rC   s      r#   Ú	broadcastzSingleDeviceStrategy.broadcastV   s   € àˆ
r$   )r   NNN)r   r   r   r   r   r   r   r   )r%   r&   )r%   r+   )r/   r   r%   r0   )r4   r5   r6   r   r7   r   r%   r5   )NF)r4   r:   r;   r<   r=   r+   r%   r:   )r6   r   r7   r   r%   r0   )r   )rB   r   rC   rD   r%   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r*   r.   r3   r9   r?   rA   rF   Ú__classcell__)r"   s   @r#   r   r      sT  ø€ € € € € ØAÐAð  Ø*.Ø-1Ø&*ðð ð ð ð ð ð ð Øð!ð !ð !ñ „Xñ „Xð!ð Øðð ð ñ „Xñ „Xðð ð$ð $ð $ñ „Xð$ð ðð ð ñ „Xðð ðð ð ð ñ „Xðð ðð ð ñ „Xðð ðð ð ð ñ „Xðð ð ð ð r$   r   )Ú
__future__r   Útypingr   r   Útorch.nnr   Útyping_extensionsr   Úlightning_fabric.acceleratorsr   Ú)lightning_fabric.plugins.io.checkpoint_ior   Ú"lightning_fabric.plugins.precisionr	   Ú$lightning_fabric.strategies.strategyr
   r   Ú lightning_fabric.utilities.typesr   r   r-   r$   r#   ú<module>rV      sì   ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø BÐ BÐ BÐ BÐ BÐ BØ 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ 4Ð 4Ð 4Ð 4Ð 4Ð 4ð;ð ;ð ;ð ;ð ;˜8ñ ;ô ;ð ;ð ;ð ;r$   