Ë
    S²jT  ã                   óâ   — d dl Z d dlmc mZ d dlmZ ddlmZ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y)é    N)ÚTensoré   )Ú_LazyNormBaseÚ	_NormBase)ÚInstanceNorm1dÚInstanceNorm2dÚInstanceNorm3dÚLazyInstanceNorm1dÚLazyInstanceNorm2dÚLazyInstanceNorm3dc                   óˆ   ‡ — e Zd Z	 	 	 	 	 	 dddœdededededed	ed
dfˆ fd„Zd„ Zd„ Zd„ Z	d„ Z
	 	 dˆ fd„Zded
efd„Zˆ xZS )Ú_InstanceNormNT)ÚbiasÚnum_featuresÚepsÚmomentumÚaffineÚtrack_running_statsr   Úreturnc                ó@   •— ||dœ}	t        ‰
| �  |||||fi |	¤d|i¤Ž y )N)ÚdeviceÚdtyper   )ÚsuperÚ__init__)Úselfr   r   r   r   r   r   r   r   Úfactory_kwargsÚ	__class__s             €ú\/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torch/nn/modules/instancenorm.pyr   z_InstanceNorm.__init__   s?   ø€ ð %+°UÑ;ˆÜ‰ÑØØØØØñ	
ð ñ	
ð ô	
ó    c                 ó   — t         ‚©N©ÚNotImplementedError©r   Úinputs     r   Ú_check_input_dimz_InstanceNorm._check_input_dim-   ó   € Ü!Ð!r   c                 ó   — t         ‚r!   r"   ©r   s    r   Ú_get_no_batch_dimz_InstanceNorm._get_no_batch_dim0   r'   r   c                 ó`   — | j                  |j                  d«      «      j                  d«      S )Nr   )Ú_apply_instance_normÚ	unsqueezeÚsqueezer$   s     r   Ú_handle_no_batch_inputz$_InstanceNorm._handle_no_batch_input3   s'   € Ø×(Ñ(¨¯©¸Ó);Ó<×DÑDÀQÓGÐGr   c           
      ó  — t        j                  || j                  | j                  | j                  | j
                  | j                  xs | j                   | j                  �| j                  | j                  «      S d| j                  «      S )Ng        )
ÚFÚinstance_normÚrunning_meanÚrunning_varÚweightr   Útrainingr   r   r   r$   s     r   r,   z"_InstanceNorm._apply_instance_norm6   sy   € Ü�‰ØØ×ÑØ×ÑØ�K‰KØ�I‰IØ�M‰MÒ9 ×!9Ñ!9Ð9Ø!Ÿ]™]Ð6ˆD�M‰MØ�H‰Hó	
ð 		
ð =@Ø�H‰Hó	
ð 		
r   c           	      óœ  •— |j                  dd «      }|€¢| j                  s–g }	dD ]  }
||
z   }||v sŒ|	j                  |«       Œ t        |	«      dkD  rd|j                  dj	                  dj                  d„ |	D «       «      | j                  j                  ¬«      «       |	D ]  }|j                  |«       Œ t        ‰| �)  |||||||«       y )NÚversion)r3   r4   r   a¤  Unexpected running stats buffer(s) {names} for {klass} with track_running_stats=False. If state_dict is a checkpoint saved before 0.4.0, this may be expected because {klass} does not track running stats by default since 0.4.0. Please remove these keys from state_dict. If the running stats are actually needed, instead set track_running_stats=True in {klass} to enable them. See the documentation of {klass} for details.z and c              3   ó(   K  — | ]
  }d |› d �–— Œ y­w)ú"N© )Ú.0Úks     r   ú	<genexpr>z6_InstanceNorm._load_from_state_dict.<locals>.<genexpr>_   s   è ø€ Ò*P¸¨Q¨q¨c°¬8Ñ*Pùs   ‚)ÚnamesÚklass)Úgetr   ÚappendÚlenÚformatÚjoinr   Ú__name__Úpopr   Ú_load_from_state_dict)r   Ú
state_dictÚprefixÚlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsr8   Úrunning_stats_keysÚnameÚkeyr   s               €r   rH   z#_InstanceNorm._load_from_state_dictB   sõ   ø€ ð !×$Ñ$ Y°Ó5ˆð ˆ? 4×#;Ò#;Ø!#ÐØ7ò 3�Ø˜t‘m�Ø˜*Ò$Ø&×-Ñ-¨cÕ2ð3ô Ð%Ó&¨Ò*Ø×!Ñ!ð@÷ AGÁØ%Ÿl™lÑ*PÐ=OÔ*PÓPØ"Ÿn™n×5Ñ5ð AGó Aôð .ò (�CØ—N‘N 3Õ'ð(ô 	‰Ñ%ØØØØØØØõ	
r   r%   c           
      óÒ  — | j                  |«       |j                  «       | j                  «       z
  }|j                  |«      | j                  k7  rU| j
                  r.t        d|› d| j                  › d|j                  |«      › d�«      ‚t        j                  d|› d�d¬«       |j                  «       | j                  «       k(  r| j                  |«      S | j                  |«      S )	Nzexpected input's size at dim=z to match num_features (z), but got: ú.zinput's size at dim=z� does not match num_features. You can silence this warning by not passing in num_features, which is not used because affine=Falseé   )Ú
stacklevel)r&   Údimr*   Úsizer   r   Ú
ValueErrorÚwarningsÚwarnr/   r,   )r   r%   Úfeature_dims      r   Úforwardz_InstanceNorm.forwardp   så   € Ø×Ñ˜eÔ$à—i‘i“k D×$:Ñ$:Ó$<Ñ<ˆØ�:‰:�kÓ" d×&7Ñ&7Ò7Ø�{Š{Ü Ø3°K°=ð AØ×*Ñ*Ð+¨<¸¿
¹
À;Ó8OÐ7PÐPQðSóð ô
 —‘Ø*¨;¨-ð 8=ð =ð  !õ	ð �9‰9‹;˜$×0Ñ0Ó2Ò2Ø×.Ñ.¨uÓ5Ð5à×(Ñ(¨Ó/Ð/r   )gñhãˆµøä>gš™™™™™¹?FFNN©r   N)rF   Ú
__module__Ú__qualname__ÚintÚfloatÚboolr   r&   r*   r/   r,   rH   r   r]   Ú__classcell__)r   s   @r   r   r      s¢   ø„ ð ØØØ$)ØØð
ð ò
àð
ð ð
ð ð	
ð
 ð
ð "ð
ð ð
ð 
õ
ò."ò"òHò

ð,
ð 
õ,
ð\0˜Vð 0¨÷ 0r   r   c                   ó$   — e Zd ZdZdefd„Zdd„Zy)r   a…  Applies Instance Normalization.

    This operation applies Instance Normalization
    over a 2D (unbatched) or 3D (batched) input as described in the paper
    `Instance Normalization: The Missing Ingredient for Fast Stylization
    <https://arxiv.org/abs/1607.08022>`__.

    .. math::

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

    The mean and standard-deviation are calculated per-dimension separately
    for each object in a mini-batch. :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size `C` (where `C` is the number of features or channels of the input) if :attr:`affine` is ``True``.
    The variance is calculated via the biased estimator, equivalent to
    `torch.var(input, correction=0)`.

    By default, this layer uses instance statistics computed from input data in
    both training and evaluation modes.

    If :attr:`track_running_stats` is set to ``True``, 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.

    .. 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.

    .. note::
        :class:`InstanceNorm1d` and :class:`LayerNorm` are very similar, but
        have some subtle differences. :class:`InstanceNorm1d` is applied
        on each channel of channeled data like multidimensional time series, but
        :class:`LayerNorm` is usually applied on entire sample and often in NLP
        tasks. Additionally, :class:`LayerNorm` applies elementwise affine
        transform, while :class:`InstanceNorm1d` usually don't apply affine
        transform.

    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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

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

    Examples::

        >>> # Without Learnable Parameters
        >>> m = nn.InstanceNorm1d(100)
        >>> # With Learnable Parameters
        >>> m = nn.InstanceNorm1d(100, affine=True)
        >>> input = torch.randn(20, 100, 40)
        >>> output = m(input)
    r   c                  ó   — y©NrU   r;   r)   s    r   r*   z InstanceNorm1d._get_no_batch_dimÏ   ó   € Ør   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y ©N)rU   é   zexpected 2D or 3D input (got úD input)©rW   rY   r$   s     r   r&   zInstanceNorm1d._check_input_dimÒ   ó0   € Ø�9‰9‹;˜fÑ$ÜÐ<¸U¿Y¹Y»[¸MÈÐRÓSÐSð %r   r^   ©rF   r_   r`   Ú__doc__ra   r*   r&   r;   r   r   r   r   ˆ   s   „ ñDðL 3ó ôTr   r   c                   ó(   — e Zd ZdZeZdefd„Zdd„Zy)r
   a  A :class:`torch.nn.InstanceNorm1d` module with lazy initialization of the ``num_features`` argument.

    The ``num_features`` argument of the :class:`InstanceNorm1d` 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:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, L)` or :math:`(C, L)`
        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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

    Shape:
        - Input: :math:`(N, C, L)` or :math:`(C, L)`
        - Output: :math:`(N, C, L)` or :math:`(C, L)` (same shape as input)
    r   c                  ó   — yrg   r;   r)   s    r   r*   z$LazyInstanceNorm1d._get_no_batch_dimö   rh   r   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y rj   rm   r$   s     r   r&   z#LazyInstanceNorm1d._check_input_dimù   rn   r   r^   )	rF   r_   r`   rp   r   Úcls_to_becomera   r*   r&   r;   r   r   r
   r
   ×   s    „ ñð8 #€Mð 3ó ôTr   r
   c                   ó$   — e Zd ZdZdefd„Zdd„Zy)r   a»  Applies Instance Normalization.

    This operation applies Instance Normalization
    over a 4D input (a mini-batch of 2D inputs
    with additional channel dimension) as described in the paper
    `Instance Normalization: The Missing Ingredient for Fast Stylization
    <https://arxiv.org/abs/1607.08022>`__.

    .. math::

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

    The mean and standard-deviation are calculated per-dimension separately
    for each object in a mini-batch. :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size `C` (where `C` is the input size) if :attr:`affine` is ``True``.
    The standard-deviation is calculated via the biased estimator, equivalent to
    `torch.var(input, correction=0)`.

    By default, this layer uses instance statistics computed from input data in
    both training and evaluation modes.

    If :attr:`track_running_stats` is set to ``True``, 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.

    .. 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.

    .. note::
        :class:`InstanceNorm2d` and :class:`LayerNorm` are very similar, but
        have some subtle differences. :class:`InstanceNorm2d` is applied
        on each channel of channeled data like RGB images, but
        :class:`LayerNorm` is usually applied on entire sample and often in NLP
        tasks. Additionally, :class:`LayerNorm` applies elementwise affine
        transform, while :class:`InstanceNorm2d` usually don't apply affine
        transform.

    Args:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, H, W)` or :math:`(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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

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

    Examples::

        >>> # Without Learnable Parameters
        >>> m = nn.InstanceNorm2d(100)
        >>> # With Learnable Parameters
        >>> m = nn.InstanceNorm2d(100, affine=True)
        >>> input = torch.randn(20, 100, 35, 45)
        >>> output = m(input)
    r   c                  ó   — y©Nrk   r;   r)   s    r   r*   z InstanceNorm2d._get_no_batch_dimG  rh   r   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y ©N)rk   é   zexpected 3D or 4D input (got rl   rm   r$   s     r   r&   zInstanceNorm2d._check_input_dimJ  rn   r   r^   ro   r;   r   r   r   r   þ   s   „ ñFðP 3ó ôTr   r   c                   ó(   — e Zd ZdZeZdefd„Zdd„Zy)r   a3  A :class:`torch.nn.InstanceNorm2d` module with lazy initialization of the ``num_features`` argument.

    The ``num_features`` argument of the :class:`InstanceNorm2d` 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:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, H, W)` or :math:`(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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

    Shape:
        - Input: :math:`(N, C, H, W)` or :math:`(C, H, W)`
        - Output: :math:`(N, C, H, W)` or :math:`(C, H, W)` (same shape as input)
    r   c                  ó   — yrw   r;   r)   s    r   r*   z$LazyInstanceNorm2d._get_no_batch_dimo  rh   r   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y ry   rm   r$   s     r   r&   z#LazyInstanceNorm2d._check_input_dimr  rn   r   r^   )	rF   r_   r`   rp   r   rt   ra   r*   r&   r;   r   r   r   r   O  ó    „ ñð: #€Mð 3ó ôTr   r   c                   ó$   — e Zd ZdZdefd„Zdd„Zy)r	   a×  Applies Instance Normalization.

    This operation applies Instance Normalization
    over a 5D input (a mini-batch of 3D inputs with additional channel dimension) as described in the paper
    `Instance Normalization: The Missing Ingredient for Fast Stylization
    <https://arxiv.org/abs/1607.08022>`__.

    .. math::

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

    The mean and standard-deviation are calculated per-dimension separately
    for each object in a mini-batch. :math:`\gamma` and :math:`\beta` are learnable parameter vectors
    of size C (where C is the input size) if :attr:`affine` is ``True``.
    The standard-deviation is calculated via the biased estimator, equivalent to
    `torch.var(input, correction=0)`.

    By default, this layer uses instance statistics computed from input data in
    both training and evaluation modes.

    If :attr:`track_running_stats` is set to ``True``, 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.

    .. 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.

    .. note::
        :class:`InstanceNorm3d` and :class:`LayerNorm` are very similar, but
        have some subtle differences. :class:`InstanceNorm3d` is applied
        on each channel of channeled data like 3D models with RGB color, but
        :class:`LayerNorm` is usually applied on entire sample and often in NLP
        tasks. Additionally, :class:`LayerNorm` applies elementwise affine
        transform, while :class:`InstanceNorm3d` usually don't apply affine
        transform.

    Args:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, D, H, W)` or :math:`(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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

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

    Examples::

        >>> # Without Learnable Parameters
        >>> m = nn.InstanceNorm3d(100)
        >>> # With Learnable Parameters
        >>> m = nn.InstanceNorm3d(100, affine=True)
        >>> input = torch.randn(20, 100, 35, 45, 10)
        >>> output = m(input)
    r   c                  ó   — y©Nrz   r;   r)   s    r   r*   z InstanceNorm3d._get_no_batch_dim¿  rh   r   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y ©N)rz   é   zexpected 4D or 5D input (got rl   rm   r$   s     r   r&   zInstanceNorm3d._check_input_dimÂ  rn   r   r^   ro   r;   r   r   r	   r	   w  s   „ ñEðN 3ó ôTr   r	   c                   ó(   — e Zd ZdZeZdefd„Zdd„Zy)r   aE  A :class:`torch.nn.InstanceNorm3d` module with lazy initialization of the ``num_features`` argument.

    The ``num_features`` argument of the :class:`InstanceNorm3d` 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:
        num_features: :math:`C` from an expected input of size
            :math:`(N, C, D, H, W)` or :math:`(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. Default: 0.1
        affine: a boolean value that when set to ``True``, this module has
            learnable affine parameters, initialized the same way as done for batch normalization.
            Default: ``False``
        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 always uses batch
            statistics in both training and eval modes. Default: ``False``
        bias: If set to ``False``, the layer will not learn an additive bias (only relevant if
            :attr:`affine` is ``True``). Default: ``True``

    Shape:
        - Input: :math:`(N, C, D, H, W)` or :math:`(C, D, H, W)`
        - Output: :math:`(N, C, D, H, W)` or :math:`(C, D, H, W)` (same shape as input)
    r   c                  ó   — yr�   r;   r)   s    r   r*   z$LazyInstanceNorm3d._get_no_batch_dimç  rh   r   Nc                 ób   — |j                  «       dvrt        d|j                  «       › d�«      ‚y rƒ   rm   r$   s     r   r&   z#LazyInstanceNorm3d._check_input_dimê  rn   r   r^   )	rF   r_   r`   rp   r	   rt   ra   r*   r&   r;   r   r   r   r   Ç  r~   r   r   )rZ   Útorch.nn.functionalÚnnÚ
functionalr1   Útorchr   Ú	batchnormr   r   Ú__all__r   r   r
   r   r   r	   r   r;   r   r   ú<module>rŽ      s‘   ðó ç Ð Ý ç /ò€ôp0�Iô p0ôfLT�]ô LTô^$T˜¨ô $TôNNT�]ô NTôb%T˜¨ô %TôPMT�]ô MTô`%T˜¨õ %Tr   