§
    T�’j   ã            	       ó¾   — d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZ g d¢Z G d„ d	¦  «        Z ed
e
¬¦  «        Zddedededefd„Zddededefd„ZdS )z;Weight Normalization from https://arxiv.org/abs/1602.07868.é    )ÚAnyÚTypeVar)Ú
deprecated)Ú_weight_normÚnorm_except_dim)ÚModule)Ú	ParameterÚUninitializedParameter)Ú
WeightNormÚweight_normÚremove_weight_normc                   ó¶   — e Zd ZU eed<   eed<   dededdfd„Zdedefd„Z	e
 ede¬	¦  «        dededd fd
„¦   «         ¦   «         Zdeddfd„Zdededdfd„ZdS )r   ÚnameÚdimÚreturnNc                 ó*   — |€d}|| _         || _        d S )Néÿÿÿÿ)r   r   )Úselfr   r   s      úHC:\Projects\DSCons\.venv\Lib\site-packages\torch\nn\utils\weight_norm.pyÚ__init__zWeightNorm.__init__   s   € Øˆ;ØˆCØˆŒ	ØˆŒˆˆó    Úmodulec                 óŽ   — t          || j        dz   ¦  «        }t          || j        dz   ¦  «        }t          ||| j        ¦  «        S ©NÚ_gÚ_v)Úgetattrr   r   r   )r   r   ÚgÚvs       r   Úcompute_weightzWeightNorm.compute_weight   sB   € Ý�F˜DœI¨Ñ,Ñ-Ô-ˆÝ�F˜DœI¨Ñ,Ñ-Ô-ˆÝ˜A˜q $¤(Ñ+Ô+Ð+r   ze`torch.nn.utils.weight_norm` is deprecated in favor of `torch.nn.utils.parametrizations.weight_norm`.)Úcategoryc           
      ó~  — | j                              ¦   «         D ]4}t          |t          ¦  «        r|j        |k    rt          d|› �¦  «        ‚Œ5|€d}t          ||¦  «        }t          | |¦  «        }t          |t          ¦  «        rt          d¦  «        ‚| j	        |= |  
                    |dz   t          t          |d|¦  «        j        ¦  «        ¦  «         |  
                    |dz   t          |j        ¦  «        ¦  «         t          | ||                     | ¦  «        ¦  «         |                      |¦  «         |S )Nz<Cannot register two weight_norm hooks on the same parameter r   zŽThe module passed to `WeightNorm` can't have uninitialized parameters. Make sure to run the dummy forward before applying weight normalizationr   é   r   )Ú_forward_pre_hooksÚvaluesÚ
isinstancer   r   ÚRuntimeErrorr   r
   Ú
ValueErrorÚ_parametersÚregister_parameterr	   r   ÚdataÚsetattrr    Úregister_forward_pre_hook)r   r   r   ÚhookÚfnÚweights         r   ÚapplyzWeightNorm.apply   s\  € ð Ô-×4Ò4Ñ6Ô6ð 	ð 	ˆDÝ˜$¥
Ñ+Ô+ð °´	¸TÒ0AÐ0AÝ"ØYÐSWÐYÐYñô ð øð ˆ;ØˆCå˜˜cÑ"Ô"ˆå˜ Ñ&Ô&ˆÝ�fÕ4Ñ5Ô5ð 	ÝðZñô ð ð
 Ô˜tÐ$ð 	×!Ò!Ø�4‰K�¥?°6¸1¸cÑ#BÔ#BÔ#GÑHÔHñ	
ô 	
ð 	
ð 	×!Ò! $¨¡+­y¸¼Ñ/EÔ/EÑFÔFÐFÝ�˜˜b×/Ò/°Ñ7Ô7Ñ8Ô8Ð8ð 	×(Ò(¨Ñ,Ô,Ð,àˆ	r   c                 óê   — |                       |¦  «        }t          || j        ¦  «         |j        | j        dz   = |j        | j        dz   = t	          || j        t          |j        ¦  «        ¦  «         d S r   )r    Údelattrr   r)   r,   r	   r+   )r   r   r0   s      r   ÚremovezWeightNorm.removeF   so   € Ø×$Ò$ VÑ,Ô,ˆÝ�˜œ	Ñ"Ô"Ð"ØÔ˜tœy¨4Ñ/Ð0ØÔ˜tœy¨4Ñ/Ð0Ý�˜œ	¥9¨V¬[Ñ#9Ô#9Ñ:Ô:Ð:Ð:Ð:r   Úinputsc                 óX   — t          || j        |                      |¦  «        ¦  «         d S )N)r,   r   r    )r   r   r5   s      r   Ú__call__zWeightNorm.__call__M   s*   € Ý�˜œ	 4×#6Ò#6°vÑ#>Ô#>Ñ?Ô?Ð?Ð?Ð?r   )Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__Úintr   r   r   r    Ústaticmethodr   ÚFutureWarningr1   r4   r7   © r   r   r   r      s$  € € € € € € Ø
€I€I�IØ	€H€H�Hð˜Sð  sð ¨tð ð ð ð ð, Vð ,°ð ,ð ,ð ,ð ,ð
 Ø€Zð	Eàðñ ô ð
˜Cð  cð ¨lð ð ð ñô ñ „\ððB;˜Vð ;¨ð ;ð ;ð ;ð ;ð@˜vð @¨sð @°tð @ð @ð @ð @ð @ð @r   r   ÚT_module)Úboundr0   r   r   r   r   c                 ó>   — t                                | ||¦  «         | S )aF	  Apply weight normalization to a parameter in the given module.

    .. math::
         \mathbf{w} = g \dfrac{\mathbf{v}}{\|\mathbf{v}\|}

    Weight normalization is a reparameterization that decouples the magnitude
    of a weight tensor from its direction. This replaces the parameter specified
    by :attr:`name` (e.g. ``'weight'``) with two parameters: one specifying the magnitude
    (e.g. ``'weight_g'``) and one specifying the direction (e.g. ``'weight_v'``).
    Weight normalization is implemented via a hook that recomputes the weight
    tensor from the magnitude and direction before every :meth:`~Module.forward`
    call.

    By default, with ``dim=0``, the norm is computed independently per output
    channel/plane. To compute a norm over the entire weight tensor, use
    ``dim=None``.

    See https://arxiv.org/abs/1602.07868

    .. warning::

        This function is deprecated.  Use :func:`torch.nn.utils.parametrizations.weight_norm`
        which uses the modern parametrization API.  The new ``weight_norm`` is compatible
        with ``state_dict`` generated from old ``weight_norm``.

        Migration guide:

        * The magnitude (``weight_g``) and direction (``weight_v``) are now expressed
          as ``parametrizations.weight.original0`` and ``parametrizations.weight.original1``
          respectively.  If this is bothering you, please comment on
          https://github.com/pytorch/pytorch/issues/102999

        * To remove the weight normalization reparameterization, use
          :func:`torch.nn.utils.parametrize.remove_parametrizations`.

        * The weight is no longer recomputed once at module forward; instead, it will
          be recomputed on every access.  To restore the old behavior, use
          :func:`torch.nn.utils.parametrize.cached` before invoking the module
          in question.

    Args:
        module (Module): containing module
        name (str, optional): name of weight parameter
        dim (int, optional): dimension over which to compute the norm

    Returns:
        The original module with the weight norm hook

    Example::

        >>> m = weight_norm(nn.Linear(20, 40), name='weight')
        >>> m
        Linear(in_features=20, out_features=40, bias=True)
        >>> m.weight_g.size()
        torch.Size([40, 1])
        >>> m.weight_v.size()
        torch.Size([40, 20])

    )r   r1   )r   r   r   s      r   r   r   T   s"   € õx ×Ò�V˜T 3Ñ'Ô'Ð'Ø€Mr   c                 óì   — | j                              ¦   «         D ]F\  }}t          |t          ¦  «        r,|j        |k    r!|                     | ¦  «         | j         |= | c S ŒGt          d|› d| › �¦  «        ‚)a  Remove the weight normalization reparameterization from a module.

    Args:
        module (Module): containing module
        name (str, optional): name of weight parameter

    Example:
        >>> m = weight_norm(nn.Linear(20, 40))
        >>> remove_weight_norm(m)
    zweight_norm of 'z' not found in )r$   Úitemsr&   r   r   r4   r(   )r   r   Úkr.   s       r   r   r   ”   sŠ   € ð Ô,×2Ò2Ñ4Ô4ð ð ‰ˆˆ4Ý�d�JÑ'Ô'ð 	¨D¬I¸Ò,=Ð,=Ø�KŠK˜ÑÔÐØÔ)¨!Ð,ØˆMˆMˆMøå
ÐE¨ÐEÐE¸VÐEÐEÑ
FÔ
FÐFr   N)r0   r   )r0   )Ú__doc__Útypingr   r   Útyping_extensionsr   Útorchr   r   Útorch.nn.modulesr   Útorch.nn.parameterr	   r
   Ú__all__r   rA   r;   r=   r   r   r@   r   r   ú<module>rN      sC  ðà BÐ Bà Ð Ð Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (à /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø #Ð #Ð #Ð #Ð #Ð #Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @ð >Ð
=Ð
=€ð?@ð ?@ð ?@ð ?@ð ?@ñ ?@ô ?@ð ?@ðD ˆ7�: VÐ,Ñ,Ô,€ð=ð =˜ð =¨ð =¸Sð =Èð =ð =ð =ð =ð@Gð G˜xð G¨sð GÀ(ð Gð Gð Gð Gð Gð Gr   