§
    �Štj  ã                   óH  — d dl 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
 e j        j        Z ee j        e j        e j        e j        g¦  «        Z eg ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej        ‘ej         ‘ej!        ‘ej"        ‘ej#        ‘ej$        ‘ej%        ‘ej&        ‘ej'        ‘ej(        ‘ej)        ‘ej*        ‘ej+        ‘ej,        ‘ej-        ‘ej.        ‘ej/        ‘ej0        ‘¦  «        Z1 eej2        ej3        ej4        ej5        ej6        ej7        ej8        ej9        ej:        g	¦  «        Z;e1e;z  Z<de=e>z  dd	d
e=fd„Z?	 dd
e=fd„Z@de jA        d
e>fd„ZBd
e=fd„ZCdS )é    N)Úget_device_tflopsÚget_gpu_dram_gbps)Úoptimization_hintÚstatically_known_true)Ú
OrderedSeté   )Úflop_registryÚflopsÚdtypeztorch.dtypeÚreturnc                 óV   — t          |¦  «        dz  }|dk    rdS | dz  }|d|z  z  dz  S )z“Convert a FLOPs count to estimated nanoseconds on the current GPU.

    Uses 75% of theoretical peak and converts FLOPs to MACs (divide by 2).
    g   ¢”mBr   ç        é   g      è?g    eÍÍA)r   )r
   r   Úpeak_gpu_flopsÚmacss       ú]/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/utils/_runtime_estimation.pyÚflops_to_nsr   M   sD   € õ
 ' uÑ-Ô-°Ñ4€NØ˜ÒÐØˆsØ�1‰9€DØ�D˜>Ñ)Ñ*¨cÑ1Ð1ó    c                 óø   — | t           v rpt          |¦  «        dk    rt          d|› d| › �¦  «        ‚|                     ¦   «         }t           |          }i }|�||d<    ||i |¤d|i¤|¤Ž}	t	          |	|¦  «        S dS )a2  
    Estimates the compute time of an aten operator.

    Args:
        func_packet: The operator overload packet.
        args: The arguments to the operator.
        kwargs: The keyword arguments to the operator.
        out: The output of the operator.
        out_dtypes: The output data types.
        node_meta: Optional FX node meta dict. Passed through to the flop
            formula as ``_node_meta`` kwarg so formulas can read annotations
            like ``sparsity_hint``.

    Returns:
        float: The estimated compute time in nanoseconds.
    r   z"Only support single out dtype got z for NÚ
_node_metaÚout_valr   )r	   ÚlenÚAssertionErrorÚpopr   )
Úfunc_packetÚargsÚkwargsÚoutÚ
out_dtypesÚ	node_metar   Úflop_count_funcÚextra_kwargsÚ
flop_counts
             r   Úget_compute_timer$   Y   s®   € ð& •mÐ#Ð#Ýˆz‰?Œ?˜aÒÐÝ ØS°ZÐSÐSÀkÐSÐSñô ð ð —’Ñ Ô ˆÝ'¨Ô4ˆØˆØÐ Ø)2ˆL˜Ñ&Ø$�_ dÐR¨fÐRÐR¸cÐRÐRÀ\ÐRÐRˆ
Ý˜: uÑ-Ô-Ð-Øˆ3r   Útc                 óÜ   — d}t          | j        |                      ¦   «         ¦  «        D ],\  }}t          |dk    ¦  «        s|t	          |d¬¦  «        z  }Œ-||                      ¦   «         z  S )z¹
    Calculates the memory consumption of a tensor.

    Args:
        t (torch.Tensor): The input tensor.

    Returns:
        int: The memory consumption of the tensor in bytes.
    r   r   )Úfallback)ÚzipÚshapeÚstrider   r   Úelement_size)r%   Ú
real_numelÚsizer*   s       r   Úget_num_bytesr.   {   sr   € ð €JÝ˜AœG Q§X¢X¡Z¤ZÑ0Ô0ð >ð >‰ˆˆfå$ V¨q¢[Ñ1Ô1ð 	>ØÕ+¨D¸1Ð=Ñ=Ô=Ñ=ˆJøà˜ŸšÑ(Ô(Ñ(Ð(r   c                 óš   — t          ¦   «         }t          d„ | D ¦   «         ¦  «        }t          d„ |D ¦   «         ¦  «        }||z   }||z  }|S )aG  
    Estimates the memory transfer time of input and output tensors.

    Args:
        flat_args_kwargs (List[torch.Tensor]): The flat list of arguments and keyword arguments.
        flat_outs (List[torch.Tensor]): The flat list of outputs.

    Returns:
        float: The estimated memory transfer time in nanoseconds.
    c              3   óh   K  — | ]-}t          |t          j        ¦  «        ¯t          |¦  «        V — Œ.d S ©N©Ú
isinstanceÚtorchÚTensorr.   ©Ú.0r%   s     r   ú	<genexpr>z$get_transfer_time.<locals>.<genexpr>š   sO   è è € ð ð ØµjÀÅEÄLÑ6QÔ6QðÝ�aÑÔðð ð ð ð ð r   c              3   óh   K  — | ]-}t          |t          j        ¦  «        ¯t          |¦  «        V — Œ.d S r1   r2   r6   s     r   r8   z$get_transfer_time.<locals>.<genexpr>�   sO   è è € ð ð Ø­z¸!½U¼\Ñ/JÔ/JðÝ�aÑÔðð ð ð ð ð r   )r   Úsum)Úflat_args_kwargsÚ	flat_outsÚgpu_memory_bandwidthÚ
read_bytesÚwrite_bytesÚcounted_bytesÚtransfer_times          r   Úget_transfer_timerB   Ž   s…   € õ -Ñ.Ô.ÐÝð ð Ø"2ðñ ô ñ ô €Jõ ð ð Ø"+ðñ ô ñ ô €Kð  Ñ,€Mà!Ð$8Ñ8€MØÐr   r1   )Dr4   Útorch._inductor.utilsr   r   Ú%torch.fx.experimental.symbolic_shapesr   r   Útorch.utils._ordered_setr   Úflop_counterr	   ÚopsÚatenÚfloat16Úbfloat16Úfloat32Úfloat64Ú_FLOAT_TYPESÚ
lift_freshr%   Ú	transposeÚviewÚdetachÚ_unsafe_viewÚsplitÚadjointÚ
as_stridedÚdiagonalÚexpandÚ	expand_asÚmovedimÚpermuteÚselectÚsqueezeÚmTÚmHÚrealÚimagÚview_asÚ	unflattenÚunfoldÚunbindÚ	unsqueezeÚvsplitÚhsplitÚsplit_with_sizesÚswapaxesÚswapdimsÚchunkÚ	_VIEW_OPSÚrandintÚrandnÚrandÚ
randn_likeÚ	rand_likeÚrandint_likeÚarangeÚ	ones_likeÚ
zeros_likeÚ_CREATE_OPSÚ_IGNORE_OPSÚfloatÚintr   r$   r5   r.   rB   © r   r   ú<module>r{      s#  ðØ €€€Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ Fðð ð ð ð ð ð ð ð 0Ð /Ð /Ð /Ð /Ð /à 'Ð 'Ð 'Ð 'Ð 'Ð 'ð „y„~€àˆzàŒØŒØŒØŒð	ñô €ð ˆJð ØŒð àŒð ð 	Œð ð 	Œ	ð	 ð
 	Œð ð 	Ôð ð 	Œ
ð ð 	Œð ð 	Œð ð 	Œð ð 	Œð ð 	Œð ð 	Œð ð 	Œð ð 	Œð ð  	Œð! ð" 	Œð# ð$ 	Œð% ð& 	Œ	ð' ð( 	Œ	ð) ð* 	Œð+ ð, 	Œð- ð. 	Œð/ ð0 	Œð1 ð2 	Œð3 ð4 	Œð5 ð6 	Œð7 ð8 	Ôð9 ð: 	Œð; ð< 	Œð= ð> 	Œ
ð? ñ"ô "€	ðH ˆjàŒØŒ
ØŒ	ØŒØŒØÔØŒØŒØŒð
ñô €ð ˜+Ñ%€ð	2�u˜s‘{ð 	2¨=ð 	2¸Uð 	2ð 	2ð 	2ð 	2ð ;?ðð à
ðð ð ð ðD)�U”\ð ) cð )ð )ð )ð )ð&°eð ð ð ð ð ð r   