
    Χgc                         d Z ddlZddlZddlZddlZddlmc mZ  G d d          Z	d Z
edk    r e
             dS dS )zAExample of Timer and Compare APIs:

$ python -m examples.compare
    Nc                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )		FauxTorchzEmulate different versions of pytorch.

    In normal circumstances this would be done with multiple processes
    writing serialized measurements, but this simplifies that model to
    make the example clearer.
    c                 "    || _         || _        d S N)_real_torch_extra_ns_per_element)self
real_torchextra_ns_per_elements      b/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/utils/benchmark/examples/compare.py__init__zFauxTorch.__init__   s    %%9"""    c                     t          |                                          }|dk    rt          j        || j        z  dz             |S )Ni  g&.>)intnumeltimesleepr   )r	   resultr   s      r   extra_overheadzFauxTorch.extra_overhead   sD     FLLNN##4<<Jut99D@AAAr   c                 L    |                       | j        j        |i |          S r   )r   r   addr	   argskwargss      r   r   zFauxTorch.add#   ,    ""#74#3#7#H#H#HIIIr   c                 L    |                       | j        j        |i |          S r   )r   r   mulr   s      r   r   zFauxTorch.mul&   r   r   c                 L    |                       | j        j        |i |          S r   )r   r   catr   s      r   r   zFauxTorch.cat)   r   r   c                 L    |                       | j        j        |i |          S r   )r   r   matmulr   s      r   r!   zFauxTorch.matmul,   s,    ""#:4#3#:D#KF#K#KLLLr   N)
__name__
__module____qualname____doc__r   r   r   r   r   r!    r   r   r   r      s         : : :  J J JJ J JJ J JM M M M Mr   r   c            	         ddgg } d}fddD             }t          ||z            D ]\  }}|                     t          j        |                    d                               t          d|d	z    d
t          |          |z   d           t          j        	                                 t                       t          j        d | D                       }t          d           |                                 t          d           |                                 |                                 |                                 d S )N)r   r   ztorch.add(x, y))r   zadd (extra +0)ztorch.add(x, y + zero)   c                 2   g | ]\  }}D ]\  }}}d D ]}dD ]}}t          j        ||dk    rt          nt          t          |          t          j        |df          t          j        d          t          j        d          d||d| ||          ~S ))   
   d   i  i'  iP  )r*      masterr-   r&   )torchxyzerozsize: )stmtglobalslabel	sub_labeldescriptionenvnum_threads)benchmark_utilsTimerr/   r   oneszeros)	.0branchoverhead_nsr5   r6   r3   sizer9   taskss	           r   
<listcomp>zmain.<locals>.<listcomp>8   s         FK&+!   #E9d4# " !% $ # 	"(H"4"4)E;:W:WZq	**Z''B	  '#	
 	
 	
     r   ))r.   N)	my_branchr*   )severe_regression   g?)min_run_timer*   z /  )endc                 6    g | ]}t          j        |          S r&   )pickleloads)r>   is     r   rC   zmain.<locals>.<listcomp>U   s-     * * *Q* * *r   z== Unformatted ================================================================================
///////////////////////////////////////////////////////////////////////////////////////////////
z== Formatted ================================================================================
/////////////////////////////////////////////////////////////////////////////////////////////
)	enumerateappendrL   dumpsblocked_autorangeprintlensysstdoutflushr:   Comparetrim_significant_figurescolorize)serialized_resultsrepeatstimersrN   timer
comparisonrB   s         @r   mainr`   0   s   );E
 G    $b  F* fw.//  5!!&,###66#
 #
 	 	 	 	41q544S[[7244"====
	GGG ( * *!3* * *  J 

?@@@	
=>>>'')))r   __main__)r%   rL   rU   r   r/   torch.utils.benchmarkutils	benchmarkr:   r   r`   r"   r&   r   r   <module>re      s    
  



   / / / / / / / / /M M M M M M M M@/ / /d zDFFFFF r   