ó
    !EñiÞO  ã                   óâ   • S SK r S SKJs  Jr  S SKJr  SSKJrJ	r	  / SQr
 " S S\	5      r " S S	\5      r " S
 S\\5      r " S S\5      r " S S\\5      r " S S\5      r " S S\\5      rg)é    N)ÚTensoré   )Ú_LazyNormBaseÚ	_NormBase)ÚInstanceNorm1dÚInstanceNorm2dÚInstanceNorm3dÚLazyInstanceNorm1dÚLazyInstanceNorm2dÚLazyInstanceNorm3dc                   ó’   ^ • \ rS rSr      SS\S\S\S\S\SS4U 4S	 jjjrS
 rS r	S r
S r  SU 4S jjrS\S\4S jrSrU =r$ )Ú_InstanceNormé   NÚnum_featuresÚepsÚmomentumÚaffineÚtrack_running_statsÚreturnc                 ó4   >• XgS.n[         T	U ]  " XX4U40 UD6  g )N)ÚdeviceÚdtype)ÚsuperÚ__init__)
Úselfr   r   r   r   r   r   r   Úfactory_kwargsÚ	__class__s
            €ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/nn/modules/instancenorm.pyr   Ú_InstanceNorm.__init__   s*   ø€ ð %+Ñ;ˆÜ‰ÒØ˜xÐ1Dñ	
ØHVó	
ó    c                 ó   • [         e©N©ÚNotImplementedError©r   Úinputs     r   Ú_check_input_dimÚ_InstanceNorm._check_input_dim%   ó   € Ü!Ð!r    c                 ó   • [         er"   r#   ©r   s    r   Ú_get_no_batch_dimÚ_InstanceNorm._get_no_batch_dim(   r)   r    c                 ó`   • U R                  UR                  S5      5      R                  S5      $ )Nr   )Ú_apply_instance_normÚ	unsqueezeÚsqueezer%   s     r   Ú_handle_no_batch_inputÚ$_InstanceNorm._handle_no_batch_input+   s'   € Ø×(Ñ(¨¯©¸Ó);Ó<×DÑDÀQÓGÐGr    c           
      ó4  • [         R                  " UU R                  U R                  U R                  U R
                  U R                  =(       d    U R                  (       + U R                  b  U R                  U R                  5      $ SU R                  5      $ )Ng        )
ÚFÚinstance_normÚrunning_meanÚrunning_varÚweightÚbiasÚtrainingr   r   r   r%   s     r   r/   Ú"_InstanceNorm._apply_instance_norm.   sy   € Ü�ŠØØ×ÑØ×ÑØ�K‰KØ�I‰IØ�M‰M×9 ×!9Ñ!9Ô9Ø!Ÿ]™]Ñ6ˆD�M‰MØ�H‰Hó	
ð 		
ð =@Ø�H‰Hó	
ð 		
r    c           	      ó®  >• UR                  SS 5      nUcª  U R                  (       d™  / n	S H  n
X*-   nX±;   d  M  U	R                  U5        M!     [        U	5      S:”  ac  UR                  SR	                  SR                  S U	 5       5      U R                  R                  S95        U	 H  nUR                  U5        M     [        TU ])  UUUUUUU5        g )NÚversion)r7   r8   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   ó.   #   • U  H  nS U S 3v •  M     g7f)Ú"N© )Ú.0Úks     r   Ú	<genexpr>Ú6_InstanceNorm._load_from_state_dict.<locals>.<genexpr>W   s   é € Ð*PÒ=O¸¨Q¨q¨c°­8Ò=Où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_msgsr>   Úrunning_stats_keysÚnameÚkeyr   s               €r   rO   Ú#_InstanceNorm._load_from_state_dict:   sç   ø€ ð !×$Ñ$ Y°Ó5ˆð ‰? 4×#;×#;Ø!#ÐÛ7�Ø‘m�ØÕ$Ø&×-Ñ-¨cÖ2ñ 8ô Ð%Ó&¨Ó*Ø×!Ñ!ð@÷ AGÁØ%Ÿl™lÑ*PÑ=OÓ*PÓPØ"Ÿn™n×5Ñ5ð AGð Aôó .�CØ—N‘N 3Ö'ñ .ô 	‰Ñ%ØØØØØØØõ	
r    r&   c           
      óÜ  • U R                  U5        UR                  5       U R                  5       -
  nUR                  U5      U R                  :w  aX  U R
                  (       a.  [        SU SU R                   SUR                  U5       S35      e[        R                  " SU S3SS9  UR                  5       U R                  5       :X  a  U R                  U5      $ U R                  U5      $ )	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Úwarnr2   r/   )r   r&   Úfeature_dims      r   ÚforwardÚ_InstanceNorm.forwardh   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    rA   )gñhãˆµøä>gš™™™™™¹?FFNN©r   N)rM   Ú
__module__Ú__qualname__Ú__firstlineno__ÚintÚfloatÚboolr   r'   r,   r2   r/   rO   r   re   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s˜   ø† ð ØØØ$)ØØñ
àð
ð ð
ð ð	
ð
 ð
ð "ð
ð 
÷
ð 
ò"ò"òHò

ð,
ð 
÷,
ð\0˜Vð 0¨÷ 0ò 0r    r   c                   ó0   • \ rS rSrSrS\4S jrSS jrSrg)	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``

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                 ó   • g©Nr]   rA   r+   s    r   r,   Ú InstanceNorm1d._get_no_batch_dimÅ   ó   € Ør    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg ©N)r]   é   zexpected 2D or 3D input (got úD input)©r_   ra   r%   s     r   r'   ÚInstanceNorm1d._check_input_dimÈ   ó0   € Ø�9‰9‹;˜fÓ$ÜÐ<¸U¿Y¹Y»[¸MÈÐRÓSÐSð %r    rA   rg   ©	rM   rh   ri   rj   Ú__doc__rk   r,   r'   rn   rA   r    r   r   r   €   s   † ñBðH 3ô ÷Tr    r   c                   ó4   • \ rS rSrSr\rS\4S jrSS jr	Sr
g)	r
   éÍ   a4  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``

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                 ó   • grs   rA   r+   s    r   r,   Ú$LazyInstanceNorm1d._get_no_batch_dimê   ru   r    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg rw   rz   r%   s     r   r'   Ú#LazyInstanceNorm1d._check_input_dimí   r|   r    rA   rg   )rM   rh   ri   rj   r~   r   Úcls_to_becomerk   r,   r'   rn   rA   r    r   r
   r
   Í   s    † ñð4 #€Mð 3ô ÷Tr    r
   c                   ó0   • \ rS rSrSrS\4S jrSS jrSrg)	r   éò   aB  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``

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                 ó   • g©Nrx   rA   r+   s    r   r,   Ú InstanceNorm2d._get_no_batch_dim9  ru   r    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg ©N)rx   é   zexpected 3D or 4D input (got ry   rz   r%   s     r   r'   ÚInstanceNorm2d._check_input_dim<  r|   r    rA   rg   r}   rA   r    r   r   r   ò   s   † ñDðL 3ô ÷Tr    r   c                   ó4   • \ rS rSrSr\rS\4S jrSS jr	Sr
g)	r   iA  aF  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``

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                 ó   • gr‰   rA   r+   s    r   r,   Ú$LazyInstanceNorm2d._get_no_batch_dim_  ru   r    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg rŒ   rz   r%   s     r   r'   Ú#LazyInstanceNorm2d._check_input_dimb  r|   r    rA   rg   )rM   rh   ri   rj   r~   r   r…   rk   r,   r'   rn   rA   r    r   r   r   A  ó    † ñð6 #€Mð 3ô ÷Tr    r   c                   ó0   • \ rS rSrSrS\4S jrSS jrSrg)	r	   ig  ab  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``

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                 ó   • g©Nr�   rA   r+   s    r   r,   Ú InstanceNorm3d._get_no_batch_dim­  ru   r    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg ©N)r�   é   zexpected 4D or 5D input (got ry   rz   r%   s     r   r'   ÚInstanceNorm3d._check_input_dim°  r|   r    rA   rg   r}   rA   r    r   r	   r	   g  s   † ñCðJ 3ô ÷Tr    r	   c                   ó4   • \ rS rSrSr\rS\4S jrSS jr	Sr
g)	r   iµ  aX  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``

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                 ó   • gr—   rA   r+   s    r   r,   Ú$LazyInstanceNorm3d._get_no_batch_dimÓ  ru   r    Nc                 óf   • UR                  5       S;  a  [        SUR                  5        S35      eg rš   rz   r%   s     r   r'   Ú#LazyInstanceNorm3d._check_input_dimÖ  r|   r    rA   rg   )rM   rh   ri   rj   r~   r	   r…   rk   r,   r'   rn   rA   r    r   r   r   µ  r”   r    r   )rb   Útorch.nn.functionalÚnnÚ
functionalr5   Útorchr   Ú	batchnormr   r   Ú__all__r   r   r
   r   r   r	   r   rA   r    r   Ú<module>r¨      s‘   ðó ç Ð Ý ç /ò€ôh0�Iô h0ôVJT�]ô JTôZ"T˜¨ô "TôJLT�]ô LTô^#T˜¨ô #TôLKT�]ô KTô\#T˜¨õ #Tr    