Ë
    úÍ:j�d  ã                   ó   — d Z ddlZddlZddlmZmZmZ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	 d1dedededeej(                     def
d„Z	 d1dedededeej(                     def
d„Z	 d1dedededededeej(                     defd„Zdededefd„Zdedefd„Z	 d1dedee	eef      defd„Z	 	 	 d2dedededeej(                     def
d„Z	 	 	 d2dedededeej(                     def
d„Z	 	 	 	 	 d3dedededededeej(                     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"d4ded"edefd#„Z#dede$eef   fd$„Z%	 	 d5ded%edeej(                     defd&„Z&	 	 d5ded%edeej(                     defd'„Z'ded(edefd)„Z(	 	 	 	 d6deded(ededeej(                     defd*„Z)	 	 	 	 d6deded(ededeej(                     defd+„Z*	 	 d7ded%edeej(                     defd,„Z+	 	 d8ded-ededeej(                     def
d.„Z,d/eeef   deeef   fd0„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*«      Z6 e-e+«      Z7 e-e,«      Z8y)9zHThis file contains utilities for initializing neural network parameters.é    N)ÚCallableÚLiteralÚOptionalÚTypeVarÚUnion)Ú	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  | j                  |||¬«      cd d d «       S # 1 sw Y   y xY w©N©r7   )ÚtorchÚno_gradr   ©r4   r5   r6   r7   s       úb/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torch/nn/init.pyÚ_no_grad_uniform_r@   D   s4   € ô 
�‰‹ñ :Ø�‰˜q !¨yˆÓ9÷:÷ :ò :úó   •3³<ÚmeanÚstdc                 ó~   — t        j                  «       5  | j                  |||¬«      cd d d «       S # 1 sw Y   y xY wr:   )r<   r=   r   ©r4   rB   rC   r7   s       r?   Ú_no_grad_normal_rF   K   s4   € ô 
�‰‹ñ >Ø�~‰~˜d C°9ˆ~Ó=÷>÷ >ò >úrA   c                 ó  — dt         dt         fd„}||d|z  z
  k  s||d|z  z   kD  rt        j                  dd¬«       t        j                  «       5   |||z
  |z  «      } |||z
  |z  «      }| j                  d|z  dz
  d|z  dz
  |¬«       | j                  «        | j                  |t        j                  d	«      z  «       | j                  |«       | j                  ||¬
«       | cd d d «       S # 1 sw Y   y xY w)NÚxr8   c                 ód   — dt        j                  | t        j                  d«      z  «      z   dz  S )Nç      ð?ç       @)ÚmathÚerfÚsqrt)rH   s    r?   Únorm_cdfz(_no_grad_trunc_normal_.<locals>.norm_cdf^   s(   € à”d—h‘h˜q¤4§9¡9¨S£>Ñ1Ó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.©Ú
stacklevelé   r;   rK   )ÚminÚmax)ÚfloatÚwarningsÚwarnr<   r=   r   Úerfinv_Úmul_rL   rN   Úadd_Úclamp_)	r4   rB   rC   r5   r6   r7   rO   ÚlÚus	            r?   Ú_no_grad_trunc_normal_r`   U   sþ   € ð:”Eð :œeó :ð 	ˆq�1�s‘7‰{Ò  q¨1¨s©7¡{Ò 2Ü�‰ð;àõ	
ô 
�‰‹ñ ñ �a˜$‘h #Ñ%Ó&ˆÙ�a˜$‘h #Ñ%Ó&ˆð 	�‰˜˜A™ ™	 1 q¡5¨1¡9¸	ˆÔBð 	�‰Ôð 	�‰�Cœ$Ÿ)™) C›.Ñ(Ô)Ø�‰�DÔð 	�‰˜! ˆÔ#Ø÷+÷ ò ús   ÁBC5Ã5C>Úvalc                 óx   — t        j                  «       5  | j                  |«      cd d d «       S # 1 sw Y   y xY w©N)r<   r=   Úfill_©r4   ra   s     r?   Ú_no_grad_fill_rf   �   s,   € Ü	�‰‹ñ !Ø�|‰|˜CÓ ÷!÷ !ò !ús   •0°9c                 óv   — t        j                  «       5  | j                  «       cd d d «       S # 1 sw Y   y xY wrc   )r<   r=   Úzero_©r4   s    r?   Ú_no_grad_zero_rj   †   s)   € Ü	�‰‹ñ Ø�|‰|‹~÷÷ ò ús   •/¯8ÚnonlinearityÚparamc                 ó\  — g d¢}| |v s| dk(  ry| dk(  ry| dk(  rt        j                  d«      S | dk(  re|€d	}nBt        |t        «      st        |t        «      st        |t
        «      r|}nt        d
|› d�«      ‚t        j                  dd|dz  z   z  «      S | dk(  r	 y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`_ ,
        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

    .. _Self-Normalizing Neural Networks: https://papers.nips.cc/paper/2017/hash/5d44ee6f2c3f71b73125876103c8f6c4-Abstract.html
    )r&   r'   r(   r)   r*   r+   r,   r-   rT   r.   g«ªªªªªú?r/   rK   r0   ç{®Gáz„?znegative_slope z not a valid numberrQ   r1   g      è?zUnsupported nonlinearity )rL   rN   Ú
isinstanceÚboolÚintrW   Ú
ValueError)rk   rl   Ú
linear_fnsÚnegative_slopes       r?   r
   r
   ‹   sÎ   € òL€Jð �zÑ! \°YÒ%>ØØ	˜Ò	ØØ	˜Ò	Ü�y‰y˜‹~ÐØ	˜Ò	%Øˆ=Ø!‰Nä˜5¤$Ô'Ü˜5¤#Ô&Ü˜%¤Ô'ð #‰Nä˜¨u¨gÐ5HÐIÓJÐJÜ�y‰y˜  N°AÑ$5Ñ 5Ñ6Ó7Ð7Ø	˜Ò	àð	
ô Ð4°\°NÐCÓDÐDrP   c                 ó°   — t         j                  j                  | «      r*t         j                  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   Õ   sT   € ô( ‡�×2Ñ2°6Ô:Ü�‰×4Ñ4Ü�v�i¨°!°qÀIð 5ó 
ð 	
ô ˜V Q¨¨9Ó5Ð5rP   c                 ó°   — t         j                  j                  | «      r*t         j                  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)
    rE   )r<   rv   rw   rx   r   rF   rE   s       r?   r   r   ð   sT   € ô( ‡�×2Ñ2°6Ô:Ü�‰×4Ñ4Ü�f�Y v°D¸cÈYð 5ó 
ð 	
ô ˜F D¨#¨yÓ9Ð9rP   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`.

    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)
    r;   )r`   )r4   rB   rC   r5   r6   r7   s         r?   r   r     s   € ô8 " &¨$°°Q¸ÀYÔOÐOrP   c                 ó¨   — t         j                  j                  | «      r(t         j                  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)
    re   )r<   rv   rw   rx   r   rf   re   s     r?   r   r   *  sL   € ô ‡�×2Ñ2°6Ô:Ü�‰×4Ñ4Ü˜�y¨°Sð 5ó 
ð 	
ô ˜& #Ó&Ð&rP   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)
    rJ   )rf   ri   s    r?   r   r   <  s   € ô ˜& #Ó&Ð&rP   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)
    )rj   ri   s    r?   r   r   I  s   € ô ˜&Ó!Ð!rP   c                 óê   — | j                  «       dk7  rt        d«      ‚t        j                  «       5  t        j                  | j
                  | | j                  dœŽ ddd«       | S # 1 sw Y   | S xY w)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)
    rQ   ú,Only tensors with 2 dimensions are supported)ÚoutÚrequires_gradN)Ú
ndimensionrr   r<   r=   r   Úshaper�   ri   s    r?   r   r   V  sa   € ð ×ÑÓ˜aÒÜÐGÓHÐHä	�‰‹ñ QÜ�	‰	�6—<‘< V¸6×;OÑ;OÓP÷Qà€M÷Qà€Mús   ³+A(Á(A2Úgroupsc                 ó¾  — | j                  «       }|dvrt        d«      ‚| j                  «       }|d   |z  dk7  rt        d«      ‚|d   |z  }t        ||d   «      }t	        j
                  «       5  | j                  «        t        |«      D ]·  }t        |«      D ]§  }|dk(  r!d| ||z  |z   || j                  d«      dz  f<   Œ)|dk(  r4d| ||z  |z   || j                  d«      dz  | j                  d«      dz  f<   Œbd| ||z  |z   || j                  d«      dz  | j                  d«      dz  | j                  d«      dz  f<   Œ© Œ¹ 	 d	d	d	«       | S # 1 sw Y   | S xY w)
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 groupsrT   r†   rQ   r‡   N)r‚   rr   ÚsizerU   r<   r=   rh   Úrange)r4   r„   Ú
dimensionsÚsizesÚout_chans_per_grpÚmin_dimÚgÚds           r?   r   r   k  s•  € ð  ×"Ñ"Ó$€JØ˜Ñ"ÜÐPÓQÐQà�K‰K‹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Ø 1’_ð ð ØÐ-Ñ-°Ñ1ØØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ð-òð ð ØÐ-Ñ-°Ñ1ØØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ð	-òññ	÷ð, €M÷-ð, €Mús   Á1CEÅEc                 óþ   — | j                  «       }|dk  rt        d«      ‚| j                  d«      }| j                  d«      }d}| j                  «       dkD  r| j                  dd  D ]  }||z  }Œ	 ||z  }||z  }||fS )NrQ   zNFan in and fan out can not be computed for tensor with fewer than 2 dimensionsrT   r   )Údimrr   r‰   rƒ   )r4   r‹   Únum_input_fmapsÚnum_output_fmapsÚreceptive_field_sizeÚsr2   r3   s           r?   Ú_calculate_fan_in_and_fan_outr—      sœ   € Ø—‘“€JØ�A‚~ÜØ\ó
ð 	
ð —k‘k !“n€OØ—{‘{ 1“~ÐØÐØ‡z�zƒ|�aÒð —‘˜a˜bÐ!ò 	&ˆAØ  AÑ%Ñ ð	&àÐ3Ñ3€FØÐ!5Ñ5€Gà�7ˆ?ÐrP   Ú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"))

    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.xavier_uniform_(w.T, ...)``.
    rK   ç      @)r—   rL   rN   rW   r@   )r4   r˜   r7   r2   r3   rC   r5   s          r?   r   r   µ  sZ   € ôD 4°FÓ;�O€FˆGØ
”—‘˜3¤ v°Ñ'7Ó!8Ñ8Ó9Ñ
9€CÜ�	‰	�#‹˜Ñ€Aä˜V a R¨¨IÓ6Ð6rP   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)

    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.xavier_normal_(w.T, ...)``.
    rK   ç        )r—   rL   rN   rW   rF   )r4   r˜   r7   r2   r3   rC   s         r?   r   r   Þ  sF   € ôB 4°FÓ;�O€FˆGØ
”—‘˜3¤ v°Ñ'7Ó!8Ñ8Ó9Ñ
9€Cä˜F C¨¨iÓ8Ð8rP   Úmodec                 ó‚   — |j                  «       }ddg}||vrt        d|› d|› �«      ‚t        | «      \  }}|dk(  r|S |S )Nr2   r3   zMode z" not supported, please use one of )Úlowerrr   r—   )r4   r�   Úvalid_modesr2   r3   s        r?   Ú_calculate_correct_fanr¡     sX   € Ø�:‰:‹<€DØ˜YÐ'€KØ�;ÑÜ˜5  Ð&HÈÈÐVÓWÐWä3°FÓ;�O€FˆGØ˜XÒ%ˆ6Ð2¨7Ð2rP   c           	      óî  — t         j                  j                  | «      r+t         j                  j                  t        | f| ||||¬«      S d| j
                  v rt        j                  d«       | S t        | |«      }t        ||«      }|t        j                  |«      z  }t        j                  d«      |z  }t        j                  «       5  | j                  | ||¬«      cddd«       S # 1 sw Y   yxY w)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, ...)``.
    )r4   r5   r�   rk   r7   r   ú,Initializing zero-element tensors is a no-oprš   r;   N)r<   rv   rw   rx   r   rƒ   rX   rY   r¡   r
   rL   rN   r=   r   )	r4   r5   r�   rk   r7   Úfanr˜   rC   Úbounds	            r?   r   r     sÜ   € ôV ‡�×2Ñ2°6Ô:Ü�‰×4Ñ4ÜØˆIØØØØ%Øð 5ó 
ð 	
ð 	ˆF�L‰LÑÜ�‰ÐDÔEØˆÜ
  ¨Ó
.€CÜ˜,¨Ó*€DØ
”—‘˜3“Ñ
€CÜ�I‰I�c‹N˜SÑ €EÜ	�‰‹ñ CØ�‰ ˜v u¸	ˆÓB÷C÷ Cò Cús   ÃC+Ã+C4c                 ó(  — d| j                   v rt        j                  d«       | S t        | |«      }t	        ||«      }|t        j                  |«      z  }t        j                  «       5  | j                  d||¬«      cddd«       S # 1 sw Y   yxY w)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£   r;   N)
rƒ   rX   rY   r¡   r
   rL   rN   r<   r=   r   )r4   r5   r�   rk   r7   r¤   r˜   rC   s           r?   r   r   P  s}   € ðV 	ˆF�L‰LÑÜ�‰ÐDÔEØˆÜ
  ¨Ó
.€CÜ˜,¨Ó*€DØ
”—‘˜3“Ñ
€CÜ	�‰‹ñ ;Ø�~‰~˜a °	ˆ~Ó:÷;÷ ;ò ;ús   Á*BÂBc                 ó¢  — | j                  «       dk  rt        d«      ‚| j                  «       dk(  r| S | j                  d«      }| j                  «       |z  }| j	                  ||f«      j                  dd|¬«      }||k  r|j                  «        t        j                  j                  |«      \  }}t        j                  |d«      }|j                  «       }	||	z  }||k  r|j                  «        t        j                  «       5  | j                  |«      j                  |«       | j                  |«       ddd«       | S # 1 sw Y   | S xY w)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)
    rQ   z4Only tensors with 2 or more dimensions are supportedr   rT   r;   N)r‚   rr   Únumelr‰   Ú	new_emptyr   Út_r<   ÚlinalgÚqrÚdiagÚsignr=   Úview_asÚcopy_r[   )
r4   r˜   r7   ÚrowsÚcolsÚ	flattenedÚqÚrr�   Úphs
             r?   r   r   …  s  € ð, ×ÑÓ˜QÒÜÐOÓPÐPà‡|�|ƒ~˜ÒàˆØ�;‰;�q‹>€DØ�<‰<‹>˜TÑ!€DØ× Ñ  $¨ Ó.×6Ñ6°q¸!ÀyÐ6ÓQ€Iàˆd‚{Ø�‰Œô �<‰<�?‰?˜9Ó%�D€A€qä�
‰
�1�aÓ€AØ	
�‰‹€BØˆ�G€Aàˆd‚{Ø	�‰Œä	�‰‹ñ Ø�‰�qÓ×Ñ Ô"Ø�‰�DÔ÷ð €M÷ð €Mús   Ä2EÅEÚsparsityc                 ó‚  — | j                  «       dk7  rt        d«      ‚| j                  \  }}t        t	        j
                  ||z  «      «      }t        j                  «       5  | j                  d||¬«       t        |«      D ]#  }t        j                  |«      }|d| }	d| |	|f<   Œ% 	 ddd«       | S # 1 sw Y   | S xY w)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)
    rQ   r   r   r;   N)r‚   rr   rƒ   rq   rL   Úceilr<   r=   r   rŠ   Úrandperm)
r4   r·   rC   r7   r±   r²   Ú	num_zerosÚcol_idxÚrow_indicesÚzero_indicess
             r?   r   r   ¸  sº   € ð. ×ÑÓ˜aÒÜÐGÓHÐHà—‘�J€Dˆ$Ü”D—I‘I˜h¨™oÓ.Ó/€Iä	�‰‹ñ .Ø�‰�q˜#¨ˆÔ3Ü˜T“{ò 	.ˆGÜŸ.™.¨Ó.ˆKØ& z¨	Ð2ˆLØ,-ˆF�< Ð(Ò)ñ	.÷.ð €M÷.ð €Mús   Á#AB4Â4B>Úmethc                 óº   ‡ ‡‡— ‰ j                   Š‰d d Šdt        j                  dt        j                  dt        fˆ ˆˆfd„}d‰› d‰› d‰› d	�|_        ‰|_         |S )
NéÿÿÿÿÚargsÚkwargsr8   c                  óZ   •— t        j                  d‰› d‰› d�t        d¬«        ‰| i |¤ŽS )Nz	`nn.init.z)` is now deprecated in favor of `nn.init.z`.rQ   rR   )rX   rY   ÚFutureWarning)rÂ   rÃ   r¿   Únew_nameÚold_names     €€€r?   Údeprecated_initz(_make_deprecate.<locals>.deprecated_initã  s;   ø€ Ü�‰Ø˜�zÐ!JÈ8È*ÐTVÐWÜØõ	
ñ
 �TÐ$˜VÑ$Ð$rP   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Ë   ß  sy   ú€ Ø�}‰}€HØ˜˜ˆ}€Hð%œrŸw™wð %´"·)±)ð %Ä÷ %ð$Ø€Jð Hð IQÀzð Rà'˜j¨ð:€OÔð  (€OÔØÐrP   rc   )rœ   rJ   N)rœ   rJ   g       ÀrK   N)rT   )rJ   N)r   r2   r0   N)rT   N)rn   N)9rÊ   rL   rX   Útypingr   r   r   Ú	_Optionalr   r   Útyping_extensionsr   r<   r	   Ú__all__r$   r%   Ú_NonlinearityTypeÚ_FanModerW   Ú	Generatorr@   rF   r`   rf   rj   rq   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#   © rP   r?   ú<module>rÕ      sh  ðÙ Nã Û ß KÕ KÝ 'ã Ý ò€ñ> ˆTƒ]€Ùˆtƒ_€àðñÐ ð Ð&Ñ'€ð QUñ:Øð:Øð:Ø!&ð:Ø3<¸U¿_¹_Ñ3Mð:àó:ð -1ñ	>Øð>à
ð>ð 
ð>ð ˜Ÿ™Ñ)ð	>ð
 ó>ð  -1ñ)Øð)à
ð)ð 
ð)ð ð	)ð
 ð)ð ˜Ÿ™Ñ)ð)ð ó)ðX!˜6ð !¨ð !°&ó !ð
˜6ð  fó ð LPñGEØ#ðGEØ,5°e¸CÀ¸JÑ6GÑ,HðGEà
óGEðX ØØ,0ñ	6Øð6àð6ð ð6ð ˜Ÿ™Ñ)ð	6ð
 ó6ð: ØØ,0ñ	:Øð:à
ð:ð 
ð:ð ˜Ÿ™Ñ)ð	:ð
 ó:ð: ØØØØ,0ñPØðPà
ðPð 
ðPð ð	Pð
 ðPð ˜Ÿ™Ñ)ðPð óPð>'�fð ' 5ð '¨Vó 'ð$
'�&ð 
'˜Vó 
'ð
"�6ð 
"˜fó 
"ð�ð ˜Fó ñ*2�6ð 2 3ð 2¨vó 2ðj¨&ð °U¸3À¸8±_ó ð. Ø,0ñ&7Øð&7à
ð&7ð ˜Ÿ™Ñ)ð&7ð ó	&7ðV Ø,0ñ$9Øð$9à
ð$9ð ˜Ÿ™Ñ)ð$9ð ó	$9ðN3 6ð 3°ð 3¸có 3ð ØØ&2Ø,0ñ>CØð>Càð>Cð ð>Cð $ð	>Cð
 ˜Ÿ™Ñ)ð>Cð ó>CðF ØØ&2Ø,0ñ2;Øð2;àð2;ð ð2;ð $ð	2;ð
 ˜Ÿ™Ñ)ð2;ð ó2;ðn Ø,0ñ0Øð0à
ð0ð ˜Ÿ™Ñ)ð0ð ó	0ðl Ø,0ñ	#Øð#àð#ð 
ð#ð ˜Ÿ™Ñ)ð	#ð
 ó#ðN˜( 2 r 6Ñ*ð ¨x¸¸B¸Ñ/?ó ñ. ˜(Ó
#€Ù	˜Ó	!€Ù˜9Ó%€Ù�dÓ€Ù˜Ó€Ù  Ó1€Ù Ó/€Ù!Ð"2Ó3€Ù  Ó1€Ù˜[Ó)€
Ù	˜Ó	!�rP   