§
    �Štja  ã                  ó’   — d dl mZ d dlZd dlmZ d dlZg d¢Z edd¬¦  «        Z edd	¬¦  «        Z	 d#d$d„Z		 d#d%d„Z
d&d„Zd'd"„ZdS )(é    )ÚannotationsN)ÚTypeVar)Úfuse_conv_bn_evalÚfuse_conv_bn_weightsÚfuse_linear_bn_evalÚfuse_linear_bn_weightsÚConvTztorch.nn.modules.conv._ConvNd)ÚboundÚLinearTztorch.nn.LinearFÚconvÚbnú%torch.nn.modules.batchnorm._BatchNormÚ	transposeÚboolÚreturnc           
     ó.  — | j         s|j         rt          d¦  «        ‚t          j        | ¦  «        }|j        �|j        €t          d¦  «        ‚t          |j        |j        |j        |j        |j	        |j        |j        |¦  «        \  |_        |_        |S )a+  Fuse a convolutional module and a BatchNorm module into a single, new convolutional module.

    Args:
        conv (torch.nn.modules.conv._ConvNd): A convolutional module.
        bn (torch.nn.modules.batchnorm._BatchNorm): A BatchNorm module.
        transpose (bool, optional): If True, transpose the convolutional weight. Defaults to False.

    Returns:
        torch.nn.modules.conv._ConvNd: The fused convolutional module.

    .. note::
        Both ``conv`` and ``bn`` must be in eval mode, and ``bn`` must have its running buffers computed.
    úFusion only for eval!Nú3bn.running_mean and bn.running_var must not be None)
ÚtrainingÚAssertionErrorÚcopyÚdeepcopyÚrunning_meanÚrunning_varr   ÚweightÚbiasÚeps)r   r   r   Ú
fused_convs       úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/nn/utils/fusion.pyr   r      s›   € ð$ „}ð 6˜œð 6ÝÐ4Ñ5Ô5Ð5Ý”˜tÑ$Ô$€Jà	„Ð "¤.Ð"8ÝÐRÑSÔSÐSÝ)=ØÔØŒØ
ŒØ
ŒØ
ŒØ
Œ	Ø
ŒØñ	*ô 	*Ñ&€JÔ�z”ð Ðó    Úconv_wútorch.TensorÚconv_bútorch.Tensor | NoneÚbn_rmÚbn_rvÚbn_epsÚfloatÚbn_wÚbn_bú-tuple[torch.nn.Parameter, torch.nn.Parameter]c                ó”  — | j         }|�|j         n|}	|€t          j        |¦  «        }|€t          j        |¦  «        }|€t          j        |¦  «        }t          j        ||z   ¦  «        }
|r!ddgdgt          | j        ¦  «        dz
  z  z   }n ddgdgt          | j        ¦  «        dz
  z  z   }| ||
z                       |¦  «        z                       |¬¦  «        }||z
  |
z  |z  |z                        |	¬¦  «        }t          j	         
                    || j        ¦  «        t          j	         
                    ||j        ¦  «        fS )aÀ  Fuse convolutional module parameters and BatchNorm module parameters into new convolutional module parameters.

    Args:
        conv_w (torch.Tensor): Convolutional weight.
        conv_b (Optional[torch.Tensor]): Convolutional bias.
        bn_rm (torch.Tensor): BatchNorm running mean.
        bn_rv (torch.Tensor): BatchNorm running variance.
        bn_eps (float): BatchNorm epsilon.
        bn_w (Optional[torch.Tensor]): BatchNorm weight.
        bn_b (Optional[torch.Tensor]): BatchNorm bias.
        transpose (bool, optional): If True, transpose the conv weight. Defaults to False.

    Returns:
        Tuple[torch.nn.Parameter, torch.nn.Parameter]: Fused convolutional weight and bias.
    Né   éÿÿÿÿé   ©Údtype)r1   ÚtorchÚ
zeros_likeÚ	ones_likeÚrsqrtÚlenÚshapeÚreshapeÚtoÚnnÚ	ParameterÚrequires_grad)r!   r#   r%   r&   r'   r)   r*   r   Úconv_weight_dtypeÚconv_bias_dtypeÚbn_var_rsqrtr7   Úfused_conv_wÚfused_conv_bs                 r   r   r   :   se  € ð2 œÐØ&,Ð&8�f”l�lÐ>O€OØ€~ÝÔ! %Ñ(Ô(ˆØ€|ÝŒ˜uÑ%Ô%ˆØ€|ÝÔ Ñ&Ô&ˆÝ”;˜u v™~Ñ.Ô.€Làð 8Ø�B�˜1˜#¥ V¤\Ñ!2Ô!2°QÑ!6Ñ7Ñ7ˆˆà�Q�˜1˜#¥ V¤\Ñ!2Ô!2°QÑ!6Ñ7Ñ7ˆà˜d \Ñ1×:Ò:¸5ÑAÔAÑA×EÒEØð Fñ ô €Lð ˜e‘^ |Ñ3°dÑ:¸TÑA×EÒEØð Fñ ô €Lõ
 	Œ×Ò˜<¨Ô)=Ñ>Ô>ÝŒ×Ò˜<¨Ô)=Ñ>Ô>ðð r    Úlinearc           	     ó¢  — | j         s|j         rt          d¦  «        ‚t          j        | ¦  «        }	 | j        |j        k    r*|j        dk    rt          d| j        › d|j        › �¦  «        ‚|j        �|j        €t          d¦  «        ‚t          |j	        |j
        |j        |j        |j        |j	        |j
        ¦  «        \  |_	        |_
        |S )a“  Fuse a linear module and a BatchNorm module into a single, new linear module.

    Args:
        linear (torch.nn.Linear): A Linear module.
        bn (torch.nn.modules.batchnorm._BatchNorm): A BatchNorm module.

    Returns:
        torch.nn.Linear: The fused linear module.

    .. note::
        Both ``linear`` and ``bn`` must be in eval mode, and ``bn`` must have its running buffers computed.
    r   r-   zaTo fuse, linear.out_features == bn.num_features or bn.num_features == 1, got linear.out_features=z and bn.num_features=Nr   )r   r   r   r   Úout_featuresÚnum_featuresr   r   r   r   r   r   )rB   r   Úfused_linears      r   r   r   o   sû   € ð  „ð 6˜"œ+ð 6ÝÐ4Ñ5Ô5Ð5Ý”= Ñ(Ô(€Lð	ð Ô˜bœoÒ-Ð-°"´/ÀQÒ2FÐ2FÝðcØ'-Ô':ðcð cØQSÔQ`ðcð cñ
ô 
ð 	
ð
 
„Ð "¤.Ð"8ÝÐRÑSÔSÐSÝ-CØÔØÔØ
ŒØ
ŒØ
ŒØ
Œ	Ø
Œñ.ô .Ñ*€LÔ˜Ô*ð Ðr    Úlinear_wÚlinear_bc                ó°  — | j         }|�|j         n|}|€t          j        |¦  «        }|t          j        ||z   ¦  «        z  }	| |	                     d¦  «                             |¬¦  «        z  }
||z
  |	z  |z                        |¬¦  «        }t          j                             |
| j        ¦  «        t          j                             ||j        ¦  «        fS )a2  Fuse linear module parameters and BatchNorm module parameters into new linear module parameters.

    Args:
        linear_w (torch.Tensor): Linear weight.
        linear_b (Optional[torch.Tensor]): Linear bias.
        bn_rm (torch.Tensor): BatchNorm running mean.
        bn_rv (torch.Tensor): BatchNorm running variance.
        bn_eps (float): BatchNorm epsilon.
        bn_w (torch.Tensor): BatchNorm weight.
        bn_b (torch.Tensor): BatchNorm bias.

    Returns:
        Tuple[torch.nn.Parameter, torch.nn.Parameter]: Fused linear weight and bias.
    Nr.   r0   )	r1   r2   r3   r5   Ú	unsqueezer9   r:   r;   r<   )rG   rH   r%   r&   r'   r)   r*   Úlinear_weight_dtypeÚlinear_bias_dtypeÚbn_scaleÚfused_wÚfused_bs               r   r   r   ¢   sÜ   € ð. #œ.ÐØ*2Ð*>˜œ˜ÐDWÐØÐÝÔ# EÑ*Ô*ˆØ•e”k %¨&¡.Ñ1Ô1Ñ1€Hà˜×+Ò+¨BÑ/Ô/×2Ò2Ð9LÐ2ÑMÔMÑM€GØ˜5Ñ  HÑ,¨tÑ3×7Ò7Ð>OÐ7ÑPÔP€GåŒ8×Ò˜g xÔ'=Ñ>Ô>ÅÄ×@RÒ@RØ�Ô'ñAô Að ð r    )F)r   r	   r   r   r   r   r   r	   )r!   r"   r#   r$   r%   r"   r&   r"   r'   r(   r)   r$   r*   r$   r   r   r   r+   )rB   r   r   r   r   r   )rG   r"   rH   r$   r%   r"   r&   r"   r'   r(   r)   r"   r*   r"   r   r+   )Ú
__future__r   r   Útypingr   r2   Ú__all__r	   r   r   r   r   r   © r    r   ú<module>rT      sé   ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ð Ð à €€€ðð ð €ð 	ˆ�Ð>Ð?Ñ?Ô?€Ø
ˆ'�)Ð#4Ð
5Ñ
5Ô
5€ð ð#ð #ð #ð #ð #ð\ ð2ð 2ð 2ð 2ð 2ðj0ð 0ð 0ð 0ðf"ð "ð "ð "ð "ð "r    