
    JTh*                         S SK r S SKJr  S SKrS SKJr  S SKJrJr  S SK	J
r
Jr  SSKJr  SSK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g)    N)Any)Tensor)
functionalinit)	ParameterUninitializedParameter   )LazyModuleMixin)Module)BilinearIdentity
LazyLinearLinearc                   N   ^  \ rS rSrSrS\S\SS4U 4S jjrS\S\4S	 jrS
r	U =r
$ )r      a  A placeholder identity operator that is argument-insensitive.

Args:
    args: any argument (unused)
    kwargs: any keyword argument (unused)

Shape:
    - Input: :math:`(*)`, where :math:`*` means any number of dimensions.
    - Output: :math:`(*)`, same shape as the input.

Examples::

    >>> m = nn.Identity(54, unused_argument1=0.1, unused_argument2=False)
    >>> input = torch.randn(128, 20)
    >>> output = m(input)
    >>> print(output.size())
    torch.Size([128, 20])

argskwargsreturnNc                 "   > [         TU ]  5         g Nsuper__init__)selfr   r   	__class__s      O/var/www/auris/envauris/lib/python3.13/site-packages/torch/nn/modules/linear.pyr   Identity.__init__+   s        inputc                     U$ r    r   r   s     r   forwardIdentity.forward.   s    r   r!   )__name__
__module____qualname____firstlineno____doc__r   r   r   r#   __static_attributes____classcell__r   s   @r   r   r      s:    (c S T V   r   r   c            	          ^  \ rS rSr% SrSS/r\\S'   \\S'   \\S'      SS\S\S\	SS4U 4S	 jjjr
SS
 jrS\S\4S jrS\4S jrSrU =r$ )r   2   a  Applies an affine linear transformation to the incoming data: :math:`y = xA^T + b`.

This module supports :ref:`TensorFloat32<tf32_on_ampere>`.

On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.

Args:
    in_features: size of each input sample
    out_features: size of each output sample
    bias: If set to ``False``, the layer will not learn an additive bias.
        Default: ``True``

Shape:
    - Input: :math:`(*, H_\text{in})` where :math:`*` means any number of
      dimensions including none and :math:`H_\text{in} = \text{in\_features}`.
    - Output: :math:`(*, H_\text{out})` where all but the last dimension
      are the same shape as the input and :math:`H_\text{out} = \text{out\_features}`.

Attributes:
    weight: the learnable weights of the module of shape
        :math:`(\text{out\_features}, \text{in\_features})`. The values are
        initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where
        :math:`k = \frac{1}{\text{in\_features}}`
    bias:   the learnable bias of the module of shape :math:`(\text{out\_features})`.
            If :attr:`bias` is ``True``, the values are initialized from
            :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})` where
            :math:`k = \frac{1}{\text{in\_features}}`

Examples::

    >>> m = nn.Linear(20, 30)
    >>> input = torch.randn(128, 20)
    >>> output = m(input)
    >>> print(output.size())
    torch.Size([128, 30])
in_featuresout_featuresweightNbiasr   c                 ,  > XES.n[         TU ]  5         Xl        X l        [	        [
        R                  " X!440 UD65      U l        U(       a&  [	        [
        R                  " U40 UD65      U l        OU R                  SS 5        U R                  5         g Ndevicedtyper2   )r   r   r/   r0   r   torchemptyr1   r2   register_parameterreset_parameters)r   r/   r0   r2   r6   r7   factory_kwargsr   s          r   r   Linear.__init__]   s     %+;&(KK3F~F
 !%++l"Mn"MNDI##FD1r   c                 R   [         R                  " U R                  [        R                  " S5      S9  U R
                  bg  [         R                  " U R                  5      u  pUS:  a  S[        R                  " U5      -  OSn[         R                  " U R
                  U* U5        g g )N   )ar   r	   )r   kaiming_uniform_r1   mathsqrtr2   _calculate_fan_in_and_fan_outuniform_)r   fan_in_bounds       r   r;   Linear.reset_parametersr   sv     	dkkTYYq\:99 ::4;;GIF-3aZA		&))QEMM$))eVU3 !r   r   c                 X    [         R                  " XR                  U R                  5      $ r   )Flinearr1   r2   r"   s     r   r#   Linear.forward|   s    xx{{DII66r   c                 X    SU R                    SU R                   SU R                  S L 3$ )Nzin_features=, out_features=, bias=)r/   r0   r2   r   s    r   
extra_reprLinear.extra_repr   s8    d../t?P?P>QQXY]YbYbjnYnXoppr   r2   r/   r0   r1   TNNr   Nr%   r&   r'   r(   r)   __constants__int__annotations__r   boolr   r;   r#   strrR   r*   r+   r,   s   @r   r   r   2   s    #J #N3MN      	  
   *47V 7 7qC q qr   r   c            	       F   ^  \ rS rSr   S	S\S\S\SS4U 4S jjjrSrU =r$ )
NonDynamicallyQuantizableLinear   Nr/   r0   r2   r   c                 $   > [         TU ]  XX4US9  g )N)r2   r6   r7   r   )r   r/   r0   r2   r6   r7   r   s         r   r   (NonDynamicallyQuantizableLinear.__init__   s     	Du 	 	
r   r!   rU   )	r%   r&   r'   r(   rY   r[   r   r*   r+   r,   s   @r   r^   r^      s>    
 



 

 	

 


 

r   r^   c                      ^  \ rS rSr% Sr/ SQr\\S'   \\S'   \\S'   \\S'      SS\S\S\S	\	S
S4
U 4S jjjr
SS jrS\S\S
\4S jrS
\4S jrSrU =r$ )r      aH  Applies a bilinear transformation to the incoming data: :math:`y = x_1^T A x_2 + b`.

Args:
    in1_features: size of each first input sample
    in2_features: size of each second input sample
    out_features: size of each output sample
    bias: If set to ``False``, the layer will not learn an additive bias.
        Default: ``True``

Shape:
    - Input1: :math:`(*, H_\text{in1})` where :math:`H_\text{in1}=\text{in1\_features}` and
      :math:`*` means any number of additional dimensions including none. All but the last dimension
      of the inputs should be the same.
    - Input2: :math:`(*, H_\text{in2})` where :math:`H_\text{in2}=\text{in2\_features}`.
    - Output: :math:`(*, H_\text{out})` where :math:`H_\text{out}=\text{out\_features}`
      and all but the last dimension are the same shape as the input.

Attributes:
    weight: the learnable weights of the module of shape
        :math:`(\text{out\_features}, \text{in1\_features}, \text{in2\_features})`.
        The values are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where
        :math:`k = \frac{1}{\text{in1\_features}}`
    bias:   the learnable bias of the module of shape :math:`(\text{out\_features})`.
            If :attr:`bias` is ``True``, the values are initialized from
            :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where
            :math:`k = \frac{1}{\text{in1\_features}}`

Examples::

    >>> m = nn.Bilinear(20, 30, 40)
    >>> input1 = torch.randn(128, 20)
    >>> input2 = torch.randn(128, 30)
    >>> output = m(input1, input2)
    >>> print(output.size())
    torch.Size([128, 40])
)in1_featuresin2_featuresr0   rd   re   r0   r1   Nr2   r   c                 :  > XVS.n[         TU ]  5         Xl        X l        X0l        [        [        R                  " X1U440 UD65      U l        U(       a&  [        [        R                  " U40 UD65      U l	        OU R                  SS 5        U R                  5         g r4   )r   r   rd   re   r0   r   r8   r9   r1   r2   r:   r;   )	r   rd   re   r0   r2   r6   r7   r<   r   s	           r   r   Bilinear.__init__   s     %+;(((KK\BUnU
 !%++l"Mn"MNDI##FD1r   c                    S[         R                  " U R                  R                  S5      5      -  n[        R
                  " U R                  U* U5        U R                  b$  [        R
                  " U R                  U* U5        g g )Nr	   )rB   rC   r1   sizer   rE   r2   )r   rH   s     r   r;   Bilinear.reset_parameters   s_    DIIdkk..q122dkkE65199 MM$))eVU3 !r   input1input2c                 Z    [         R                  " XU R                  U R                  5      $ r   )rK   bilinearr1   r2   )r   rk   rl   s      r   r#   Bilinear.forward   s    zz&$++tyyAAr   c           	      r    SU R                    SU R                   SU R                   SU R                  S L 3$ )Nzin1_features=z, in2_features=rO   rP   )rd   re   r0   r2   rQ   s    r   rR   Bilinear.extra_repr   sJ    D--.od>O>O=P Q --.gdiit6K5LN	
r   )r2   rd   re   r0   r1   rU   rV   rW   r,   s   @r   r   r      s    #J EMN      	 
   
   04Bf Bf B B
C 
 
r   r   c                   v   ^  \ rS rSr% Sr\r\\S'   \\S'    SS\	S\
SS4U 4S jjjrSU 4S	 jjrSS
 jrSrU =r$ )r      a  A :class:`torch.nn.Linear` module where `in_features` is inferred.

In this module, the `weight` and `bias` are of :class:`torch.nn.UninitializedParameter`
class. They will be initialized after the first call to ``forward`` is done and the
module will become a regular :class:`torch.nn.Linear` module. The ``in_features`` argument
of the :class:`Linear` is inferred from the ``input.shape[-1]``.

Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation
on lazy modules and their limitations.

Args:
    out_features: size of each output sample
    bias: If set to ``False``, the layer will not learn an additive bias.
        Default: ``True``

Attributes:
    weight: the learnable weights of the module of shape
        :math:`(\text{out\_features}, \text{in\_features})`. The values are
        initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where
        :math:`k = \frac{1}{\text{in\_features}}`
    bias:   the learnable bias of the module of shape :math:`(\text{out\_features})`.
            If :attr:`bias` is ``True``, the values are initialized from
            :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})` where
            :math:`k = \frac{1}{\text{in\_features}}`


r1   r2   Nr0   r   c                    > X4S.n[         TU ]  SSS5        [        S0 UD6U l        Xl        U(       a  [        S0 UD6U l        g g )Nr5   r   Fr!   )r   r   r   r1   r0   r2   )r   r0   r2   r6   r7   r<   r   s         r   r   LazyLinear.__init__  sL     %+; 	Au%,>~>(.@@DI r   c                 p   > U R                  5       (       d   U R                  S:w  a  [        TU ]  5         g g g )Nr   )has_uninitialized_paramsr/   r   r;   )r   r   s    r   r;   LazyLinear.reset_parameters  s3    ,,..43C3Cq3HG$& 4I.r   c                    U R                  5       (       a  [        R                  " 5          UR                  S   U l        U R
                  R                  U R                  U R                  45        U R                  b&  U R                  R                  U R                  45        U R                  5         S S S 5        g g ! , (       d  f       g = f)N)
rw   r8   no_gradshaper/   r1   materializer0   r2   r;   r"   s     r   initialize_parameters LazyLinear.initialize_parameters  s    ((**#(;;r? ''):):D<L<L(MN99(II))4+<+<*>?%%' ! + s   B	B>>
CrT   rU   rV   )r%   r&   r'   r(   r)   r   cls_to_becomer   rZ   rY   r[   r   r;   r~   r*   r+   r,   s   @r   r   r      sX    8 M""
   HL
A
A'+
A	
A 
A'( (r   r   )rB   typingr   r8   r   torch.nnr   rK   r   torch.nn.parameterr   r   lazyr
   moduler   __all__r   r   r^   r   r   r!   r   r   <module>r      sj        * @ ! v 8NqV Nql
f 
Q
v Q
h8(& 8(r   