§
    Ó˜ºh,  ã                   óü   — 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      €ú_/var/www/html/services/rag-service/venv/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   aC  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Ú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,   r/   r0   Úfactory_kwargsr   s          €r   r   zLinear.__init__]   s¾   ø€ ð %+°UÐ;Ð;ˆÝ‰Œ×ÒÑÔÐØ&ˆÔØ(ˆÔÝÝŒK˜ {Ð3ÐFÐF°~ÐFÐFñ
ô 
ˆŒð ð 	2Ý!¥%¤+¨lÐ"MÐ"M¸nÐ"MÐ"MÑNÔNˆDŒIˆIà×#Ò# F¨DÑ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   r4   zLinear.reset_parametersr   s‰   € õ 	Ô˜dœk­T¬Y°q©\¬\Ð:Ñ:Ô:Ð:ØŒ9Ð ÝÔ:¸4¼;ÑGÔG‰IˆF�AØ-3°aªZ¨Z�A�œ	 &Ñ)Ô)Ñ)Ð)¸QˆEÝŒM˜$œ) e V¨UÑ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œ{¨D¬IÑ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   € Øp˜dÔ.ÐpÐp¸tÔ?PÐpÐpÐY]ÔYbÐjnÐYnÐpÐpÐpr   ©TNN©r   N©r"   r#   r$   r%   Ú__constants__ÚintÚ__annotations__r   Úboolr   r4   r!   ÚstrrH   r&   r'   s   @r   r   r   2   s  ø€ € € € € € ð#ð #ðJ # NÐ3€MØÐÐÑØÐÐÑØ€N€N�Nð ØØð ð  àð ð ð ð ð	 ð 
ð ð  ð  ð  ð  ð  ð*4ð 4ð 4ð 4ð7˜Vð 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,   r/   r0   r   )r   r)   r*   r,   r/   r0   r   s         €r   r   z(NonDynamicallyQuantizableLinear.__init__‰   s;   ø€ õ 	‰Œ×ÒØ˜¨D¸Àuð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r   rI   )r"   r#   r$   rM   rO   r   r&   r'   s   @r   rR   rR   ˆ   ss   ø€ € € € € ð
 ØØð

ð 

àð

ð ð

ð ð	

ð 
ð

ð 

ð 

ð 

ð 

ð 

ð 

ð 

ð 

ð 

r   rR   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, 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_featuresr*   rU   rV   r*   r+   TNr,   r   c                 óœ  •— ||dœ}t          ¦   «                              ¦   «          |dk    rt          d|› �¦  «        ‚|| _        || _        || _        t          t          j        |||ffi |¤Ž¦  «        | _	        |r%t          t          j        |fi |¤Ž¦  «        | _
        n|                      dd ¦  «         |                      ¦   «          d S )Nr.   r   z"in1_features must be > 0, but got r,   )r   r   Ú
ValueErrorrU   rV   r*   r   r1   r2   r+   r,   r3   r4   )	r   rU   rV   r*   r,   r/   r0   r5   r   s	           €r   r   zBilinear.__init__Â   sê   ø€ ð %+°UÐ;Ð;ˆÝ‰Œ×ÒÑÔÐØ˜1ÒÐÝÐPÀ,ÐPÐPÑQÔQÐQØ(ˆÔØ(ˆÔØ(ˆÔÝÝŒK˜ |°\ÐBÐUÐUÀnÐUÐUñ
ô 
ˆŒð ð 	2Ý!¥%¤+¨lÐ"MÐ"M¸nÐ"MÐ"MÑNÔNˆDŒIˆIà×#Ò# F¨DÑ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   r@   s     r   r4   zBilinear.reset_parametersÜ   sl   € Ø•D”I˜dœk×.Ò.¨qÑ1Ô1Ñ2Ô2Ñ2ˆÝŒ�d”k E 6¨5Ñ1Ô1Ð1ØŒ9Ð ÝŒM˜$œ) e V¨UÑ3Ô3Ð3Ð3Ð3ð !Ð r   Úinput1Úinput2c                 óD   — t          j        ||| j        | j        ¦  «        S r   )rB   Úbilinearr+   r,   )r   r[   r\   s      r   r!   zBilinear.forwardâ   s   € ÝŒz˜& &¨$¬+°t´yÑAÔAÐAr   c           	      óJ   — d| j         › d| j        › d| j        › d| j        d u› �S )Nzin1_features=z, in2_features=rE   rF   )rU   rV   r*   r,   rG   s    r   rH   zBilinear.extra_reprå   sW   € ðN˜DÔ-ð Nð N¸dÔ>Oð Nð NØ Ô-ðNð NØ6:´iÀtÐ6KðNð Nð	
r   rI   rJ   rK   r'   s   @r   r   r   –   s$  ø€ € € € € € ð#ð #ðJ EÐDÐD€MØÐÐÑØÐÐÑØÐÐÑØ€N€N�Nð ØØð ð  àð ð ð ð ð	 ð
 ð ð 
ð ð  ð  ð  ð  ð  ð4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,   r/   r0   r5   r   s         €r   r   zLazyLinear.__init__  s{   ø€ ð %+°UÐ;Ð;ˆõ 	‰Œ×Ò˜˜A˜uÑ%Ô%Ð%Ý,Ð>Ð>¨~Ð>Ð>ˆŒØ(ˆÔØð 	AÝ.Ð@Ð@°Ð@Ð@ˆDŒIˆIˆIð	Að 	Ar   c                 óŽ   •— |                       ¦   «         s-| j        dk    r$t          ¦   «                              ¦   «          d S d S d S )Nr   )Úhas_uninitialized_paramsr)   r   r4   )r   r   s    €r   r4   zLazyLinear.reset_parameters  sP   ø€ Ø×,Ò,Ñ.Ô.ð 	'°4Ô3CÀqÒ3HÐ3HÝ‰GŒG×$Ò$Ñ&Ô&Ð&Ð&Ð&ð	'ð 	'Ð3HÐ3Hr   c                 ó@  — |                       ¦   «         ržt          j        ¦   «         5  |j        d         | _        | j                             | j        | j        f¦  «         | j        � | j                             | j        f¦  «         |  	                    ¦   «          d d d ¦  «         n# 1 swxY w Y   | j        dk    r`|j        d         | j        j        d         k    s+J d|j        d         › d| j        j        d         › �¦   «         ‚|j        d         | _        d S d S )Néÿÿÿÿr   z%The in_features inferred from input: z/ is not equal to in_features from self.weight: )
rc   r1   Úno_gradÚshaper)   r+   Úmaterializer*   r,   r4   r    s     r   Úinitialize_parametersz LazyLinear.initialize_parameters  sa  € Ø×(Ò(Ñ*Ô*ð 	(Ý”‘”ð (ð (Ø#(¤;¨r¤?�Ô Ø”×'Ò'¨Ô):¸DÔ<LÐ(MÑNÔNÐNØ”9Ð(Ø”I×)Ò)¨4Ô+<Ð*>Ñ?Ô?Ð?Ø×%Ò%Ñ'Ô'Ð'ð(ð (ð (ñ (ô (ð (ð (ð (ð (ð (ð (øøøð (ð (ð (ð (ð Ô˜qÒ Ð Ø”;˜r”? d¤kÔ&7¸Ô&;Ò;Ð;Ð;ð+¸¼ÀB¼ð +ð +à”;Ô$ RÔ(ð+ð +ñ <Ô;Ð;ð
  %œ{¨2œˆDÔÐÐð !Ð s   ¨A4B(Â(B,Â/B,rI   rJ   )r"   r#   r$   r%   r   Úcls_to_becomer   rN   rM   rO   r   r4   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   r1   r   Útorch.nnr   rB   r   Útorch.nn.parameterr   r   Úlazyr
   Úmoduler   Ú__all__r   r   rR   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ñ 
ô 
ð 
ðS
ð S
ð S
ð S
ð S
ˆvñ S
ô S
ð S
ðl?/ð ?/ð ?/ð ?/ð ?/� &ñ ?/ô ?/ð ?/ð ?/ð ?/r   