
    IЦi                         % S SK r S SKJrJrJrJrJr  S SKJr  \\	\	\\
\4   \\\      \\   /S4   r\\S'    " S S5      rg)    N)AnyCallableDictOptionalType)	TypeAlias
OnExitTypec                       \ rS rSrS\4S jrSS jrS\\\	      S\\	   S\
SS	4S
 jrS\4S jrS\S\SS	4S jrS\S\
SS	4S jrS\S\S\
SS	4S jrS\\\
4   SS	4S jrS\\\
4   SS	4S jrS\S\
SS	4S jrSrg	)MetricsContext   on_exitc                 :    Xl         0 U l        SU l        SU l        g)a)  
Use this class as a contextmanager to create a context under which to accumulate
a set of metrics, e.g., metrics gathered during a compilation. On exit of the
contextmanager, call the provided 'on_exit' function and pass a dictionary of
all metrics set during the lifetime of the contextmanager.
r   N)_on_exit_metrics_start_time_ns_level)selfr   s     \/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/_dynamo/metrics_context.py__init__MetricsContext.__init__   s      (*#$    returnc                     U R                   S:X  a!  0 U l        [        R                  " 5       U l        U =R                   S-  sl         U $ )z
Initialize metrics recording.
r      )r   r   timetime_nsr   r   s    r   	__enter__MetricsContext.__enter__   s8     ;;!DM"&,,.Dqr   exc_type	exc_value
_tracebackNc                     U =R                   S-  sl         U R                   S:  d   eU R                   S:X  a=  [        R                  " 5       nU R                  U R                  X@R
                  X5        gg)z.
At exit, call the provided on_exit function.
r   r   N)r   r   r   r   r   r   )r   r    r!   r"   end_time_nss        r   __exit__MetricsContext.__exit__%   s]     	q{{a;;!,,.KMM##[-- r   c                      U R                   S:  $ )z$
True if we've entered the context.
r   )r   r   s    r   in_progressMetricsContext.in_progress6   s     {{Qr   metricvaluec                     U R                   S:X  a  [        SU S35      eXR                  ;  a  SU R                  U'   U R                  U==   U-  ss'   g)z'
Increment a metric by a given amount.
r   zCannot increment  outside of a MetricsContextNr   RuntimeErrorr   r   r*   r+   s      r   	incrementMetricsContext.increment<   sR     ;;!!26(:VWXX&$%DMM&!f&r   c                     U R                   S:X  a  [        SU S35      eXR                  ;   a  [        SU S35      eX R                  U'   g)zj
Set a metric to a given value. Raises if the metric has been assigned previously
in the current context.
r   Cannot set r-   zMetric 'z-' has already been set in the current contextNr.   r0   s      r   setMetricsContext.setF   sW    
 ;;!VH4PQRR]]"6("OP  !&fr   keyc                     U R                   S:X  a  [        SU S35      eXR                  ;  a  0 U R                  U'   X0R                  U   U'   g)a  
Treats a give metric as a dictionary and set the k and value within it.
Note that the metric must be a dictionary or not present.

We allow this to be called multiple times (i.e. for features, it's not uncommon
for them to be used multiple times within a single compilation).
r   r4   r-   Nr.   )r   r*   r7   r+   s       r   set_key_valueMetricsContext.set_key_valueS   sN     ;;!VH4PQRR&$&DMM&!%*fc"r   valuesc                     U R                   S:X  a  [        S5      eU R                  R                  5       UR                  5       -  nU(       a  [        SU S35      eU R                  R	                  U5        g)z
Set multiple metrics directly. This method does NOT increment. Raises if any
metric has been assigned previously in the current context.
r   1Cannot update metrics outside of a MetricsContextz
Metric(s) z- have already been set in the current contextN)r   r/   r   keysupdate)r   r;   existings      r   r?   MetricsContext.updatea   sj    
 ;;!RSS==%%'&++-7XJ&ST  	V$r   c                 ~    U R                   S:X  a  [        S5      eU R                   S:X  a  U R                  U5        gg)z1
Update, but only when at the outermost context.
r   r=   r   N)r   r/   r?   )r   r;   s     r   update_outerMetricsContext.update_outero   s9     ;;!RSS;;!KK r   c                     U R                   S:X  a  [        SU S35      eXR                  ;  a  [        5       U R                  U'   U R                  U   R	                  U5        g)z(
Records a metric as a set() of values.
r   zCannot add r-   N)r   r/   r   r5   addr0   s      r   
add_to_setMetricsContext.add_to_setx   sV     ;;!VH4PQRR&$'EDMM&!f!!%(r   )r   r   r   r   )r   r   )__name__
__module____qualname____firstlineno__r	   r   r   r   r   BaseExceptionr   r%   boolr(   strintr1   r5   r9   r   r?   rC   rG   __static_attributes__ r   r   r   r      s    

 

4./ M* 	
 
"T ' 'C 'D '&# &c &d &+C +c +# +$ +%T#s(^ % % 4S>  d  ) )S )T )r   r   )r   typingr   r   r   r   r   typing_extensionsr   rP   rO   rM   r	   __annotations__r   rR   r   r   <module>rV      s]     6 6 ' !#tCH~x](;<h}>UV

I t) t)r   