+
    &j                        R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt ^ RI	t	^RI
Ht ]P                   ! R R4      4       t ! R R	4      tR
 R ltR R lt ! R R4      tR R ltR# )aN  
Dynamo profiling implementation.

This module provides profiling functionality for Dynamo, including:
- ProfileMetrics: Class for collecting and aggregating performance metrics like
  execution time, operator counts, and fusion statistics
- ProfileResult: Class for analyzing and reporting profiling results
- Utilities for tracking missed/uncaptured operations
- Functions for instrumenting FX graphs with profiling capabilities

The profiler helps measure and optimize the performance of Dynamo-compiled code
by tracking both captured and total operations, timing, and graph statistics.
)annotationsN)Any)Self)
print_oncec                      ] tR t^t$ RtR]R&   ^ tR]R&   ^ tR]R&   ^ tR]R&   R R	 lt	R
 R lt
R R ltR R ltR R ltRtR# )ProfileMetricsg        floatmicrosecondsint	operatorsfusionsgraphsc                    V ^8  d   QhRRRR/#    otherr   return )formats   "n/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/_dynamo/profiler.py__annotate__ProfileMetrics.__annotate__"         d t     c                	    V ;P                   VP                   ,          un         V ;P                  VP                  ,          un        V ;P                  VP                  ,          un        V # Nr	   r   r   selfr   s   &&r   __iadd__ProfileMetrics.__iadd__"   sB    U///%//)%r   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   )r   s   "r   r   r   (   s     
 
^ 
 
r   c                	    \        V\        4      '       g   Q h\        V P                  VP                  ,           V P                  VP                  ,           V P                  VP                  ,           4      # r   )
isinstancer   r	   r   r   r   s   &&r   __add__ProfileMetrics.__add__(   sV    %0000 2 22NNU__,LL5==(
 	
r   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   0   s     	
 	
 	
 	
r   c           	     	>   \        V\        4      '       d   \        WV4      p\        V P                  \	        ^VP                  4      ,          V P
                  \	        ^VP
                  4      ,          V P                  \	        ^VP                  4      ,          4      # )   )r#   r
   r   r	   maxr   r   r   s   &&r   __truediv__ProfileMetrics.__truediv__0   sq    eS!!"57EAu'9'9 ::NNSEOO44LL3q%--00
 	
r   c                   V ^8  d   QhRR/# r   r   strr   )r   s   "r   r   r   ;   s     J J Jr   c                	>    V P                   R  RV P                  R  R2# )z4.0%z ops z timer   r	   r   s   &r   __str__ProfileMetrics.__str__;   s%    ..&eD,=,=d+C5IIr   c                   V ^8  d   QhRR/# )r   r   zlist[float]r   )r   s   "r   r   r   >   s     3 3{ 3r   c                	2    V P                   V P                  .# r   r0   r1   s   &r   tocsvProfileMetrics.tocsv>   s     1 122r   r   N)__name__
__module____qualname____firstlineno__r	   __annotations__r   r   r   r   r$   r*   r2   r6   __static_attributes__r   r   r   r   r      sH    L%IsGSFCO
	
J3 3r   r   c                  R    ] tR t^BtR R ltR R ltR R ltR R ltR	 R
 ltRt	R# )ProfileResultc               (    V ^8  d   QhRRRRRRRR/# )r   capturedr   totalunique_graphsr
   r   Noner   )r   s   "r   r   ProfileResult.__annotate__C   s,     0 0&0/=0NQ0	0r   c                	v    T;'       g    \        4       V n        T;'       g    \        4       V n        W0n        R # r   )r   rA   rB   rC   )r   rA   rB   rC   s   &&&&r   __init__ProfileResult.__init__C   s.     )1(D(DN4D%*%>%>n.>
"/r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   rE   J   r   r   c                	    V ;P                   VP                   ,          un         V ;P                  VP                  ,          un        V ;P                  VP                  ,          un        V # r   rA   rB   rC   r   s   &&r   r   ProfileResult.__iadd__J   sB    '

ekk!
e111r   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   rE   P   s     * * *r   c                	<    V P                   V P                  ,          # r   )rA   rB   r1   s   &r   percentProfileResult.percentP   s    }}tzz))r   c                   V ^8  d   QhRR/# r-   r   )r   s   "r   r   rE   S   s     
 
 
r   c                	    V P                   R  RV P                  P                  R  RV P                  P                  R RV P                  P                  R R2\        V P                  4       4      ,           # )2z graphs z graph calls 4/z = )rC   rA   r   r   rB   r.   rO   r1   s   &r   r2   ProfileResult.__str__S   sj    !!!$HT]]-A-A!,DM}}&&q)4::+?+?*B#G$,,.!"	
r   c                   V ^8  d   QhRR/# )r   r   	list[Any]r   )r   s   "r   r   rE   Z   s     # #y #r   c                	    V P                   V P                  P                  V P                  P                  V P                  P                  .V P                  4       P                  4       ,           # r   )rC   rA   r   r   rB   rO   r6   r1   s   &r   r6   ProfileResult.tocsvZ   sU    MM  MM##JJ  	

 LLN  "# 	#r   rK   N)
r8   r9   r:   r;   rG   r   rO   r2   r6   r=   r   r   r   r?   r?   B   s     0*
# #r   r?   c                   V ^8  d   QhRR/# )r   r   boolr   )r   s   "r   r   r   c   s     > >d >r   c                 F    \         P                  P                  R 4      R8H  # )TORCHDYNAMO_PRINT_MISSING1)osenvirongetr   r   r   should_print_missingrc   c   s    ::>>56#==r   c                    V ^8  d   QhRRRR/# )r   stackz	list[str]r   rD   r   )r   s   "r   r   r   g   s     3 3 3t 3r   c                
   \         ;QJ d    R  V  4       F  '       g   K   RM	  RM! R  V  4       4      '       d   R# V  Uu. uF  pRV9  g   K  RV9  g   K  VNK  	  p p\        RRP                  V RR 4      4       R# u upi )	c              3  ,   "   T F
  pR V9   x  K  	  R# 5i)z/torch/autograd/profiler.pyNr   ).0xs   & r   	<genexpr> print_missing.<locals>.<genexpr>h   s     
=u!(A-us   TFNz	<built-inzsite-packages/torch/MISSINGz >> )anyr   join)re   ri   s   & r   print_missingrp   g   sv    
s
=u
=sss
=u
===a[16LTU6U5 
  y&++eBCj12s   	B B B c                  >    ] tR t^pt$ ^ tR]R&   R R ltR R ltRtR# )	Profilerr
   rC   c                   V ^8  d   QhRR/# )r   r   rD   r   )r   s   "r   r   Profiler.__annotate__s   s     
 
$ 
r   c                	    \         P                  P                  \         P                  P                  P                  .\        4       R 7      V n        R# ))
activities
with_stackN)torchprofilerprofileProfilerActivityCPUrc   profr1   s   &r   rG   Profiler.__init__s   s9    NN**77;;<+- + 
	r   c                   V ^8  d   QhRR/# )r   r   r?   r   )r   s   "r   r   rt   y   s     .
 .
 .
r   c           	     	4   ^ p^ p^ p^ p^ pRpRp\        V P                  P                  4       R R7      pV EF  p	V	P                  R8X  d+   V	P                  P
                  pV^,          pV^,          pK?  V	P                  P                  V8  d   V	P                  P
                  pV	P                  P
                  V8:  d+   V^,          pW9P                  P                  4       ,          pM%\        4       '       d   \        V	P                  4       V^,          pWYP                  P                  4       ,          pEK  EK	  	  \        P                  p
^ \        n        V^,          p\        \        VVW!,
          VR7      \        VVV^,
          R7      V
R7      # )    c                .    V P                   P                  # r   )
time_rangestart)ri   s   &r   <lambda>"Profiler.results.<locals>.<lambda>   s    !,,:L:Lr   )keyTORCHDYNAMO)r	   r   r   r   r   rK   )sortedr}   eventsnamer   endr   
elapsed_usrc   rp   re   rr   rC   r?   r   )r   captured_regionscaptured_opscaptured_microseconds	total_opstotal_microsecondslast_op_end_timecaptured_region_end_timer   erC   s   &          r   resultsProfiler.resultsy   si    !	#% 		((*0LMAvv&+,<<+;+;( A% Q	##'77#$<<#3#3 <<##'?? A%L)\\-D-D-FF))++!!''*Q	"ll&=&=&??"! $ !..!"Q	#2&$7'	 !/#!A
 (
 	
r   )r}   N)	r8   r9   r:   r;   rC   r<   rG   r   r=   r   r   r   rr   rr   p   s    M3
.
 .
r   rr   c               $    V ^8  d   QhRRRRRR/# )r   gmztorch.fx.GraphModuleexample_inputsrX   r   r   r   )r   s   "r   r   r      s#      0 ) PS r   c                T   a  R  V 3R llp\         ;P                  ^,          un        V# )c                    V ^8  d   QhRRRR/# )r   argsr   r   r   )r   s   "r   r   )fx_insert_profiling.<locals>.__annotate__   s     % % % %r   c                    < \         P                  P                  R 4      ;_uu_ 4        SP                  ! V !  uuRRR4       #   + '       g   i     R# ; i)r   N)rx   ry   record_functionforward)r   r   s   *r   _wrapped%fx_insert_profiling.<locals>._wrapped   s3    ^^++M::::t$ ;:::s   AA	)rr   rC   )r   r   r   s   f& r   fx_insert_profilingr      s%    % % aOr   )__doc__
__future__r   dataclassesr`   typingr   typing_extensionsr   rx   utilsr   	dataclassr   r?   rc   rp   rr   r   r   r   r   <module>r      sf    #  	  "   #3 #3 #3L# #B>37
 7
tr   