
    9i.                         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      W/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/nn/modules/linear.pyr   Identity.__init__+   s        inputc                     U$ z
Runs the forward pass.
 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   5   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   r5   r6   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)G
Resets parameters based on their initialization used in ``__init__``.
   )aNr   r	   )r   kaiming_uniform_r1   mathsqrtr2   _calculate_fan_in_and_fan_outuniform_)r   fan_in_bounds       r   r:   Linear.reset_parametersu   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$ )0
Return the extra representation of the module.
zin_features=, out_features=, bias=N)r/   r0   r2   r   s    r   
extra_reprLinear.extra_repr   s:     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#   strrS   r*   r+   r,   s   @r   r   r   5   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   r5   r6   r   )r   r/   r0   r2   r5   r6   r   s         r   r   (NonDynamicallyQuantizableLinear.__init__   s     	Du 	 	
r   r!   rV   )	r%   r&   r'   r(   rZ   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      ao  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, must be > 0
    in2_features: size of each second input sample, must be > 0
    out_features: size of each output sample, must be > 0
    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   re   rf   r0   r1   Nr2   r   c                 b  > XVS.n[         TU ]  5         US::  a  [        SU 35      e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 )Nr4   r   z"in1_features must be > 0, but got r2   )r   r   
ValueErrorre   rf   r0   r   r7   r8   r1   r2   r9   r:   )	r   re   rf   r0   r2   r5   r6   r;   r   s	           r   r   Bilinear.__init__   s     %+;1A,PQQ(((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)r>   r	   N)rB   rC   r1   sizer   rE   r2   )r   rH   s     r   r:   Bilinear.reset_parameters   sa     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   rm   rn   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$ )rO   zin1_features=z, in2_features=rP   rQ   N)re   rf   r0   r2   rR   s    r   rS   Bilinear.extra_repr   sL    
 D--.od>O>O=P Q --.gdiit6K5LN	
r   )r2   re   rf   r0   r1   rV   rW   rX   r,   s   @r   r   r      s    #J EMN      	 
   
   4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   i  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 )Nr4   r   Fr!   )r   r   r   r1   r0   r2   )r   r0   r2   r5   r6   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)r>   r   N)has_uninitialized_paramsr/   r   r:   )r   r   s    r   r:   LazyLinear.reset_parameters.  s5     ,,..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        U R                  S:X  ap  UR                  S   U R
                  R                  S   :X  d1   SUR                  S    SU R
                  R                  S    35       eUR                  S   U l        gg! , (       d  f       N= f)zG
Infers ``in_features`` based on ``input`` and initializes parameters.
Nr   z%The in_features inferred from input: z/ is not equal to in_features from self.weight: )
rx   r7   no_gradshaper/   r1   materializer0   r2   r:   r"   s     r   initialize_parameters LazyLinear.initialize_parameters5  s    ((**#(;;r? ''):):D<L<L(MN99(II))4+<+<*>?%%' ! q ;;r?dkk&7&7&;; 7B7H IA;;$$R()+;
  %{{2D ! !s   B	D==
ErU   rV   rW   )r%   r&   r'   r(   r)   r   cls_to_becomer   r[   rZ   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   r7   r   torch.nnr   rK   r   torch.nn.parameterr   r   lazyr
   moduler   __all__r   r   r_   r   r   r!   r   r   <module>r      sl        * @ ! v >WqV Wq~
f 
\
v \
~E/& E/r   