
    Χg)                         d dl Z d dlmZ d dlZd dlmZ d dlmZmZ d dl	m
Z
mZ ddlmZ ddlmZ g d	Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d dee          ZdS )    N)Any)Tensor)
functionalinit)	ParameterUninitializedParameter   )LazyModuleMixin)Module)BilinearIdentity
LazyLinearLinearc                   @     e Zd ZdZdededdf fdZdedefdZ xZS )	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                 H    t                                                       d S Nsuper__init__)selfr   r   	__class__s      S/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/nn/modules/linear.pyr   zIdentity.__init__+   s        inputc                     |S r    r   r   s     r   forwardzIdentity.forward.   s    r   )	__name__
__module____qualname____doc__r   r   r   r!   __classcell__r   s   @r   r   r      s~         (c S T      V         r   r   c            	            e Zd ZU dZddgZeed<   eed<   eed<   	 	 	 ddedededdf fd	Z	dd
Z
dedefdZdefdZ xZS )r   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_{in})` where :math:`*` means any number of
          dimensions including none and :math:`H_{in} = \text{in\_features}`.
        - Output: :math:`(*, H_{out})` where all but the last dimension
          are the same shape as the input and :math:`H_{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weightTNbiasr   c                 \   ||d}t                                                       || _        || _        t	          t          j        ||ffi |          | _        |r%t	          t          j        |fi |          | _        n| 	                    dd            | 
                                 d S Ndevicedtyper,   )r   r   r)   r*   r   torchemptyr+   r,   register_parameterreset_parameters)r   r)   r*   r,   r0   r1   factory_kwargsr   s          r   r   zLinear.__init__]   s     %+U;;&(K{3FF~FF
 
  	2!%+l"M"Mn"M"MNNDII##FD111r   c                     t          j        | j        t          j        d                     | j        Yt          j        | j                  \  }}|dk    rdt          j        |          z  nd}t          j        | j        | |           d S d S )N   )ar   r	   )r   kaiming_uniform_r+   mathsqrtr,   _calculate_fan_in_and_fan_outuniform_)r   fan_in_bounds       r   r5   zLinear.reset_parametersr   s     	dkTYq\\::::9 :4;GGIFA-3aZZA	&))))QEM$)eVU33333 ! r   r   c                 B    t          j        || j        | j                  S r   )Flinearr+   r,   r    s     r   r!   zLinear.forward|   s    xt{DI666r   c                 :    d| j          d| j         d| j        d u S )Nzin_features=, out_features=, bias=)r)   r*   r,   r   s    r   
extra_reprzLinear.extra_repr   s0    pd.ppt?PppY]YbjnYnpppr   TNNr   Nr"   r#   r$   r%   __constants__int__annotations__r   boolr   r5   r!   strrI   r&   r'   s   @r   r   r   2   s        # #J #N3MNNN        	  
           *4 4 4 47V 7 7 7 7 7qC q q q q q q q qr   r   c            	       8     e Zd Z	 	 	 ddedededdf fdZ xZS )	NonDynamicallyQuantizableLinearTNr)   r*   r,   r   c                 T    t                                          |||||           d S )N)r,   r0   r1   r   )r   r)   r*   r,   r0   r1   r   s         r   r   z(NonDynamicallyQuantizableLinear.__init__   s;     	Du 	 	
 	
 	
 	
 	
r   rJ   )r"   r#   r$   rN   rP   r   r&   r'   s   @r   rS   rS      ss        
 

 



 

 	

 


 

 

 

 

 

 

 

 

 

r   rS   c                        e Zd ZU dZg dZeed<   eed<   eed<   eed<   	 	 	 ddededed	ed
df
 fdZ	ddZ
deded
efdZd
efdZ xZS )r   a  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_{in1})` where :math:`H_{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_{in2})` where :math:`H_{in2}=\text{in2\_features}`.
        - Output: :math:`(*, H_{out})` where :math:`H_{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_featuresr*   rV   rW   r*   r+   TNr,   r   c                 l   ||d}t                                                       || _        || _        || _        t          t          j        |||ffi |          | _        |r%t          t          j        |fi |          | _	        n| 
                    dd            |                                  d S r.   )r   r   rV   rW   r*   r   r2   r3   r+   r,   r4   r5   )	r   rV   rW   r*   r,   r0   r1   r6   r   s	           r   r   zBilinear.__init__   s     %+U;;(((K|\BUUnUU
 
  	2!%+l"M"Mn"M"MNNDII##FD111r   c                     dt          j        | j                            d                    z  }t	          j        | j        | |           | j        t	          j        | j        | |           d S d S )Nr	   )r;   r<   r+   sizer   r>   r,   )r   rA   s     r   r5   zBilinear.reset_parameters   sl    DIdk..q11222dkE651119 M$)eVU33333 ! r   input1input2c                 D    t          j        ||| j        | j                  S r   )rC   bilinearr+   r,   )r   r[   r\   s      r   r!   zBilinear.forward   s    z&&$+tyAAAr   c           	      J    d| j          d| j         d| j         d| j        d u S )Nzin1_features=z, in2_features=rF   rG   )rV   rW   r*   r,   rH   s    r   rI   zBilinear.extra_repr   sW    ND- N Nd>O N N -N N6:it6KN N	
r   rJ   rK   rL   r'   s   @r   r   r      s$        # #J EDDMNNN        	 
   
           04 4 4 4Bf Bf B B B B B
C 
 
 
 
 
 
 
 
r   r   c                   b     e Zd ZU dZeZeed<   eed<   	 ddede	ddf fdZ
d fd	Zdd
Z xZS )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}}`


    r+   r,   TNr*   r   c                     ||d}t                                          ddd           t          di || _        || _        |rt          di || _        d S d S )Nr/   r   Fr   )r   r   r   r+   r*   r,   )r   r*   r,   r0   r1   r6   r   s         r   r   zLazyLinear.__init__  s{     %+U;; 	Au%%%,>>~>>( 	A.@@@@DIII	A 	Ar   c                     |                                  s-| j        dk    r$t                                                       d S d S d S )Nr   )has_uninitialized_paramsr)   r   r5   )r   r   s    r   r5   zLazyLinear.reset_parameters  sP    ,,.. 	'43Cq3H3HGG$$&&&&&	' 	'3H3Hr   c                 p   |                                  rt          j                    5  |j        d         | _        | j                            | j        | j        f           | j         | j                            | j        f           | 	                                 d d d            d S # 1 swxY w Y   d S d S )N)
rc   r2   no_gradshaper)   r+   materializer*   r,   r5   r    s     r   initialize_parametersz LazyLinear.initialize_parameters  s    ((** 	( ( (#(;r? ''):D<L(MNNN9(I))4+<*>???%%'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	(s   A4B))B-0B-rJ   rK   )r"   r#   r$   r%   r   cls_to_becomer   rO   rN   rP   r   r5   ri   r&   r'   s   @r   r   r      s          8 M""""
     HL
A 
A
A'+
A	
A 
A 
A 
A 
A 
A' ' ' ' ' '( ( ( ( ( ( ( (r   r   )r;   typingr   r2   r   torch.nnr   rC   r   torch.nn.parameterr   r   lazyr
   moduler   __all__r   r   rS   r   r   r   r   r   <module>rq      s                 * * * * * * * * @ @ @ @ @ @ @ @ ! ! ! ! ! !            v   8Nq Nq Nq Nq NqV Nq Nq Nql
 
 
 
 
f 
 
 
Q
 Q
 Q
 Q
 Q
v Q
 Q
 Q
h8( 8( 8( 8( 8(& 8( 8( 8( 8( 8(r   