Ë
    ÌÓ^j  ã                   ó
  — 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j0                  ‘ej2                  ‘ej4                  ‘ej6                  ‘ej8                  ‘ej:                  ‘ej<                  ‘ej>                  ‘ej@                  ‘ejB                  ‘ejD                  ‘ejF                  ‘ejH                  ‘ejJ                  ‘ejL                  ‘ejN                  ‘ejP                  ‘ejR                  ‘ejT                  ‘ejV                  ‘ejX                  ‘ejZ                  ‘ej\                  ‘ej^                  ‘ej`                  ‘«      Z1 eejd                  ejf                  ejh                  ejj                  ejl                  ejn                  ejp                  ejr                  ejt                  g	«      Z;e1e;z  Z<de=e>z  dd	d
e=fd„Z?	 dd
e=fd„Z@de j‚                  d
e>fd„ZBd
e=fd„ZCy)é    N)Úget_device_tflopsÚget_gpu_dram_gbps)Úoptimization_hintÚstatically_known_true)Ú
OrderedSeté   )Úflop_registryÚflopsÚdtypeztorch.dtypeÚreturnc                 óJ   — t        |«      dz  }|dk(  ry| 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       új/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/utils/_runtime_estimation.pyÚflops_to_nsr   M   s<   € ô
 ' uÓ-°Ñ4€NØ˜ÒØØ�1‰9€DØ�D˜>Ñ)Ñ*¨cÑ1Ð1ó    c                 óÊ   — | t         v r[t        |«      dk7  rt        d|› d| › �«      ‚|j                  «       }t         |    }i }|�||d<    ||i |¤d|i¤|¤Ž}	t	        |	|«      S y)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 Ú
_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ÒÜ Ø4°Z°LÀÀkÀ]ÐSóð ð —‘Ó ˆÜ'¨Ñ4ˆØˆØÐ Ø)2ˆL˜Ñ&Ù$ dÐR¨fÑR¸cÑRÀ\ÑRˆ
Ü˜: uÓ-Ð-Ør   Útc                 óÂ   — d}t        | j                  | j                  «       «      D ]$  \  }}t        |dk(  «      rŒ|t	        |d¬«      z  }Œ& || j                  «       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.   {   s_   € ð €JÜ˜AŸG™G Q§X¡X£ZÓ0ò >‰ˆˆfä$ V¨q¡[Õ1ØÔ+¨D¸1Ô=Ñ=‰Jð>ð
 ˜Ÿ™Ó(Ñ(Ð(r   c                 óv   — 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                  «      sŒt        |«      –— Œ, y ­w©N©Ú
isinstanceÚtorchÚTensorr.   ©Ú.0r%   s     r   ú	<genexpr>z$get_transfer_time.<locals>.<genexpr>š   s'   è ø€ ò Ø´jÀÄEÇLÁLÕ6QŒ�a×ñùó   ‚2¢2c              3   óh   K  — | ]*  }t        |t        j                  «      sŒt        |«      –— Œ, y ­wr1   r2   r6   s     r   r8   z$get_transfer_time.<locals>.<genexpr>�   s'   è ø€ ò Ø¬z¸!¼U¿\¹\Õ/JŒ�a×ñùr9   )r   Úsum)Úflat_args_kwargsÚ	flat_outsÚgpu_memory_bandwidthÚ
read_bytesÚwrite_bytesÚcounted_bytesÚtransfer_times          r   Úget_transfer_timerC   Ž   sZ   € ô -Ó.ÐÜñ Ø"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.   rC   © r   r   ú<module>r|      sÈ  ðÛ ß F÷õ 0å 'ð ‡y�y‡~�~€áà�‰Ø�‰Ø�‰Ø�‰ð	ó€ñ ð Ø�‰ð à�‰ð ð 	�‰ð ð 	�	‰	ð	 ð
 	�‰ð ð 	×Ñð ð 	�
‰
ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð 	�‰ð ð  	�‰ð! ð" 	�‰ð# ð$ 	�‰ð% ð& 	�	‰	ð' ð( 	�	‰	ð) ð* 	�‰ð+ ð, 	�‰ð- ð. 	�‰ð/ ð0 	�‰ð1 ð2 	�‰ð3 ð4 	�‰ð5 ð6 	�‰ð7 ð8 	×Ñð9 ð: 	�‰ð; ð< 	�‰ð= ð> 	�
‰
ð? ó"€	ñH à�‰Ø�
‰
Ø�	‰	Ø�‰Ø�‰Ø×ÑØ�‰Ø�‰Ø�‰ð
ó€ð ˜+Ñ%€ð	2�u˜s‘{ð 	2¨=ð 	2¸Uó 	2ð ;?ñà
óðD)�U—\‘\ð ) có )ð&°eô r   