ó
    !Eñiû  ã            	       ó²   • S r SSKJrJr  SSKJr  SSKJrJr  SSK	J
r
  SSKJrJr  / SQr " S S	5      r\" S
\
S9rSS\S\S\S\4S jjrSS\S\S\4S jjrg)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                   ó®   • \ rS rSr% \\S'   \\S'   S\S\SS4S jrS\S\	4S jr
\\" S	\S
9S\S\SS 4S j5       5       rS\SS4S jrS\S\	SS4S jrSrg)r   é   ÚnameÚdimÚreturnNc                 ó&   • Uc  SnXl         X l        g )Néÿÿÿÿ)r   r   )Úselfr   r   s      ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/nn/utils/weight_norm.pyÚ__init__ÚWeightNorm.__init__   s   € Ø‰;ØˆCØŒ	Ø�ó    Úmodulec                 óŽ   • [        XR                  S-   5      n[        XR                  S-   5      n[        X2U R                  5      $ ©NÚ_gÚ_v)Úgetattrr   r   r   )r   r   ÚgÚvs       r   Úcompute_weightÚWeightNorm.compute_weight   s9   € Ü�FŸI™I¨Ñ,Ó-ˆÜ�FŸI™I¨Ñ,Ó-ˆÜ˜A $§(¡(Ó+Ð+r   ze`torch.nn.utils.weight_norm` is deprecated in favor of `torch.nn.utils.parametrizations.weight_norm`.)Úcategoryc           
      óP  • U R                   R                  5        H8  n[        U[        5      (       d  M  UR                  U:X  d  M,  [        SU 35      e   Uc  Sn[        X5      n[        X5      n[        U[        5      (       a  [        S5      eU R                  U	 U R                  US-   [        [        USU5      R                  5      5        U R                  US-   [        UR                  5      5        [        XUR                  U 5      5        U R!                  U5        U$ )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   ÚapplyÚWeightNorm.apply   s  € ð ×-Ñ-×4Ñ4Ö6ˆDÜ˜$¤
×+Ó+°·	±	¸TÕ0AÜ"ØRÐSWÐRXÐYóð ñ 7ð ‰;ØˆCä˜Ó"ˆä˜Ó&ˆÜ�fÔ4×5Ñ5ÜðZóð ð
 ×Ñ˜tÐ$ð 	×!Ñ!Ø�4‰Kœ¤?°6¸1¸cÓ#B×#GÑ#GÓHô	
ð 	×!Ñ! $¨¡+¬y¸¿¹Ó/EÔFÜ�˜b×/Ñ/°Ó7Ô8ð 	×(Ñ(¨Ô,àˆ	r   c                 ó
  • U R                  U5      n[        XR                  5        UR                  U R                  S-   	 UR                  U R                  S-   	 [	        XR                  [        UR                  5      5        g r   )r"   Údelattrr   r,   r/   r	   r.   )r   r   r3   s      r   ÚremoveÚWeightNorm.removeF   sc   € Ø×$Ñ$ VÓ,ˆÜ�Ÿ	™	Ô"Ø×Ñ˜tŸy™y¨4Ñ/Ð0Ø×Ñ˜tŸy™y¨4Ñ/Ð0Ü�Ÿ	™	¤9¨V¯[©[Ó#9Õ:r   Úinputsc                 óN   • [        XR                  U R                  U5      5        g )N)r/   r   r"   )r   r   r:   s      r   Ú__call__ÚWeightNorm.__call__M   s   € Ü�Ÿ	™	 4×#6Ñ#6°vÓ#>Õ?r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚstrÚ__annotations__Úintr   r   r   r"   Ústaticmethodr   ÚFutureWarningr4   r8   r<   Ú__static_attributes__© r   r   r   r      sª   ‡ Ø
ƒIØ	ƒHð˜Sð  sð ¨tô ð, Vð ,°ô ,ð
 Ùð	Eàñð
˜Cð  cð ¨ló óó ððB;˜Vð ;¨ô ;ð@˜vð @¨sð @°t÷ @r   r   ÚT_module)Úboundr   r   r   r   c                 ó2   • [         R                  XU5        U $ )aš  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   r4   )r   r   r   s      r   r   r   T   s   € ôx ×Ñ�V 3Ô'Ø€Mr   c                 óü   • U R                   R                  5        HN  u  p#[        U[        5      (       d  M  UR                  U:X  d  M.  UR                  U 5        U R                   U	 U s  $    [        SU SU  35      e)zö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   r8   r+   )r   r   Úkr1   s       r   r   r   ”   sq   € ð ×,Ñ,×2Ñ2Ö4‰ˆÜ�dœJ×'Ó'¨D¯I©I¸Õ,=Ø�K‰K˜ÔØ×)Ñ)¨!Ð,ØŠMñ	 5ô Ð'¨ v¨_¸V¸HÐEÓ
FÐFr   N)r3   r   )r3   )Ú__doc__Útypingr   r   Útyping_extensionsr   Útorchr   r   Útorch.nn.modulesr   Útorch.nn.parameterr	   r
   Ú__all__r   rI   rB   rD   r   r   rH   r   r   Ú<module>rV      sy   ðá Bç Ý (ç /Ý #ß @ò >€÷?@ñ ?@ñD �: VÑ,€ñ=˜ð =¨ð =¸Sð =Èõ =ñ@G˜xð G¨sð GÀ(ö Gr   