
    ȅiw                        % S SK r S SKrS SKJr  S SKJr  S SKJr  / SQr\" S/ SQ5      r	 " S S	5      r
 " S
 S\ R                  5      r " S S\5      r " S S\5      r " S S5      r0 r\\\4   \S'   \" 5       q\\S'   S%S\S\S-  4S jjrS\4S jrS rS&S\4S jjr\" S\S9S%S j5       rS'S\S\S\4S  jjr\" S!\S9S\S\S\4S" j5       rS#\4S$ jrg)(    N)
namedtuplewraps)
deprecated)MetricsConfigMetricHandlerConsoleMetricHandlerNullMetricHandlerMetricStream	configure	getStreamprofprofile
put_metricpublish_metricget_elapsed_time_ms
MetricDatar   )	timestamp
group_namenamevaluec                   <    \ rS rSrS/rSS\\\4   S-  4S jjrSrg)r   $   paramsNc                 :    Xl         U R                   c  0 U l         g g Nr   )selfr   s     _/home/james-whalen/.local/lib/python3.13/site-packages/torch/distributed/elastic/metrics/api.py__init__MetricsConfig.__init__'   s    ;;DK     r   r   )	__name__
__module____qualname____firstlineno__	__slots__dictstrr    __static_attributes__ r"   r   r   r   $   s'    
ItCH~4  r"   r   c                   @    \ rS rSr\R
                  S\4S j5       rSrg)r   -   metric_datac                     g r   r+   r   r.   s     r   emitMetricHandler.emit.   s    r"   r+   N)	r#   r$   r%   r&   abcabstractmethodr   r1   r*   r+   r"   r   r   r   -   s!    
  r"   r   c                   "    \ rS rSrS\4S jrSrg)r	   3   r.   c           
          [        SUR                   SUR                   SUR                   SUR                   35        g )N[z][z]: =)printr   r   r   r   r0   s     r   r1   ConsoleMetricHandler.emit4   sD    %%&b)?)?(@KDTDTCUUVWbWhWhVij	
r"   r+   Nr#   r$   r%   r&   r   r1   r*   r+   r"   r   r	   r	   3   s    

 
r"   r	   c                   "    \ rS rSrS\4S jrSrg)r
   :   r.   c                     g r   r+   r0   s     r   r1   NullMetricHandler.emit;   s    r"   r+   Nr<   r+   r"   r   r
   r
   :   s    
 r"   r
   c                   8    \ rS rSrS\S\4S jrS\S\4S jrSr	g	)
r   ?   r   handlerc                     Xl         X l        g r   r   rC   )r   r   rC   s      r   r    MetricStream.__init__@   s    $r"   metric_namemetric_valuec                     U R                   R                  [        [        R                  " 5       U R                  X5      5        g r   )rC   r1   r   timer   )r   rG   rH   s      r   	add_valueMetricStream.add_valueD   s*    tyy{DOO[O	
r"   rE   N)
r#   r$   r%   r&   r)   r   r    intrK   r*   r+   r"   r   r   r   ?   s(    3  
S 
 
r"   r   _metrics_map_default_metrics_handlerrC   groupc                 "    Uc  U q g U [        U'   g r   )rO   rN   )rC   rP   s     r   r   r   O   s    } $+ %Ur"   c                 L    [         R                  U [        5      n[        X5      $ r   )rN   getrO   r   )rP   rC   s     r   r   r   Y   s     u&>?G''r"   c                     U R                   nUR                  S5      n[        U5      S:X  a5  U R                  nU(       a  UR                  S5      S   S-   US   -   $ US   $ U$ )N.   r   )r%   splitlenr$   )fnqualnamerX   modules       r   _get_metric_namer]   ^   s`    HNN3E
5zQ<<$R(3.q998Or"   c                 2   ^ U4S jnU (       a  U" U 5      $ U$ )a  
@profile decorator publishes duration.ms, count, success, failure metrics for the function that it decorates.

The metric name defaults to the qualified name (``class_name.def_name``) of the function.
If the function does not belong to a class, it uses the leaf module name instead.

Usage

::

 @metrics.prof
 def x():
     pass


 @metrics.prof(group="agent")
 def y():
     pass
c                 4   >^  [        T 5      U U4S j5       nU$ )Nc                  (  > [        T5      n [        R                  " 5       nT" U 0 UD6n[        U S3ST5         [        U S3[	        U5      T5        U$ ! [         a    [        U S3ST5        e f = f! [        U S3[	        W5      T5        f = fNz.successrV   z.failurez.duration.ms)r]   rJ   r   	Exceptionr   )argskwargskeystartresultfrP   s        r   wrapper#prof.<locals>.wrap.<locals>.wrapper   s    "1%CT		D+F+cU(+Q6
 cU,/1DU1KUSM  cU(+Q6 cU,/1DU1KUSs   -A A33A6 6Br   )rh   ri   rP   s   ` r   wrapprof.<locals>.wrap   s     	q	 
	 r"   r+   )rZ   rP   rk   s    ` r   r   r   k   s    *" 
Bxr"   zDeprecated, use `@prof` instead)categoryc                    ^  U 4S jnU$ )z
@profile decorator adds latency and success/failure metrics to any given function.

Usage

::

 @metrics.profile("my_metric_group")
 def some_function(<arguments>):
c                 4   >^  [        T 5      U U4S j5       nU$ )Nc            	      b  >  [         R                   " 5       nT" U 0 UD6n[        TTR                   S3S5         [        TTR                   S3[	        U5      5        U$ ! [         a    [        TTR                   S3S5        e f = f! [        TTR                   S3[	        W5      5        f = fra   )rJ   r   r#   rb   r   )rc   rd   
start_timerg   funcrP   s       r   ri   &profile.<locals>.wrap.<locals>.wrapper   s    !YY[
t.v.ux&@!D }}o\2'
3	 M  ux&@!D
 }}o\2'
3	s   7A   &BB	 	%B.r   )rr   ri   rP   s   ` r   rk   profile.<locals>.wrap   s     	t	 
	& r"   r+   )rP   rk   s   ` r   r   r      s    . Kr"   rG   rH   metric_groupc                 8    [        U5      R                  X5        g)z{
Publish a metric data point.

Usage

::

 put_metric("metric_name", 1)
 put_metric("metric_name", 1, "metric_group_name")
Nr   rK   )rG   rH   ru   s      r   r   r      s     l%%k@r"   zMDeprecated, use `put_metric(metric_group)(metric_name, metric_value)` insteadc                 <    [        U 5      nUR                  X5        g r   rw   )ru   rG   rH   metric_streams       r   r   r      s    
 l+MK6r"   start_time_in_secondsc                 L    [         R                   " 5       n[        X-
  S-  5      $ )z<Return the elapsed time in millis from the given start time.i  )rJ   rM   )rz   end_times     r   r   r      s     yy{H0D899r"   r   )Ntorchelastic)r}   ) r3   rJ   collectionsr   	functoolsr   typing_extensionsr   __all__r   r   ABCr   r	   r
   r   rN   r(   r)   __annotations__rO   r   r   r]   r   FutureWarningr   rM   r   r   floatr   r+   r"   r   <module>r      s=     "  (  &RS
 CGG 
= 
 

 
 *,d3%& +*;*= - =&} &S4Z &(S (

) )X -F# G#LAC As A# A S7 73 7c 7	7
:u :r"   