§
    �Štjág  ã                   ó  — d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 ddl
Z
ddl
mZ g d¢Z ed¦  «        Z e	d	¦  «        Zed
         Zed         Z	 d:dededede
j        dz  def
d„Z	 d:dededede
j        dz  def
d„Z	 d:dededededede
j        dz  defd„Zdededefd„Zdedefd„Z	 d:dedeez  dz  defd„Z	 	 	 d;dededede
j        dz  def
d„Z	 	 	 d;dededede
j        dz  def
d„Z	 	 	 	 	 d<dededededede
j        dz  defd"„Zdededefd#„Zdedefd$„Zdedefd%„Zdedefd&„Z d=ded(edefd)„Z!dede"eef         fd*„Z#	 	 d>ded+ede
j        dz  defd,„Z$	 	 d>ded+ede
j        dz  defd-„Z%ded.edefd/„Z&	 	 	 	 d?deded.edede
j        dz  defd2„Z'	 	 	 	 d?deded.edede
j        dz  defd3„Z(	 	 d@ded+ede
j        dz  defd4„Z)	 	 dAded6edede
j        dz  def
d7„Z*d8eeef         deeef         fd9„Z+ e+e¦  «        Z, e+e¦  «        Z- e+e¦  «        Z. e+e ¦  «        Z/ e+e!¦  «        Z0 e+e$¦  «        Z1 e+e%¦  «        Z2 e+e'¦  «        Z3 e+e(¦  «        Z4 e+e)¦  «        Z5 e+e*¦  «        Z6dS )BzHThis file contains utilities for initializing neural network parameters.é    N)ÚCallable)ÚLiteralÚTypeVar)Ú	ParamSpec)ÚTensor)Úcalculate_gainÚuniform_Únormal_Útrunc_normal_Ú	constant_Úones_Úzeros_Úeye_Údirac_Úxavier_uniform_Úxavier_normal_Úkaiming_uniform_Úkaiming_normal_Úorthogonal_Úsparse_ÚuniformÚnormalÚconstantÚeyeÚdiracÚxavier_uniformÚxavier_normalÚkaiming_uniformÚkaiming_normalÚ
orthogonalÚsparseÚ_RÚ_P)ÚlinearÚconv1dÚconv2dÚconv3dÚconv_transpose1dÚconv_transpose2dÚconv_transpose3dÚsigmoidÚtanhÚreluÚ
leaky_reluÚselu)Úfan_inÚfan_outÚtensorÚaÚbÚ	generatorÚreturnc                 óŒ   — t          j        ¦   «         5  |                      |||¬¦  «        cd d d ¦  «         S # 1 swxY w Y   d S ©N©r5   )ÚtorchÚno_gradr	   ©r2   r3   r4   r5   s       úK/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/nn/init.pyÚ_no_grad_uniform_r>   E   s‰   € õ 
Œ‰Œð :ð :Ø�Š˜q !¨yˆÑ9Ô9ð:ð :ð :ð :ñ :ô :ð :ð :ð :ð :ð :ð :øøøð :ð :ð :ð :ð :ð :ó   ”9¹=Á =ÚmeanÚstdc                 óŒ   — t          j        ¦   «         5  |                      |||¬¦  «        cd d d ¦  «         S # 1 swxY w Y   d S r8   )r:   r;   r
   ©r2   r@   rA   r5   s       r=   Ú_no_grad_normal_rD   L   s‰   € õ 
Œ‰Œð >ð >Ø�~Š~˜d C°9ˆ~Ñ=Ô=ð>ð >ð >ð >ñ >ô >ð >ð >ð >ð >ð >ð >øøøð >ð >ð >ð >ð >ð >r?   c           	      ó�  — | j         r| S dt          dt          fd„}||d|z  z
  k     s||d|z  z   k    rt          j        dd¬¦  «         t	          j        ¦   «         5   |||z
  |z  ¦  «         |||z
  |z  ¦  «        z
  }|dk    rç|                      |d¬	¦  «                             ¦   «         }|                      |d¬	¦  «                             ¦   «         }	|                      |||¬
¦  «        }
	 |
|k     |
|	k    z  }| 	                    ¦   «         sn?t	          j
        |t	          j        |
¦  «                             |||¬
¦  «        |
¦  «        }
Œa| |
ur|                      |
¦  «         �n?t          |t          ||¦  «        ¦  «        }d||z
  |z  dz  z  }t	          j        | ¦  «        }t	          j        | ¦  «        }|                      |||¬
¦  «         |                     | ¦  «         |                     |¦  «                             |¦  «                             d¦  «                             d¦  «                             |¦  «         |                     |¬
¦  «                             ¦   «                              |¦  «        }| 	                    ¦   «         s�n| }
	 |                     |||¬
¦  «         t	          j
        |||
¦  «        }
|                     |¦  «                             |¦  «                             d¦  «                             d¦  «                             |¦  «         t	          j
        ||                     |¬
¦  «                             ¦   «                              |¦  «        |¦  «        }| 	                    ¦   «         snŒô|                      |
¦  «         | cd d d ¦  «         S # 1 swxY w Y   d S )NÚxr6   c                 ó`   — dt          j        | t          j        d¦  «        z  ¦  «        z   dz  S )Nç      ð?ç       @)ÚmathÚerfÚsqrt)rF   s    r=   Únorm_cdfz(_no_grad_trunc_normal_.<locals>.norm_cdfb   s)   € Ø•d”h˜q¥4¤9¨S¡>¤>Ñ1Ñ2Ô2Ñ2°cÑ9Ð9ó    é   zjmean is more than 2 std from [a, b] in nn.init.trunc_normal_. The distribution of values may be incorrect.©Ú
stacklevelg333333Ó?Úcpu)Údevicer9   Tg      à¿)Úis_metaÚfloatÚwarningsÚwarnr:   r;   Ú
new_tensorÚitemr
   ÚanyÚwhereÚ
empty_likeÚcopy_ÚmaxÚminr	   Úsub_Údiv_Úpow_Úmul_Úlog_Úgt)r2   r@   rA   r3   r4   r5   rM   ÚpÚloÚhiÚresultÚmaskÚmodeÚlog_peakÚ
candidatesÚ
accept_bufÚpendings                    r=   Ú_no_grad_trunc_normal_rp   V   s  € ð „~ð Øˆð:•Eð :�eð :ð :ð :ð :ð 	ˆq�1�s‘7‰{ÒÐ  q¨1¨s©7¡{Ò 2Ð 2ÝŒð;àð	
ñ 	
ô 	
ð 	
õ 
Œ‰Œð 4ð 4ØˆH�a˜$‘h #Ñ%Ñ&Ô&¨¨°1°t±8¸sÑ2BÑ)CÔ)CÑCˆàˆsŠ7ˆ7ð ×"Ò" 1¨UÐ"Ñ3Ô3×8Ò8Ñ:Ô:ˆBØ×"Ò" 1¨UÐ"Ñ3Ô3×8Ò8Ñ:Ô:ˆBØ—^’^ D¨#¸�^ÑCÔCˆFðØ š¨°ªÑ4�Ø—x’x‘z”zð ØÝœØÝÔ$ VÑ,Ô,×4Ò4°T¸3È)Ð4ÑTÔTØñô �ð	ð ˜VÐ#Ð#Ø—’˜VÑ$Ô$Ð$ùå�q�#˜d A™,œ,Ñ'Ô'ˆDØ  t¡¨sÑ2°qÑ8Ñ8ˆHåÔ)¨&Ñ1Ô1ˆJÝÔ)¨&Ñ1Ô1ˆJð �OŠO˜A˜q¨IˆOÑ6Ô6Ð6Ø×Ò˜VÑ$Ô$Ð$à�OŠO˜DÑ!Ô!×&Ò& sÑ+Ô+×0Ò0°Ñ3Ô3×8Ò8¸Ñ>Ô>×CÒCÀHÑMÔMÐMØ ×)Ò)°IÐ)Ñ>Ô>×CÒCÑEÔE×HÒHÈÑTÔTˆGØ—;’;‘=”=ð %Ùà�ðØ×'Ò'¨¨1¸	Ð'ÑBÔBÐBÝ"œ[¨°*¸fÑEÔE�Fà—O’O DÑ)Ô)×.Ò.¨sÑ3Ô3×8Ò8¸Ñ;Ô;×@Ò@ÀÑFÔF×KÒKÈHÑUÔUÐUÝ#œkØØ"×+Ò+°iÐ+Ñ@Ô@×EÒEÑGÔG×JÒJÈ:ÑVÔVØñô �Gð
 #Ÿ;š;™=œ=ð Øðð —’˜VÑ$Ô$Ð$àði4ð 4ð 4ð 4ñ 4ô 4ð 4ð 4ð 4ð 4ð 4ð 4øøøð 4ð 4ð 4ð 4ð 4ð 4s   ÁMN;Î;N?ÏN?Úvalc                 ó†   — t          j        ¦   «         5  |                      |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S ©N)r:   r;   Úfill_©r2   rq   s     r=   Ú_no_grad_fill_rv   £   s�   € Ý	Œ‰Œð !ð !Ø�|Š|˜CÑ Ô ð!ð !ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !ð !ð !s   ”6¶:½:c                 ó„   — t          j        ¦   «         5  |                      ¦   «         cd d d ¦  «         S # 1 swxY w Y   d S rs   )r:   r;   Úzero_©r2   s    r=   Ú_no_grad_zero_rz   ¨   s}   € Ý	Œ‰Œð ð Ø�|Š|‰~Œ~ðð ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ð s   ”5µ9¼9ÚnonlinearityÚparamc                 ó–  — g d¢}| |v s| dk    rdS | dk    rdS | dk    rt          j        d¦  «        S | dk    rw|€d
}nUt          |t          ¦  «        st          |t          ¦  «        st          |t
          ¦  «        r|}nt          d|› d�¦  «        ‚t          j        dd|dz  z   z  ¦  «        S | dk    r	 dS t          d| › �¦  «        ‚)aÜ  Return the recommended gain value for the given nonlinearity function.

    The values are as follows:

    ================= ====================================================
    nonlinearity      gain
    ================= ====================================================
    Linear / Identity :math:`1`
    Conv{1,2,3}D      :math:`1`
    Sigmoid           :math:`1`
    Tanh              :math:`\frac{5}{3}`
    ReLU              :math:`\sqrt{2}`
    Leaky Relu        :math:`\sqrt{\frac{2}{1 + \text{negative\_slope}^2}}`
    SELU              :math:`\frac{3}{4}`
    ================= ====================================================

    .. warning::
        In order to implement `Self-Normalizing Neural Networks
        <https://papers.nips.cc/paper/2017/hash/5d44ee6f2c3f71b73125876103c8f6c4-Abstract.html>`__,
        you should use ``nonlinearity='linear'`` instead of ``nonlinearity='selu'``.
        This gives the initial weights a variance of ``1 / N``,
        which is necessary to induce a stable fixed point in the forward pass.
        In contrast, the default gain for ``SELU`` sacrifices the normalization
        effect for more stable gradient flow in rectangular layers.

    Args:
        nonlinearity: the non-linear function (`nn.functional` name)
        param: optional parameter for the non-linear function

    Examples:
        >>> gain = nn.init.calculate_gain(
        ...     "leaky_relu", 0.2
        ... )  # leaky_relu with negative_slope=0.2

    )r$   r%   r&   r'   r(   r)   r*   r+   é   r,   g«ªªªªªú?r-   rI   r.   Nç{®Gáz„?znegative_slope z not a valid numberrO   r/   g      è?zUnsupported nonlinearity )rJ   rL   Ú
isinstanceÚboolÚintrU   Ú
ValueError)r{   r|   Ú
linear_fnsÚnegative_slopes       r=   r   r   ­   s  € ðLð ð €Jð �zÐ!Ð! \°YÒ%>Ð%>ØˆqØ	˜Ò	Ð	ØˆwØ	˜Ò	Ð	ÝŒy˜‰~Œ~ÐØ	˜Ò	%Ð	%Øˆ=Ø!ˆNˆNå˜5¥$Ñ'Ô'ð	Kå˜5¥#Ñ&Ô&ð	Kõ ˜%¥Ñ'Ô'ð	Kð #ˆNˆNåÐI¨uÐIÐIÐIÑJÔJÐJÝŒy˜  N°AÑ$5Ñ 5Ñ6Ñ7Ô7Ð7Ø	˜Ò	Ð	àð	
ð 	
õ ÐC°\ÐCÐCÑDÔDÐDrN   ç        rH   c                 óº   — t           j                             | ¦  «        r+t           j                             t          | f| |||¬¦  «        S t          | |||¦  «        S )a«  Fill the input Tensor with values drawn from the uniform distribution.

    :math:`\mathcal{U}(a, b)`.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        a: the lower bound of the uniform distribution
        b: the upper bound of the uniform distribution
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.uniform_(w)
    r<   )r:   Ú	overridesÚhas_torch_function_variadicÚhandle_torch_functionr	   r>   r<   s       r=   r	   r	   ÷   s`   € õ( „×2Ò2°6Ñ:Ô:ð 
ÝŒ×4Ò4Ý�v�i¨°!°qÀIð 5ñ 
ô 
ð 	
õ ˜V Q¨¨9Ñ5Ô5Ð5rN   c                 óº   — t           j                             | ¦  «        r+t           j                             t          | f| |||¬¦  «        S t          | |||¦  «        S )aÁ  Fill the input Tensor with values drawn from the normal distribution.

    :math:`\mathcal{N}(\text{mean}, \text{std}^2)`.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        mean: the mean of the normal distribution
        std: the standard deviation of the normal distribution
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.normal_(w)
    rC   )r:   rˆ   r‰   rŠ   r
   rD   rC   s       r=   r
   r
     s`   € õ( „×2Ò2°6Ñ:Ô:ð 
ÝŒ×4Ò4Ý�f�Y v°D¸cÈYð 5ñ 
ô 
ð 	
õ ˜F D¨#¨yÑ9Ô9Ð9rN   ç       ÀrI   c                 ó,   — t          | |||||¬¦  «        S )a  Fill the input Tensor with values drawn from a truncated normal distribution.

    The values are effectively drawn from the
    normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)`
    with values outside :math:`[a, b]` redrawn until they are within
    the bounds. The method used for generating the random values works
    best when :math:`a \leq \text{mean} \leq b`.

    For reduced-precision types (``torch.float16`` and ``torch.bfloat16``),
    sampling quality depends on the underlying ``normal_()`` and ``uniform_()``
    implementations which operate at higher internal precision to avoid
    quantization artifacts.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        mean: the mean of the normal distribution
        std: the standard deviation of the normal distribution
        a: the minimum cutoff value
        b: the maximum cutoff value
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.trunc_normal_(w)
    r9   )rp   )r2   r@   rA   r3   r4   r5   s         r=   r   r   -  s    € õB " &¨$°°Q¸ÀYÐOÑOÔOÐOrN   c                 ó²   — t           j                             | ¦  «        r)t           j                             t          | f| |¬¦  «        S t          | |¦  «        S )zþFill the input Tensor with the value :math:`\text{val}`.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        val: the value to fill the tensor with

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.constant_(w, 0.3)
    ru   )r:   rˆ   r‰   rŠ   r   rv   ru   s     r=   r   r   Q  sX   € õ „×2Ò2°6Ñ:Ô:ð 
ÝŒ×4Ò4Ý˜�y¨°Sð 5ñ 
ô 
ð 	
õ ˜& #Ñ&Ô&Ð&rN   c                 ó"   — t          | d¦  «        S )z¾Fill the input Tensor with the scalar value `1`.

    Args:
        tensor: an n-dimensional `torch.Tensor`

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.ones_(w)
    rH   )rv   ry   s    r=   r   r   c  s   € õ ˜& #Ñ&Ô&Ð&rN   c                 ó    — t          | ¦  «        S )z¿Fill the input Tensor with the scalar value `0`.

    Args:
        tensor: an n-dimensional `torch.Tensor`

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.zeros_(w)
    )rz   ry   s    r=   r   r   p  s   € õ ˜&Ñ!Ô!Ð!rN   c                 óâ   — |                       ¦   «         dk    rt          d¦  «        ‚t          j        ¦   «         5  t          j        | j        | | j        dœŽ ddd¦  «         n# 1 swxY w Y   | S )a=  Fill the 2-dimensional input `Tensor` with the identity matrix.

    Preserves the identity of the inputs in `Linear` layers, where as
    many inputs are preserved as possible.

    Args:
        tensor: a 2-dimensional `torch.Tensor`

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.eye_(w)
    rO   ú,Only tensors with 2 dimensions are supported)ÚoutÚrequires_gradN)Ú
ndimensionrƒ   r:   r;   r   Úshaper”   ry   s    r=   r   r   }  s½   € ð ×ÒÑÔ˜aÒÐÝÐGÑHÔHÐHå	Œ‰Œð Qð QÝŒ	�6”< V¸6Ô;OÐPÐPÐPÐPðQð Qð Qñ Qô Qð Qð Qð Qð Qð Qð Qøøøð Qð Qð Qð Qà€Ms   »A$Á$A(Á+A(r~   Úgroupsc                 óR  — |                       ¦   «         }|dvrt          d¦  «        ‚|                      ¦   «         }|d         |z  dk    rt          d¦  «        ‚| j        r| S |d         |z  }t	          ||d         ¦  «        }t          j        ¦   «         5  |                      ¦   «          t          |¦  «        D ]Ó}t          |¦  «        D ]Á}|dk    r%d| ||z  |z   ||                      d¦  «        dz  f<   Œ-|dk    r<d| ||z  |z   ||                      d¦  «        dz  |                      d¦  «        dz  f<   Œod| ||z  |z   ||                      d¦  «        dz  |                      d¦  «        dz  |                      d¦  «        dz  f<   ŒÂŒÔ	 d	d	d	¦  «         n# 1 swxY w Y   | S )
aF  Fill the {3, 4, 5}-dimensional input `Tensor` with the Dirac delta function.

    Preserves the identity of the inputs in `Convolutional`
    layers, where as many input channels are preserved as possible. In case
    of groups>1, each group of channels preserves identity

    Args:
        tensor: a {3, 4, 5}-dimensional `torch.Tensor`
        groups (int, optional): number of groups in the conv layer (default: 1)
    Examples:
        >>> w = torch.empty(3, 16, 5, 5)
        >>> nn.init.dirac_(w)
        >>> w = torch.empty(3, 24, 5, 5)
        >>> nn.init.dirac_(w, 3)
    )é   é   é   z5Only tensors with 3, 4, or 5 dimensions are supportedr   z!dim 0 must be divisible by groupsr~   r™   rO   rš   N)	r•   rƒ   ÚsizerT   r_   r:   r;   rx   Úrange)r2   r—   Ú
dimensionsÚsizesÚout_chans_per_grpÚmin_dimÚgÚds           r=   r   r   ’  s(  € ð  ×"Ò"Ñ$Ô$€JØ˜Ð"Ð"ÝÐPÑQÔQÐQà�KŠK‰MŒM€EàˆQ„x�&Ñ˜AÒÐÝÐ<Ñ=Ô=Ð=à„~ð Øˆà˜aœ FÑ*ÐÝÐ# U¨1¤XÑ.Ô.€Gå	Œ‰Œð ð Ø�Š‰Œˆå�v‘”ð 	ð 	ˆAÝ˜7‘^”^ð ð �Ø ’?�?ØPQ�F˜1Ð0Ñ0°1Ñ4°a¸¿ºÀQ¹¼È1Ñ9LÐLÑMÐMØ 1’_�_ð ð ØÐ-Ñ-°Ñ1ØØŸš A™œ¨!Ñ+ØŸš A™œ¨!Ñ+ð-ñð ð ð ØÐ-Ñ-°Ñ1ØØŸš A™œ¨!Ñ+ØŸš A™œ¨!Ñ+ØŸš A™œ¨!Ñ+ð	-ñð ðð	ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð, €Ms   ÂC8FÆF Æ#F c                 ó&  — |                       ¦   «         }|dk     rt          d¦  «        ‚|                      d¦  «        }|                      d¦  «        }d}|                       ¦   «         dk    r| j        dd …         D ]}||z  }Œ||z  }||z  }||fS )NrO   zNFan in and fan out can not be computed for tensor with fewer than 2 dimensionsr~   r   )Údimrƒ   rœ   r–   )r2   rž   Únum_input_fmapsÚnum_output_fmapsÚreceptive_field_sizeÚsr0   r1   s           r=   Ú_calculate_fan_in_and_fan_outrª   Ê  s±   € Ø—’‘”€JØ�A‚~€~ÝØ\ñ
ô 
ð 	
ð —k’k !‘n”n€OØ—{’{ 1‘~”~ÐØÐØ‡z‚z�|„|�aÒÐð ”˜a˜b˜bÔ!ð 	&ð 	&ˆAØ  AÑ%Ð Ð ØÐ3Ñ3€FØÐ!5Ñ5€Gà�7ˆ?ÐrN   Úgainc                 óÎ   — t          | ¦  «        \  }}|t          j        dt          ||z   ¦  «        z  ¦  «        z  }t          j        d¦  «        |z  }t	          | | ||¦  «        S )aì  Fill the input `Tensor` with values using a Xavier uniform distribution.

    The method is described in `Understanding the difficulty of training
    deep feedforward neural networks` - Glorot, X. & Bengio, Y. (2010).
    The resulting tensor will have values sampled from
    :math:`\mathcal{U}(-a, a)` where

    .. math::
        a = \text{gain} \times \sqrt{\frac{6}{\text{fan\_in} + \text{fan\_out}}}

    Also known as Glorot initialization.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        gain: an optional scaling factor
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain("relu"))
    rI   ç      @)rª   rJ   rL   rU   r>   )r2   r«   r5   r0   r1   rA   r3   s          r=   r   r   ß  sc   € õ4 4°FÑ;Ô;�O€FˆGØ
•”˜3¥ v°Ñ'7Ñ!8Ô!8Ñ8Ñ9Ô9Ñ
9€CÝŒ	�#‰Œ˜Ñ€Aå˜V a R¨¨IÑ6Ô6Ð6rN   c                 óž   — t          | ¦  «        \  }}|t          j        dt          ||z   ¦  «        z  ¦  «        z  }t	          | d||¦  «        S )aÔ  Fill the input `Tensor` with values using a Xavier normal distribution.

    The method is described in `Understanding the difficulty of training deep feedforward
    neural networks` - Glorot, X. & Bengio, Y. (2010). The resulting tensor
    will have values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where

    .. math::
        \text{std} = \text{gain} \times \sqrt{\frac{2}{\text{fan\_in} + \text{fan\_out}}}

    Also known as Glorot initialization.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        gain: an optional scaling factor
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.xavier_normal_(w)
    rI   r†   )rª   rJ   rL   rU   rD   )r2   r«   r5   r0   r1   rA   s         r=   r   r      sO   € õ2 4°FÑ;Ô;�O€FˆGØ
•”˜3¥ v°Ñ'7Ñ!8Ô!8Ñ8Ñ9Ô9Ñ
9€Cå˜F C¨¨iÑ8Ô8Ð8rN   rk   c                 óœ   — |                      ¦   «         }ddg}||vrt          d|› d|› �¦  «        ‚t          | ¦  «        \  }}|dk    r|n|S )Nr0   r1   zMode z" not supported, please use one of )Úlowerrƒ   rª   )r2   rk   Úvalid_modesr0   r1   s        r=   Ú_calculate_correct_fanr²     sh   € à�:Š:‰<Œ<€DØ˜YÐ'€KØ�;ÐÐÝÐV ÐVÐVÈÐVÐVÑWÔWÐWå3°FÑ;Ô;�O€FˆGØ˜XÒ%Ð%ˆ6ˆ6¨7Ð2rN   r0   r.   c           	      ó  — t           j                             | ¦  «        r,t           j                             t          | f| ||||¬¦  «        S d| j        v rt          j        dd¬¦  «         | S t          | |¦  «        }t          ||¦  «        }|t          j        |¦  «        z  }t          j        d¦  «        |z  }t          j        ¦   «         5  |                      | ||¬¦  «        cddd¦  «         S # 1 swxY w Y   dS )	a¸  Fill the input `Tensor` with values using a Kaiming uniform distribution.

    The method is described in `Delving deep into rectifiers: Surpassing
    human-level performance on ImageNet classification` - He, K. et al. (2015).
    The resulting tensor will have values sampled from
    :math:`\mathcal{U}(-\text{bound}, \text{bound})` where

    .. math::
        \text{bound} = \text{gain} \times \sqrt{\frac{3}{\text{fan\_mode}}}

    Also known as He initialization.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        a: the negative slope of the rectifier used after this layer (only
            used with ``'leaky_relu'``)
        mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'``
            preserves the magnitude of the variance of the weights in the
            forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the
            backwards pass.
        nonlinearity: the non-linear function (`nn.functional` name),
            recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default).
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.kaiming_uniform_(w, mode="fan_in", nonlinearity="relu")

    Note:
        Be aware that ``fan_in`` and ``fan_out`` are calculated assuming
        that the weight matrix is used in a transposed manner,
        (i.e., ``x @ w.T`` in ``Linear`` layers, where ``w.shape = [fan_out, fan_in]``).
        This is important for correct initialization.
        If you plan to use ``x @ w``, where ``w.shape = [fan_in, fan_out]``,
        pass in a transposed weight matrix, i.e. ``nn.init.kaiming_uniform_(w.T, ...)``.
    )r2   r3   rk   r{   r5   r   ú,Initializing zero-element tensors is a no-oprO   rP   r­   r9   N)r:   rˆ   r‰   rŠ   r   r–   rV   rW   r²   r   rJ   rL   r;   r	   )	r2   r3   rk   r{   r5   Úfanr«   rA   Úbounds	            r=   r   r   *  s[  € õV „×2Ò2°6Ñ:Ô:ð 	
ÝŒ×4Ò4ÝØˆIØØØØ%Øð 5ñ 
ô 
ð 	
ð 	ˆFŒLÐÐÝŒÐDÐQRÐSÑSÔSÐSØˆÝ
  ¨Ñ
.Ô
.€CÝ˜,¨Ñ*Ô*€DØ
•”˜3‘”Ñ
€CÝŒI�c‰NŒN˜SÑ €EÝ	Œ‰Œð Cð CØ�Š ˜v u¸	ˆÑBÔBðCð Cð Cð Cñ Cô Cð Cð Cð Cð Cð Cð Cøøøð Cð Cð Cð Cð Cð Cs   ÃC4Ã4C8Ã;C8c                 ó<  — d| j         v rt          j        dd¬¦  «         | S t          | |¦  «        }t	          ||¦  «        }|t          j        |¦  «        z  }t          j        ¦   «         5  |  	                    d||¬¦  «        cddd¦  «         S # 1 swxY w Y   dS )aŸ  Fill the input `Tensor` with values using a Kaiming normal distribution.

    The method is described in `Delving deep into rectifiers: Surpassing
    human-level performance on ImageNet classification` - He, K. et al. (2015).
    The resulting tensor will have values sampled from
    :math:`\mathcal{N}(0, \text{std}^2)` where

    .. math::
        \text{std} = \frac{\text{gain}}{\sqrt{\text{fan\_mode}}}

    Also known as He initialization.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        a: the negative slope of the rectifier used after this layer (only
            used with ``'leaky_relu'``)
        mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'``
            preserves the magnitude of the variance of the weights in the
            forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the
            backwards pass.
        nonlinearity: the non-linear function (`nn.functional` name),
            recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default).
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.kaiming_normal_(w, mode="fan_out", nonlinearity="relu")

    Note:
        Be aware that ``fan_in`` and ``fan_out`` are calculated assuming
        that the weight matrix is used in a transposed manner,
        (i.e., ``x @ w.T`` in ``Linear`` layers, where ``w.shape = [fan_out, fan_in]``).
        This is important for correct initialization.
        If you plan to use ``x @ w``, where ``w.shape = [fan_in, fan_out]``,
        pass in a transposed weight matrix, i.e. ``nn.init.kaiming_normal_(w.T, ...)``.
    r   r´   rO   rP   r9   N)
r–   rV   rW   r²   r   rJ   rL   r:   r;   r
   )r2   r3   rk   r{   r5   rµ   r«   rA   s           r=   r   r   k  sã   € ðV 	ˆFŒLÐÐÝŒÐDÐQRÐSÑSÔSÐSØˆÝ
  ¨Ñ
.Ô
.€CÝ˜,¨Ñ*Ô*€DØ
•”˜3‘”Ñ
€CÝ	Œ‰Œð ;ð ;Ø�~Š~˜a °	ˆ~Ñ:Ô:ð;ð ;ð ;ð ;ñ ;ô ;ð ;ð ;ð ;ð ;ð ;ð ;øøøð ;ð ;ð ;ð ;ð ;ð ;s   Á,BÂBÂBc                 ó   — |                       ¦   «         dk     rt          d¦  «        ‚|                      ¦   «         dk    s| j        r| S |                      d¦  «        }|                      ¦   «         |z  }|                      ||f¦  «                             dd|¬¦  «        }||k     r|                     ¦   «          t          j	         
                    |¦  «        \  }}t          j        |d¦  «        }|                     ¦   «         }	||	z  }||k     r|                     ¦   «          t          j        ¦   «         5  |                      |¦  «                             |¦  «         |                      |¦  «         ddd¦  «         n# 1 swxY w Y   | S )a   Fill the input `Tensor` with a (semi) orthogonal matrix.

    Described in `Exact solutions to the nonlinear dynamics of learning in deep
    linear neural networks` - Saxe, A. et al. (2013). The input tensor must have
    at least 2 dimensions, and for tensors with more than 2 dimensions the
    trailing dimensions are flattened.

    Args:
        tensor: an n-dimensional `torch.Tensor`, where :math:`n \geq 2`
        gain: optional scaling factor
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
        >>> w = torch.empty(3, 5)
        >>> nn.init.orthogonal_(w)
    rO   z4Only tensors with 2 or more dimensions are supportedr   r~   r9   N)r•   rƒ   ÚnumelrT   rœ   Ú	new_emptyr
   Út_r:   ÚlinalgÚqrÚdiagÚsignr;   Úview_asr]   rc   )
r2   r«   r5   ÚrowsÚcolsÚ	flattenedÚqÚrr£   Úphs
             r=   r   r      sœ  € ð, ×ÒÑÔ˜QÒÐÝÐOÑPÔPÐPà‡|‚|�~„~˜ÒÐ˜fœnÐàˆØ�;Š;�q‰>Œ>€DØ�<Š<‰>Œ>˜TÑ!€DØ× Ò  $¨ Ñ.Ô.×6Ò6°q¸!ÀyÐ6ÑQÔQ€Iàˆd‚{€{Ø�Š‰Œˆõ Œ<�?Š?˜9Ñ%Ô%�D€A€qåŒ
�1�aÑÔ€AØ	
�Š‰Œ€BØˆ�G€Aàˆd‚{€{Ø	�Š‰Œˆå	Œ‰Œð ð Ø�Š�qÑÔ×Ò Ñ"Ô"Ð"Ø�Š�DÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð €Ms   Ä9>FÆFÆ
Fr   Úsparsityc                 óž  — |                       ¦   «         dk    rt          d¦  «        ‚| j        r| S | j        \  }}t	          j        ||z  ¦  «        }t          j        ¦   «         5  |                      d||¬¦  «         t          |¦  «        D ]'}t          j
        |¦  «        }|d|…         }	d| |	|f<   Œ(	 ddd¦  «         n# 1 swxY w Y   | S )aŽ  Fill the 2D input `Tensor` as a sparse matrix.

    The non-zero elements will be drawn from the normal distribution
    :math:`\mathcal{N}(0, 0.01)`, as described in `Deep learning via
    Hessian-free optimization` - Martens, J. (2010).

    Args:
        tensor: an n-dimensional `torch.Tensor`
        sparsity: The fraction of elements in each column to be set to zero
        std: the standard deviation of the normal distribution used to generate
            the non-zero values
        generator: the torch Generator to sample from (default: None)

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.sparse_(w, sparsity=0.1)
    rO   r’   r   r9   N)r•   rƒ   rT   r–   rJ   Úceilr:   r;   r
   r�   Úrandperm)
r2   rÇ   rA   r5   rÁ   rÂ   Ú	num_zerosÚcol_idxÚrow_indicesÚzero_indicess
             r=   r   r   Ó  s   € ð. ×ÒÑÔ˜aÒÐÝÐGÑHÔHÐHà„~ð Øˆà”�J€Dˆ$Ý”	˜( T™/Ñ*Ô*€Iå	Œ‰Œð .ð .Ø�Š�q˜#¨ˆÑ3Ô3Ð3Ý˜T‘{”{ð 	.ð 	.ˆGÝœ.¨Ñ.Ô.ˆKØ& z¨	 zÔ2ˆLØ,-ˆF�< Ð(Ñ)Ð)ð	.ð.ð .ð .ñ .ô .ð .ð .ð .ð .ð .ð .øøøð .ð .ð .ð .ð €Ms   Á%ACÃCÃ	CÚmethc                 ó¬   ‡ ‡‡— ‰ j         Š‰d d…         Šdt          j        dt          j        dt          fˆ ˆˆfd„}d‰› d‰› d‰› d	�|_        ‰|_         |S )
NéÿÿÿÿÚargsÚkwargsr6   c                  óZ   •— t          j        d‰› d‰› d�t          d¬¦  «          ‰| i |¤ŽS )Nz	`nn.init.z)` is now deprecated in favor of `nn.init.z`.rO   rP   )rV   rW   ÚFutureWarning)rÒ   rÓ   rÏ   Únew_nameÚold_names     €€€r=   Údeprecated_initz(_make_deprecate.<locals>.deprecated_init  sO   ø€ ÝŒØW˜ÐWÐWÈ8ÐWÐWÐWÝØð	
ñ 	
ô 	
ð 	
ð
 ˆt�TÐ$˜VÐ$Ð$Ð$rN   z
    z_(...)

    .. warning::
        This method is now deprecated in favor of :func:`torch.nn.init.z"`.

    See :func:`~torch.nn.init.z` for details.)Ú__name__r#   rÒ   rÓ   r"   Ú__doc__)rÏ   rØ   rÖ   r×   s   ` @@r=   Ú_make_deprecaterÛ   ý  s¦   øøø€ ØŒ}€HØ˜˜˜Œ}€Hð%�rœwð %µ"´)ð %Åð %ð %ð %ð %ð %ð %ð %ð %ð:Øð:ð :ð IQð	:ð :ð  (ð:ð :ð :€OÔð  (€OÔØÐrN   rs   )r†   rH   N)r†   rH   rŒ   rI   N)r~   )rH   N)r   r0   r.   N)r~   N)r   N)7rÚ   rJ   rV   Úcollections.abcr   Útypingr   r   Útyping_extensionsr   r:   r   Ú__all__r"   r#   Ú_NonlinearityTypeÚ_FanModerU   Ú	Generatorr>   rD   rp   rv   rz   r‚   r   r	   r
   r   r   r   r   r   r   Útuplerª   r   r   r²   r   r   r   r   rÛ   r   r   r   r   r   r   r   r   r   r    r!   © rN   r=   ú<module>rå      sª  ðØ NÐ Nà €€€Ø €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø Ð Ð Ð Ð Ð ðð ð €ð> €WˆT�]„]€Ø€Yˆt�_„_€àðôÐ ð Ð&Ô'€ð MQð:ð :Øð:Øð:Ø!&ð:Ø38´?ÀTÑ3Ið:àð:ð :ð :ð :ð )-ð	>ð >Øð>à
ð>ð 
ð>ð Œ Ñ%ð	>ð
 ð>ð >ð >ð >ð  )-ðJð JØðJà
ðJð 
ðJð ð	Jð
 ðJð Œ Ñ%ðJð ðJð Jð Jð JðZ!˜6ð !¨ð !°&ð !ð !ð !ð !ð
˜6ð  fð ð ð ð ð BFðGEð GEØ#ðGEØ,/°%©K¸$Ñ,>ðGEà
ðGEð GEð GEð GEðX ØØ(,ð	6ð 6Øð6àð6ð ð6ð Œ Ñ%ð	6ð
 ð6ð 6ð 6ð 6ð: ØØ(,ð	:ð :Øð:à
ð:ð 
ð:ð Œ Ñ%ð	:ð
 ð:ð :ð :ð :ð: ØØØØ(,ð!Pð !PØð!Pà
ð!Pð 
ð!Pð ð	!Pð
 ð!Pð Œ Ñ%ð!Pð ð!Pð !Pð !Pð !PðH'�fð ' 5ð '¨Vð 'ð 'ð 'ð 'ð$
'�&ð 
'˜Vð 
'ð 
'ð 
'ð 
'ð
"�6ð 
"˜fð 
"ð 
"ð 
"ð 
"ð�ð ˜Fð ð ð ð ð*5ð 5�6ð 5 3ð 5¨vð 5ð 5ð 5ð 5ðp¨&ð °U¸3À¸8´_ð ð ð ð ð. Ø(,ð7ð 7Øð7à
ð7ð Œ Ñ%ð7ð ð	7ð 7ð 7ð 7ðF Ø(,ð9ð 9Øð9à
ð9ð Œ Ñ%ð9ð ð	9ð 9ð 9ð 9ð>3 6ð 3°ð 3¸cð 3ð 3ð 3ð 3ð ØØ&2Ø(,ð>Cð >CØð>Càð>Cð ð>Cð $ð	>Cð
 Œ Ñ%ð>Cð ð>Cð >Cð >Cð >CðF ØØ&2Ø(,ð2;ð 2;Øð2;àð2;ð ð2;ð $ð	2;ð
 Œ Ñ%ð2;ð ð2;ð 2;ð 2;ð 2;ðn Ø(,ð0ð 0Øð0à
ð0ð Œ Ñ%ð0ð ð	0ð 0ð 0ð 0ðl Ø(,ð	&ð &Øð&àð&ð 
ð&ð Œ Ñ%ð	&ð
 ð&ð &ð &ð &ðT˜( 2 r 6Ô*ð ¨x¸¸B¸Ô/?ð ð ð ð ð. ˆ/˜(Ñ
#Ô
#€Ø	ˆ˜Ñ	!Ô	!€Øˆ?˜9Ñ%Ô%€Ø€o�dÑÔ€Øˆ˜ÑÔ€Ø � Ñ1Ô1€Ø� Ñ/Ô/€Ø!�/Ð"2Ñ3Ô3€Ø � Ñ1Ô1€Øˆ_˜[Ñ)Ô)€
Ø	ˆ˜Ñ	!Ô	!€€€rN   