§
    “©ºjl  ã                   ó¾   — d dl mZmZ d dlZd dlmZ d dlmZ d dlmZ  G d„ de¦  «        Z	 G d„ d	e	¦  «        Z
 G d
„ dej        j        j        j        ¦  «        ZdS )é    )ÚABCÚabstractmethodN)ÚTensor)ÚModule)Úoverridec                   óR   — e Zd ZdZededefd„¦   «         Zededefd„¦   «         ZdS )Ú	LayerSynczxAbstract base class for creating plugins that wrap layers of a model with synchronization logic for
    multiprocessing.ÚmodelÚreturnc                 ó   — dS )zJOverride this method to apply synchronization to the layers of this model.N© ©Úselfr
   s     út/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/plugins/layer_sync.pyÚapplyzLayerSync.apply   ó   € € € ó    c                 ó   — dS )zEOverride this method to undo all modifications made in :meth:`apply`.Nr   r   s     r   ÚrevertzLayerSync.revert   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   r	      sˆ   € € € € € ðð ð ðY˜6ð Y fð Yð Yð Yñ „^ðYð ðT˜Fð T vð Tð Tð Tñ „^ðTð Tð Tr   r	   c                   óR   — e Zd ZdZededefd„¦   «         Zededefd„¦   «         ZdS )ÚTorchSyncBatchNormz®A plugin that wraps all batch normalization layers of a model with synchronization logic for multiprocessing.

    This plugin has no effect in single-device operation.

    r
   r   c                 óJ   — t           j        j                             |¦  «        S )a‰  Add global batchnorm for a model spread across multiple GPUs and nodes.

        Override this method to synchronize batchnorm layers between specific process groups instead
        of the whole world.

        Args:
            model: Reference to the current LightningModule

        Return:
            LightningModule with batchnorm layers synchronized within the process groups.

        )ÚtorchÚnnÚSyncBatchNormÚconvert_sync_batchnormr   s     r   r   zTorchSyncBatchNorm.apply+   s   € õ ŒxÔ%×<Ò<¸UÑCÔCÐCr   c                 óP  — |}t          |t          j        j        j        j        ¦  «        r¶t          |j        |j        |j	        |j
        |j        ¦  «        }|j
        rCt          j        ¦   «         5  |j        |_        |j        |_        ddd¦  «         n# 1 swxY w Y   |j        |_        |j        |_        |j        |_        t%          |d¦  «        r|j        |_        |                     ¦   «         D ].\  }}|                     ||                      |¦  «        ¦  «         Œ/~|S )a  Convert the wrapped batchnorm layers back to regular batchnorm layers.

        Args:
            model: Reference to the current LightningModule

        Return:
            LightningModule with regular batchnorm layers that will no longer sync across processes.

        NÚqconfig)Ú
isinstancer   r   ÚmodulesÚ	batchnormr   Ú_BatchNormXdÚnum_featuresÚepsÚmomentumÚaffineÚtrack_running_statsÚno_gradÚweightÚbiasÚrunning_meanÚrunning_varÚnum_batches_trackedÚhasattrr"   Únamed_childrenÚ
add_moduler   )r   r
   Úconverted_moduleÚnameÚchilds        r   r   zTorchSyncBatchNorm.revert;   se  € ð !ÐÝ�e�UœXÔ-Ô7ÔEÑFÔFð 	9õ  ,ØÔ" E¤I¨u¬~¸u¼|ÈUÔMfñ ô  Ðð Œ|ð 7Ý”]‘_”_ð 7ð 7Ø.3¬lÐ$Ô+Ø,1¬JÐ$Ô)ð7ð 7ð 7ñ 7ô 7ð 7ð 7ð 7ð 7ð 7ð 7øøøð 7ð 7ð 7ð 7ð -2Ô,>ÐÔ)Ø+0Ô+<ÐÔ(Ø38Ô3LÐÔ0Ý�u˜iÑ(Ô(ð 9Ø+0¬=Ð Ô(Ø ×/Ò/Ñ1Ô1ð 	Bð 	B‰KˆD�%Ø×'Ò'¨¨d¯kªk¸%Ñ.@Ô.@ÑAÔAÐAÐAØØÐs   Á2BÂBÂBN)r   r   r   r   r   r   r   r   r   r   r   r   r   $   s€   € € € € € ðð ð ðD˜6ð D fð Dð Dð Dñ „XðDð ð ˜Fð   vð  ð  ð  ñ „Xð ð  ð  r   r   c                   ó.   — e Zd Zededdfd„¦   «         ZdS )r&   Úinputr   Nc                 ó   — d S )Nr   )r   r9   s     r   Ú_check_input_dimz_BatchNormXd._check_input_dim_   s	   € ð 	ˆr   )r   r   r   r   r   r;   r   r   r   r&   r&   ^   s@   € € € € € Øð fð °ð ð ð ñ „Xðð ð r   r&   )Úabcr   r   r   r   Útorch.nnr   Útyping_extensionsr   r	   r   r   r$   r%   Ú
_BatchNormr&   r   r   r   ú<module>r@      sú   ðð $Ð #Ð #Ð #Ð #Ð #Ð #Ð #à €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &ð
Tð 
Tð 
Tð 
Tð 
T�ñ 
Tô 
Tð 
Tð7 ð 7 ð 7 ð 7 ð 7 ˜ñ 7 ô 7 ð 7 ðtð ð ð ð �5”8Ô#Ô-Ô8ñ ô ð ð ð r   