§
    Ë²ÅjO™  ã                   óš  — d dl mZmZ d dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZ ddlmZ ddlmZ dd	lmZ g d
¢Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ dee¦  «        Z G d„ de¦  «        Z G d„ dee¦  «        Z G d„ de¦  «        Z G d„ dee¦  «        Z G d„ de¦  «        Z G d„ dee¦  «        Z G d„ de¦  «        ZdS )é    )ÚAnyÚOptionalN)ÚTensor)Ú
functionalÚinit)Ú	ParameterÚUninitializedBufferÚUninitializedParameteré   )ÚSyncBatchNorm)ÚLazyModuleMixin)ÚModule)ÚBatchNorm1dÚLazyBatchNorm1dÚBatchNorm2dÚLazyBatchNorm2dÚBatchNorm3dÚLazyBatchNorm3dr   c                   óÈ   ‡ — e Zd ZU dZdZg d¢Zeed<   eed<   e	e         ed<   e
ed<   e
ed<   	 	 	 	 	 	 ddedede	e         de
de
ddfˆ fd„Zdd„Zdd„Zd„ Zd„ Zˆ fd„Zˆ xZS )Ú	_NormBasez,Common base of _InstanceNorm and _BatchNorm.é   )Útrack_running_statsÚmomentumÚepsÚnum_featuresÚaffiner   r   r   r   r   çñhãˆµøä>çš™™™™™¹?TNÚreturnc           
      óŒ  •— ||dœ}t          ¦   «                              ¦   «          || _        || _        || _        || _        || _        | j        rIt          t          j	        |fi |¤Ž¦  «        | _
        t          t          j	        |fi |¤Ž¦  «        | _        n,|                      dd ¦  «         |                      dd ¦  «         | j        r¡|                      dt          j        |fi |¤Ž¦  «         |                      dt          j        |fi |¤Ž¦  «         |  |  |                      dt          j        	 d
dt          j        id	„ |                     ¦   «         D ¦   «         ¤Ž¦  «         |  nB|                      dd ¦  «         |                      dd ¦  «         |                      dd ¦  «         |                      ¦   «          d S )N©ÚdeviceÚdtypeÚweightÚbiasÚrunning_meanÚrunning_varÚnum_batches_trackedr   r#   c                 ó&   — i | ]\  }}|d k    ¯||“ŒS ©r#   © ©Ú.0ÚkÚvs      úKC:\Projects\Historical\venv\Lib\site-packages\torch/nn/modules/batchnorm.pyú
<dictcomp>z&_NormBase.__init__.<locals>.<dictcomp>K   s#   € ÐOÐOÐO¡  1À!ÀwÂ,À,�q˜!À,À,À,ó    ©r   )ÚsuperÚ__init__r   r   r   r   r   r   ÚtorchÚemptyr$   r%   Úregister_parameterÚregister_bufferÚzerosÚonesÚtensorÚlongÚitemsÚreset_parameters©
Úselfr   r   r   r   r   r"   r#   Úfactory_kwargsÚ	__class__s
            €r0   r5   z_NormBase.__init__&   s  ø€ ð %+°UÐ;Ð;ˆÝ‰Œ×ÒÑÔÐØ(ˆÔØˆŒØ ˆŒØˆŒØ#6ˆÔ ØŒ;ð 	2Ý#¥E¤K°Ð$OÐ$OÀÐ$OÐ$OÑPÔPˆDŒKÝ!¥%¤+¨lÐ"MÐ"M¸nÐ"MÐ"MÑNÔNˆDŒIˆIà×#Ò# H¨dÑ3Ô3Ð3Ø×#Ò# F¨DÑ1Ô1Ð1ØÔ#ð 	>Ø× Ò Ø¥¤¨LÐ KÐ K¸NÐ KÐ Kñô ð ð × Ò Ø�uœz¨,ÐIÐI¸.ÐIÐIñô ð ð Ð/ØÐ.Ø× Ò Ø%Ý”Øðð åœ*ðð PÐO¨×(<Ò(<Ñ(>Ô(>ÐOÑOÔOðð ñô ð ð Ð6Ð6à× Ò  °Ñ6Ô6Ð6Ø× Ò  °Ñ5Ô5Ð5Ø× Ò Ð!6¸Ñ=Ô=Ð=Ø×ÒÑÔÐÐÐr2   c                 ó°   — | j         rN| j                             ¦   «          | j                             d¦  «         | j                             ¦   «          d S d S ©Nr   )r   r&   Úzero_r'   Úfill_r(   ©rA   s    r0   Úreset_running_statsz_NormBase.reset_running_statsU   s`   € ØÔ#ð 	-ð Ô×#Ò#Ñ%Ô%Ð%ØÔ×"Ò" 1Ñ%Ô%Ð%ØÔ$×*Ò*Ñ,Ô,Ð,Ð,Ð,ð	-ð 	-r2   c                 ó¤   — |                       ¦   «          | j        r4t          j        | j        ¦  «         t          j        | j        ¦  «         d S d S ©N)rI   r   r   Úones_r$   Úzeros_r%   rH   s    r0   r?   z_NormBase.reset_parameters]   sR   € Ø× Ò Ñ"Ô"Ð"ØŒ;ð 	#ÝŒJ�t”{Ñ#Ô#Ð#ÝŒK˜œ	Ñ"Ô"Ð"Ð"Ð"ð	#ð 	#r2   c                 ó   — t           ‚rK   )ÚNotImplementedError©rA   Úinputs     r0   Ú_check_input_dimz_NormBase._check_input_dimc   s   € Ý!Ð!r2   c                 ó&   —  dj         di | j        ¤ŽS )Nzj{num_features}, eps={eps}, momentum={momentum}, affine={affine}, track_running_stats={track_running_stats}r+   )ÚformatÚ__dict__rH   s    r0   Ú
extra_reprz_NormBase.extra_reprf   s1   € ð?ð 8Ü8>ðPð PØAEÄðPð Pð	
r2   c           	      óX  •— |                      dd ¦  «        }|�|dk     rc| j        r\|dz   }	|	|vrS| j        �)| j        j        t	          j        d¦  «        k    r| j        nt	          j        dt          j        ¬¦  «        ||	<   t          ¦   «                              |||||||¦  «         d S )NÚversionr   r(   Úmetar   r*   )	Úgetr   r(   r"   r6   r<   r=   r4   Ú_load_from_state_dict)rA   Ú
state_dictÚprefixÚlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsrX   Únum_batches_tracked_keyrC   s             €r0   r[   z_NormBase._load_from_state_dictl   sÖ   ø€ ð !×$Ò$ Y°Ñ5Ô5ˆàˆO˜w¨š{˜{°Ô0H˜{ð '-Ð/DÑ&DÐ#Ø&¨jÐ8Ð8ð Ô/Ð;ØÔ0Ô7½5¼<ÈÑ;OÔ;OÒOÐOð Ô,Ð,õ œ a­u¬zÐ:Ñ:Ô:ð	 Ð2Ñ3õ 	‰Œ×%Ò%ØØØØØØØñ	
ô 	
ð 	
ð 	
ð 	
r2   ©r   r   TTNN©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_versionÚ__constants__ÚintÚ__annotations__Úfloatr   Úboolr5   rI   r?   rR   rV   r[   Ú__classcell__©rC   s   @r0   r   r      sF  ø€ € € € € € Ø6Ð6à€HØXÐXÐX€MØÐÐÑØ	€J€J�JØ�uŒoÐÐÑØ€L€L�LØÐÐÑð Ø$'ØØ$(ØØð- ð - àð- ð ð- ð ˜5”/ð	- ð
 ð- ð "ð- ð 
ð- ð - ð - ð - ð - ð - ð^-ð -ð -ð -ð#ð #ð #ð #ð"ð "ð "ð
ð 
ð 
ð 
ð  
ð  
ð  
ð  
ð  
ð  
ð  
ð  
r2   r   c                   ób   ‡ — e Zd Z	 	 	 	 	 	 ddededee         ded	ed
dfˆ fd„Zded
efd„Z	ˆ xZ
S )Ú
_BatchNormr   r   TNr   r   r   r   r   r   c                 óN   •— ||dœ} t          ¦   «         j        |||||fi |¤Ž d S ©Nr!   )r4   r5   r@   s
            €r0   r5   z_BatchNorm.__init__�   sP   ø€ ð %+°UÐ;Ð;ˆØ�‰ŒÔØ˜#˜x¨Ð1Dð	
ð 	
ØHVð	
ð 	
ð 	
ð 	
ð 	
r2   rQ   c           
      óÜ  — |                       |¦  «         | j        €d}n| j        }| j        rN| j        rG| j        �@| j                             d¦  «         | j        €dt          | j        ¦  «        z  }n| j        }	 | j        rd}n| j        d u o| j        d u }	 t          j
        || j        r| j        r| j        nd | j        r| j        r| j        nd | j        | j        ||| j        ¦  «        S )Nç        r   ç      ð?T)rR   r   Útrainingr   r(   Úadd_rn   r&   r'   ÚFÚ
batch_normr$   r%   r   )rA   rQ   Úexponential_average_factorÚbn_trainings       r0   Úforwardz_BatchNorm.forwardŸ   s1  € Ø×Ò˜eÑ$Ô$Ð$ð
 Œ=Ð Ø),Ð&Ð&à)-¬Ð&àŒ=ð 	?˜TÔ5ð 	?àÔ'Ð3ØÔ(×-Ò-¨aÑ0Ô0Ð0Ø”=Ð(Ø14µu¸TÔ=UÑ7VÔ7VÑ1VÐ.Ð.à15´Ð.ð	ð Œ=ð 	UØˆKˆKàÔ,°Ð4ÐT¸4Ô;KÈtÐ;SˆKð	õ
 Œ|Øð ”=ðØ$(Ô$<ðˆDÔÐàØ$(¤MÐW°TÔ5MÐWˆDÔÐÐSWØŒKØŒIØØ&ØŒHñ
ô 
ð 	
r2   rd   )rf   rg   rh   rl   rn   r   ro   r5   r   r   rp   rq   s   @r0   rs   rs   �   s¶   ø€ € € € € ð Ø$'ØØ$(ØØð
ð 
àð
ð ð
ð ˜5”/ð	
ð
 ð
ð "ð
ð 
ð
ð 
ð 
ð 
ð 
ð 
ð.
˜Vð .
¨ð .
ð .
ð .
ð .
ð .
ð .
ð .
ð .
r2   rs   c                   óZ   ‡ — e Zd ZU eed<   eed<   	 	 	 	 	 	 d	 dˆ fd„Zdˆ fd	„Zdd
„Zˆ xZS )Ú_LazyNormBaser$   r%   r   r   TNr   c                 ó�  •— ||dœ} t          ¦   «         j        d||ddfi |¤Ž || _        || _        | j        r"t	          di |¤Ž| _        t	          di |¤Ž| _        | j        rct          di |¤Ž| _        t          di |¤Ž| _	        t          j        	 ddt          j        id„ |                     ¦   «         D ¦   «         ¤Ž| _        d S d S )Nr!   r   Fr#   c                 ó&   — i | ]\  }}|d k    ¯||“ŒS r*   r+   r,   s      r0   r1   z*_LazyNormBase.__init__.<locals>.<dictcomp>ó   s#   € ÐKÐKÐK™D˜A˜q¸aÀ7ºl¸l�1�a¸l¸l¸lr2   r+   r3   )r4   r5   r   r   r
   r$   r%   r	   r&   r'   r6   r<   r=   r>   r(   )	rA   r   r   r   r   r"   r#   rB   rC   s	           €r0   r5   z_LazyNormBase.__init__Ô   s%  ø€ ð %+°UÐ;Ð;ˆØ�‰ŒÔð ØØØØð		
ð 		
ð ð		
ð 		
ð 		
ð ˆŒØ#6ˆÔ ØŒ;ð 	AÝ0ÐBÐB°>ÐBÐBˆDŒKÝ.Ð@Ð@°Ð@Ð@ˆDŒIØÔ#ð 	Ý 3Ð EÐ E°nÐ EÐ EˆDÔÝ2ÐDÐD°^ÐDÐDˆDÔÝ',¤|Øð(ð (å”jð(ð LÐK N×$8Ò$8Ñ$:Ô$:ÐKÑKÔKð(ð (ˆDÔ$Ð$Ð$ð	ð 	r2   c                 óŽ   •— |                       ¦   «         s-| j        dk    r$t          ¦   «                              ¦   «          d S d S d S )Nr   )Úhas_uninitialized_paramsr   r4   r?   )rA   rC   s    €r0   r?   z_LazyNormBase.reset_parametersö   sP   ø€ Ø×,Ò,Ñ.Ô.ð 	'°4Ô3DÈÒ3IÐ3IÝ‰GŒG×$Ò$Ñ&Ô&Ð&Ð&Ð&ð	'ð 	'Ð3IÐ3Ir2   c                 ó
  — |                       ¦   «         rî|j        d         | _        | j        rxt	          | j        t          ¦  «        sJ ‚t	          | j        t          ¦  «        sJ ‚| j                             | j        f¦  «         | j                             | j        f¦  «         | j	        r@| j
                             | j        f¦  «         | j                             | j        f¦  «         |                      ¦   «          d S d S rE   )r…   Úshaper   r   Ú
isinstancer$   r
   r%   Úmaterializer   r&   r'   r?   rP   s     r0   Úinitialize_parametersz#_LazyNormBase.initialize_parametersú   s  € Ø×(Ò(Ñ*Ô*ð 	$Ø %¤¨A¤ˆDÔØŒ{ð <Ý! $¤+Õ/EÑFÔFÐFÐFÐFÝ! $¤)Õ-CÑDÔDÐDÐDÐDØ”×'Ò'¨Ô):Ð(<Ñ=Ô=Ð=Ø”	×%Ò% tÔ'8Ð&:Ñ;Ô;Ð;ØÔ'ð ØÔ!×-Ò-ØÔ&Ð(ñô ð ð Ô ×,Ò,ØÔ&Ð(ñô ð ð ×!Ò!Ñ#Ô#Ð#Ð#Ð#ð	$ð 	$r2   rd   re   )	rf   rg   rh   r
   rm   r5   r?   rŠ   rp   rq   s   @r0   r�   r�   Ð   s¨   ø€ € € € € € Ø"Ð"Ð"Ñ"Ø
 Ð Ð Ñ ð ØØØ ØØð ð 
ð ð  ð  ð  ð  ð  ðD'ð 'ð 'ð 'ð 'ð 'ð$ð $ð $ð $ð $ð $ð $ð $r2   r�   c                   ó   — e Zd ZdZd„ ZdS )r   aë  Applies Batch Normalization over a 2D or 3D input.

    Method described in the paper
    `Batch Normalization: Accelerating Deep Network Training by Reducing
    Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`__ .

    .. math::

        y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta

    The mean and standard-deviation are calculated per-dimension over
    the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size `C` (where `C` is the number of features or channels of the input). By default, the
    elements of :math:`\gamma` are set to 1 and the elements of :math:`\beta` are set to 0.
    At train time in the forward pass, the variance is calculated via the biased estimator,
    equivalent to ``torch.var(input, unbiased=False)``. However, the value stored in the
    moving average of the variance is calculated via the unbiased  estimator, equivalent to
    ``torch.var(input, unbiased=True)``.

    Also by default, during training this layer keeps running estimates of its
    computed mean and variance, which are then used for normalization during
    evaluation. The running estimates are kept with a default :attr:`momentum`
    of 0.1.

    If :attr:`track_running_stats` is set to ``False``, this layer then does not
    keep running estimates, and batch statistics are instead used during
    evaluation time as well.

    .. note::
        This :attr:`momentum` argument is different from one used in optimizer
        classes and the conventional notion of momentum. Mathematically, the
        update rule for running statistics here is
        :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`,
        where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the
        new observed value.

    Because the Batch Normalization is done over the `C` dimension, computing statistics
    on `(N, L)` slices, it's common terminology to call this Temporal Batch Normalization.

    Args:
        num_features: number of features or channels :math:`C` of the input
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``

    Shape:
        - Input: :math:`(N, C)` or :math:`(N, C, L)`, where :math:`N` is the batch size,
          :math:`C` is the number of features or channels, and :math:`L` is the sequence length
        - Output: :math:`(N, C)` or :math:`(N, C, L)` (same shape as input)

    Examples::

        >>> # With Learnable Parameters
        >>> m = nn.BatchNorm1d(100)
        >>> # Without Learnable Parameters
        >>> m = nn.BatchNorm1d(100, affine=False)
        >>> input = torch.randn(20, 100)
        >>> output = m(input)
    c                 ó´   — |                      ¦   «         dk    r=|                      ¦   «         dk    r't          d|                      ¦   «         › d�¦  «        ‚d S d S ©Nr   é   zexpected 2D or 3D input (got úD input)©ÚdimÚ
ValueErrorrP   s     r0   rR   zBatchNorm1d._check_input_dimS  óW   € Ø�9Š9‰;Œ;˜!ÒÐ §	¢	¡¤¨qÒ 0Ð 0ÝÐR¸U¿YºY¹[¼[ÐRÐRÐRÑSÔSÐSð ÐÐ 0Ð 0r2   N©rf   rg   rh   ri   rR   r+   r2   r0   r   r     s5   € € € € € ðDð DðLTð Tð Tð Tð Tr2   r   c                   ó   — e Zd ZdZeZd„ ZdS )r   aR  A :class:`torch.nn.BatchNorm1d` module with lazy initialization.

    Lazy initialization based on the ``num_features`` argument of the :class:`BatchNorm1d` that is inferred
    from the ``input.size(1)``.
    The attributes that will be lazily initialized are `weight`, `bias`,
    `running_mean` and `running_var`.

    Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation
    on lazy modules and their limitations.

    Args:
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``
    c                 ó´   — |                      ¦   «         dk    r=|                      ¦   «         dk    r't          d|                      ¦   «         › d�¦  «        ‚d S d S r�   r�   rP   s     r0   rR   z LazyBatchNorm1d._check_input_dimu  r“   r2   N)rf   rg   rh   ri   r   Úcls_to_becomerR   r+   r2   r0   r   r   X  s9   € € € € € ðð ð4  €MðTð Tð Tð Tð Tr2   r   c                   ó   — e Zd ZdZd„ ZdS )r   aœ  Applies Batch Normalization over a 4D input.

    4D is a mini-batch of 2D inputs
    with additional channel dimension. Method described in the paper
    `Batch Normalization: Accelerating Deep Network Training by Reducing
    Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`__ .

    .. math::

        y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta

    The mean and standard-deviation are calculated per-dimension over
    the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are set
    to 1 and the elements of :math:`\beta` are set to 0. At train time in the forward pass, the
    standard-deviation is calculated via the biased estimator, equivalent to
    ``torch.var(input, unbiased=False)``. However, the value stored in the moving average of the
    standard-deviation is calculated via the unbiased  estimator, equivalent to
    ``torch.var(input, unbiased=True)``.

    Also by default, during training this layer keeps running estimates of its
    computed mean and variance, which are then used for normalization during
    evaluation. The running estimates are kept with a default :attr:`momentum`
    of 0.1.

    If :attr:`track_running_stats` is set to ``False``, this layer then does not
    keep running estimates, and batch statistics are instead used during
    evaluation time as well.

    .. note::
        This :attr:`momentum` argument is different from one used in optimizer
        classes and the conventional notion of momentum. Mathematically, the
        update rule for running statistics here is
        :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`,
        where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the
        new observed value.

    Because the Batch Normalization is done over the `C` dimension, computing statistics
    on `(N, H, W)` slices, it's common terminology to call this Spatial Batch Normalization.

    Args:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, H, W)`
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``

    Shape:
        - Input: :math:`(N, C, H, W)`
        - Output: :math:`(N, C, H, W)` (same shape as input)

    Examples::

        >>> # With Learnable Parameters
        >>> m = nn.BatchNorm2d(100)
        >>> # Without Learnable Parameters
        >>> m = nn.BatchNorm2d(100, affine=False)
        >>> input = torch.randn(20, 100, 35, 45)
        >>> output = m(input)
    c                 ó€   — |                      ¦   «         dk    r%t          d|                      ¦   «         › d�¦  «        ‚d S ©Né   zexpected 4D input (got r�   r�   rP   s     r0   rR   zBatchNorm2d._check_input_dimÂ  ó?   € Ø�9Š9‰;Œ;˜!ÒÐÝÐL°u·y²y±{´{ÐLÐLÐLÑMÔMÐMð Ðr2   Nr”   r+   r2   r0   r   r   z  ó5   € € € € € ðEð EðNNð Nð Nð Nð Nr2   r   c                   ó   — e Zd ZdZeZd„ ZdS )r   aU  A :class:`torch.nn.BatchNorm2d` module with lazy initialization.

    Lazy initialization is done for the ``num_features`` argument of the :class:`BatchNorm2d` that is inferred
    from the ``input.size(1)``.
    The attributes that will be lazily initialized are `weight`, `bias`,
    `running_mean` and `running_var`.

    Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation
    on lazy modules and their limitations.

    Args:
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``
    c                 ó€   — |                      ¦   «         dk    r%t          d|                      ¦   «         › d�¦  «        ‚d S rš   r�   rP   s     r0   rR   z LazyBatchNorm2d._check_input_dimä  rœ   r2   N)rf   rg   rh   ri   r   r—   rR   r+   r2   r0   r   r   Ç  ó9   € € € € € ðð ð4  €MðNð Nð Nð Nð Nr2   r   c                   ó   — e Zd ZdZd„ ZdS )r   aÑ  Applies Batch Normalization over a 5D input.

    5D is a mini-batch of 3D inputs with additional channel dimension as described in the paper
    `Batch Normalization: Accelerating Deep Network Training by Reducing
    Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`__ .

    .. math::

        y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta

    The mean and standard-deviation are calculated per-dimension over
    the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are set
    to 1 and the elements of :math:`\beta` are set to 0. At train time in the forward pass, the
    standard-deviation is calculated via the biased estimator, equivalent to
    ``torch.var(input, unbiased=False)``. However, the value stored in the moving average of the
    standard-deviation is calculated via the unbiased  estimator, equivalent to
    ``torch.var(input, unbiased=True)``.

    Also by default, during training this layer keeps running estimates of its
    computed mean and variance, which are then used for normalization during
    evaluation. The running estimates are kept with a default :attr:`momentum`
    of 0.1.

    If :attr:`track_running_stats` is set to ``False``, this layer then does not
    keep running estimates, and batch statistics are instead used during
    evaluation time as well.

    .. note::
        This :attr:`momentum` argument is different from one used in optimizer
        classes and the conventional notion of momentum. Mathematically, the
        update rule for running statistics here is
        :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`,
        where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the
        new observed value.

    Because the Batch Normalization is done over the `C` dimension, computing statistics
    on `(N, D, H, W)` slices, it's common terminology to call this Volumetric Batch Normalization
    or Spatio-temporal Batch Normalization.

    Args:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, D, H, W)`
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``

    Shape:
        - Input: :math:`(N, C, D, H, W)`
        - Output: :math:`(N, C, D, H, W)` (same shape as input)

    Examples::

        >>> # With Learnable Parameters
        >>> m = nn.BatchNorm3d(100)
        >>> # Without Learnable Parameters
        >>> m = nn.BatchNorm3d(100, affine=False)
        >>> input = torch.randn(20, 100, 35, 45, 10)
        >>> output = m(input)
    c                 ó€   — |                      ¦   «         dk    r%t          d|                      ¦   «         › d�¦  «        ‚d S ©Né   zexpected 5D input (got r�   r�   rP   s     r0   rR   zBatchNorm3d._check_input_dim1  rœ   r2   Nr”   r+   r2   r0   r   r   é  r�   r2   r   c                   ó   — e Zd ZdZeZd„ ZdS )r   aU  A :class:`torch.nn.BatchNorm3d` module with lazy initialization.

    Lazy initialization is done for the ``num_features`` argument of the :class:`BatchNorm3d` that is inferred
    from the ``input.size(1)``.
    The attributes that will be lazily initialized are `weight`, `bias`,
    `running_mean` and `running_var`.

    Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation
    on lazy modules and their limitations.

    Args:
        eps: a value added to the denominator for numerical stability.
            Default: 1e-5
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``
    c                 ó€   — |                      ¦   «         dk    r%t          d|                      ¦   «         › d�¦  «        ‚d S r£   r�   rP   s     r0   rR   z LazyBatchNorm3d._check_input_dimS  rœ   r2   N)rf   rg   rh   ri   r   r—   rR   r+   r2   r0   r   r   6  r    r2   r   c                   óœ   ‡ — e Zd ZdZ	 	 	 	 	 	 	 ddededee         d	ed
edee         ddfˆ fd„Z	d„ Z
d„ Zdedefd„Zedd„¦   «         Zˆ xZS )r   a  Applies Batch Normalization over a N-Dimensional input.

    The N-D input is a mini-batch of [N-2]D inputs with additional channel dimension) as described in the paper
    `Batch Normalization: Accelerating Deep Network Training by Reducing
    Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`__ .

    .. math::

        y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta

    The mean and standard-deviation are calculated per-dimension over all
    mini-batches of the same process groups. :math:`\gamma` and :math:`\beta`
    are learnable parameter vectors of size `C` (where `C` is the input size).
    By default, the elements of :math:`\gamma` are sampled from
    :math:`\mathcal{U}(0, 1)` and the elements of :math:`\beta` are set to 0.
    The standard-deviation is calculated via the biased estimator, equivalent to
    `torch.var(input, unbiased=False)`.

    Also by default, during training this layer keeps running estimates of its
    computed mean and variance, which are then used for normalization during
    evaluation. The running estimates are kept with a default :attr:`momentum`
    of 0.1.

    If :attr:`track_running_stats` is set to ``False``, this layer then does not
    keep running estimates, and batch statistics are instead used during
    evaluation time as well.

    .. note::
        This :attr:`momentum` argument is different from one used in optimizer
        classes and the conventional notion of momentum. Mathematically, the
        update rule for running statistics here is
        :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`,
        where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the
        new observed value.

    Because the Batch Normalization is done for each channel in the ``C`` dimension, computing
    statistics on ``(N, +)`` slices, it's common terminology to call this Volumetric Batch
    Normalization or Spatio-temporal Batch Normalization.

    Currently :class:`SyncBatchNorm` only supports
    :class:`~torch.nn.DistributedDataParallel` (DDP) with single GPU per process. Use
    :meth:`torch.nn.SyncBatchNorm.convert_sync_batchnorm()` to convert
    :attr:`BatchNorm*D` layer to :class:`SyncBatchNorm` before wrapping
    Network with DDP.

    Args:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, +)`
        eps: a value added to the denominator for numerical stability.
            Default: ``1e-5``
        momentum: the value used for the running_mean and running_var
            computation. Can be set to ``None`` for cumulative moving average
            (i.e. simple average). Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters. Default: ``True``
        track_running_stats: a boolean value that when set to ``True``, this
            module tracks the running mean and variance, and when set to ``False``,
            this module does not track such statistics, and initializes statistics
            buffers :attr:`running_mean` and :attr:`running_var` as ``None``.
            When these buffers are ``None``, this module always uses batch statistics.
            in both training and eval modes. Default: ``True``
        process_group: synchronization of stats happen within each process group
            individually. Default behavior is synchronization across the whole
            world

    Shape:
        - Input: :math:`(N, C, +)`
        - Output: :math:`(N, C, +)` (same shape as input)

    .. note::
        Synchronization of batchnorm statistics occurs only while training, i.e.
        synchronization is disabled when ``model.eval()`` is set or if
        ``self.training`` is otherwise ``False``.

    Examples::

        >>> # xdoctest: +SKIP
        >>> # With Learnable Parameters
        >>> m = nn.SyncBatchNorm(100)
        >>> # creating process group (optional)
        >>> # ranks is a list of int identifying rank ids.
        >>> ranks = list(range(8))
        >>> r1, r2 = ranks[:4], ranks[4:]
        >>> # Note: every rank calls into new_group for every
        >>> # process group created, even if that rank is not
        >>> # part of the group.
        >>> process_groups = [torch.distributed.new_group(pids) for pids in [r1, r2]]
        >>> process_group = process_groups[0 if dist.get_rank() <= 3 else 1]
        >>> # Without Learnable Parameters
        >>> m = nn.BatchNorm3d(100, affine=False, process_group=process_group)
        >>> input = torch.randn(20, 100, 35, 45, 10)
        >>> output = m(input)

        >>> # network is nn.BatchNorm layer
        >>> sync_bn_network = nn.SyncBatchNorm.convert_sync_batchnorm(network, process_group)
        >>> # only single gpu per process is currently supported
        >>> ddp_sync_bn_network = torch.nn.parallel.DistributedDataParallel(
        >>>                         sync_bn_network,
        >>>                         device_ids=[args.local_rank],
        >>>                         output_device=args.local_rank)
    r   r   TNr   r   r   r   r   Úprocess_groupr   c	                 ó\   •— ||dœ}	 t          ¦   «         j        |||||fi |	¤Ž || _        d S ru   )r4   r5   r¨   )rA   r   r   r   r   r   r¨   r"   r#   rB   rC   s             €r0   r5   zSyncBatchNorm.__init__¿  sV   ø€ ð %+°UÐ;Ð;ˆØ�‰ŒÔØ˜#˜x¨Ð1Dð	
ð 	
ØHVð	
ð 	
ð 	
ð +ˆÔÐÐr2   c                 ó€   — |                      ¦   «         dk     r%t          d|                      ¦   «         › d�¦  «        ‚d S )Nr   z expected at least 2D input (got r�   r�   rP   s     r0   rR   zSyncBatchNorm._check_input_dimÐ  s<   € Ø�9Š9‰;Œ;˜Š?ˆ?ÝÐUÀÇ	Â	ÁÄÐUÐUÐUÑVÔVÐVð ˆ?r2   c                 óV   — |                      d¦  «        dk    rt          d¦  «        ‚d S )Nr   r   z9SyncBatchNorm number of input channels should be non-zero)Úsizer’   rP   s     r0   Ú_check_non_zero_input_channelsz,SyncBatchNorm._check_non_zero_input_channelsÔ  s4   € Ø�:Š:�a‰=Œ=˜AÒÐÝØKñô ð ð Ðr2   rQ   c                 óR  — |                       |¦  «         |                      |¦  «         | j        €d}n| j        }| j        rU| j        rN| j        €J ‚| j                             d¦  «         | j        €d| j                             ¦   «         z  }n| j        }	 | j        rd}n| j        d u o| j	        d u }	 | j        r| j        r| j        nd }| j        r| j        r| j	        nd }|oB| j        o;t          j                             ¦   «         ot          j                             ¦   «         }|r£|j        j        dt          j                             ¦   «         fvr.t%          dt          j                             ¦   «         › �¦  «        ‚t          j        j        j        }| j        r| j        }t          j                             |¦  «        }|dk    }|s*t/          j        |||| j        | j        ||| j        ¦  «        S |sJ ‚t9          j        || j        | j        ||| j        |||¦	  «	        S )Nrw   r   rx   TÚcudaz4SyncBatchNorm expected input tensor to be on GPU or )rR   r­   r   ry   r   r(   rz   Úitemr&   r'   r6   ÚdistributedÚis_availableÚis_initializedr"   ÚtypeÚ_CÚ_get_privateuse1_backend_namer’   ÚgroupÚWORLDr¨   Úget_world_sizer{   r|   r$   r%   r   Úsync_batch_normÚapply)	rA   rQ   r}   r~   r&   r'   Ú	need_syncr¨   Ú
world_sizes	            r0   r   zSyncBatchNorm.forwardÚ  s™  € Ø×Ò˜eÑ$Ô$Ð$Ø×+Ò+¨EÑ2Ô2Ð2ð
 Œ=Ð Ø),Ð&Ð&à)-¬Ð&àŒ=ð 	;˜TÔ5ð 	;ØÔ+Ð7Ð7Ð7ØÔ$×)Ò)¨!Ñ,Ô,Ð,ØŒ}Ð$Ø-0°4Ô3K×3PÒ3PÑ3RÔ3RÑ-RÐ*Ð*à-1¬]Ð*ð	ð Œ=ð 	UØˆKˆKàÔ,°Ð4ÐT¸4Ô;KÈtÐ;SˆKð	ð &*¤]ÐX°dÔ6NÐXˆDÔÐÐTXð 	ð %)¤MÐW°TÔ5MÐWˆDÔÐÐSWð 	ð ð 3Ø”ð3åÔ!×.Ò.Ñ0Ô0ð3õ Ô!×0Ò0Ñ2Ô2ð	 	ð ð 	'àŒ|Ô ØÝ”×6Ò6Ñ8Ô8ð)ð ð õ !ðBÝ”x×=Ò=Ñ?Ô?ðBð Bñô ð õ
 "Ô-Ô3Ô9ˆMØÔ!ð 3Ø $Ô 2�ÝÔ*×9Ò9¸-ÑHÔHˆJØ" QšˆIð ð 	Ý”<ØØØØ”Ø”	ØØ*Ø”ñ	ô 	ð 	ð ÐÐ�;Ý"Ô(ØØ”Ø”	ØØØ”Ø*ØØñ
ô 
ð 
r2   c                 óŒ  — |}t          |t          j        j        j        j        ¦  «        rÓt          j                             |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        |_        |j        |_        t'          |d¦  «        r|j        |_        |                     ¦   «         D ]/\  }}|                     ||                      ||¦  «        ¦  «         Œ0~|S )aa  Converts all :attr:`BatchNorm*D` layers in the model to :class:`torch.nn.SyncBatchNorm` layers.

        Args:
            module (nn.Module): module containing one or more :attr:`BatchNorm*D` layers
            process_group (optional): process group to scope synchronization,
                default is the whole world

        Returns:
            The original :attr:`module` with the converted :class:`torch.nn.SyncBatchNorm`
            layers. If the original :attr:`module` is a :attr:`BatchNorm*D` layer,
            a new :class:`torch.nn.SyncBatchNorm` layer object will be returned
            instead.

        Example::

            >>> # Network with nn.BatchNorm layer
            >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
            >>> module = torch.nn.Sequential(
            >>>            torch.nn.Linear(20, 100),
            >>>            torch.nn.BatchNorm1d(100),
            >>>          ).cuda()
            >>> # creating process group (optional)
            >>> # ranks is a list of int identifying rank ids.
            >>> ranks = list(range(8))
            >>> r1, r2 = ranks[:4], ranks[4:]
            >>> # Note: every rank calls into new_group for every
            >>> # process group created, even if that rank is not
            >>> # part of the group.
            >>> # xdoctest: +SKIP("distributed")
            >>> process_groups = [torch.distributed.new_group(pids) for pids in [r1, r2]]
            >>> process_group = process_groups[0 if dist.get_rank() <= 3 else 1]
            >>> sync_bn_module = torch.nn.SyncBatchNorm.convert_sync_batchnorm(module, process_group)

        NÚqconfig)rˆ   r6   ÚnnÚmodulesÚ	batchnormrs   r   r   r   r   r   r   Úno_gradr$   r%   r&   r'   r(   ry   Úhasattrr¿   Únamed_childrenÚ
add_moduleÚconvert_sync_batchnorm)ÚclsÚmoduler¨   Úmodule_outputÚnameÚchilds         r0   rÇ   z$SyncBatchNorm.convert_sync_batchnorm6  s‚  € ðH ˆÝ�f�eœhÔ.Ô8ÔCÑDÔDð 	7Ý!œH×2Ò2ØÔ#Ø”
Ø”Ø”ØÔ*Øñô ˆMð Œ}ð 5Ý”]‘_”_ð 5ð 5Ø+1¬=�MÔ(Ø)/¬�MÔ&ð5ð 5ð 5ñ 5ô 5ð 5ð 5ð 5ð 5ð 5ð 5øøøð 5ð 5ð 5ð 5ð *0Ô)<ˆMÔ&Ø(.Ô(:ˆMÔ%Ø06Ô0JˆMÔ-Ø%+¤_ˆMÔ"Ý�v˜yÑ)Ô)ð 7Ø(.¬�Ô%Ø!×0Ò0Ñ2Ô2ð 	ð 	‰KˆD�%Ø×$Ò$Ø�c×0Ò0°¸ÑFÔFñô ð ð ð ØÐs   ÂB(Â(B,Â/B,)r   r   TTNNNrK   )rf   rg   rh   ri   rl   rn   r   ro   r   r5   rR   r­   r   r   ÚclassmethodrÇ   rp   rq   s   @r0   r   r   X  s  ø€ € € € € ðdð dðR Ø$'ØØ$(Ø'+ØØð+ð +àð+ð ð+ð ˜5”/ð	+ð
 ð+ð "ð+ð   ”}ð+ð 
ð+ð +ð +ð +ð +ð +ð"Wð Wð Wðð ð ðZ˜Vð Z¨ð Zð Zð Zð Zðx ð<ð <ð <ñ „[ð<ð <ð <ð <ð <r2   r   )Útypingr   r   r6   r   Útorch.nnr   r{   r   Útorch.nn.parameterr   r	   r
   Ú
_functionsr   rº   Úlazyr   rÉ   r   Ú__all__r   rs   r�   r   r   r   r   r   r   r+   r2   r0   ú<module>rÔ      sÎ  ðà  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ Uà 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð ðð ð €ðs
ð s
ð s
ð s
ð s
�ñ s
ô s
ð s
ðl>
ð >
ð >
ð >
ð >
�ñ >
ô >
ð >
ðB9$ð 9$ð 9$ð 9$ð 9$�O Yñ 9$ô 9$ð 9$ðxITð ITð ITð ITð IT�*ñ ITô ITð ITðXTð Tð Tð Tð T�m Zñ Tô Tð TðDJNð JNð JNð JNð JN�*ñ JNô JNð JNðZNð Nð Nð Nð N�m Zñ Nô Nð NðDJNð JNð JNð JNð JN�*ñ JNô JNð JNðZNð Nð Nð Nð N�m Zñ Nô Nð NðD[ð [ð [ð [ð [�Jñ [ô [ð [ð [ð [r2   