
    [Th,                        % S SK r S SKrS SKJ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\\   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)Optional)
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      4S jjrSr	g)r   %   paramsNc                 :    Xl         U R                   c  0 U l         g g Nr   )selfr   s     ]/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributed/elastic/metrics/api.py__init__MetricsConfig.__init__(   s    ;;DK     r   r   )
__name__
__module____qualname____firstlineno__	__slots__r   dictstrr!   __static_attributes__ r#   r    r   r   %   s'    
IxS#X7  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   r2   r+   r,   r#   r    r	   r	   .   s!    
  r#   r	   c                   "    \ rS rSrS\4S jrSrg)r
   4   r/   c           
          [        SUR                   SUR                   SUR                   SUR                   35        g )N[z][z]: =)printr   r   r   r   r1   s     r    r2   ConsoleMetricHandler.emit5   sD    %%&b)?)?(@KDTDTCUUVWbWhWhVij	
r#   r,   Nr$   r%   r&   r'   r   r2   r+   r,   r#   r    r
   r
   4   s    

 
r#   r
   c                   "    \ rS rSrS\4S jrSrg)r   ;   r/   c                     g r   r,   r1   s     r    r2   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   rD   )r   r   rD   s      r    r!   MetricStream.__init__A   s    $r#   metric_namemetric_valuec                     U R                   R                  [        [        R                  " 5       U R                  X5      5        g r   )rD   r2   r   timer   )r   rH   rI   s      r    	add_valueMetricStream.add_valueE   s*    tyy{DOO[O	
r#   rF   N)
r$   r%   r&   r'   r*   r	   r!   intrL   r+   r,   r#   r    r   r   @   s(    3  
S 
 
r#   r   _metrics_map_default_metrics_handlerrD   groupc                 "    Uc  U q g U [        U'   g r   )rP   rO   )rD   rQ   s     r    r   r   P   s    } $+ %Ur#   c                 L    U [         ;   a
  [         U    nO[        n[        X5      $ r   )rO   rP   r   )rQ   rD   s     r    r   r   Z   s$    u%*''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]   b   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]   rK   r   	Exceptionr   )argskwargskeystartresultfrQ   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   rQ   s   ` r    wrapprof.<locals>.wrap   s     	q	 
	 r#   r,   )rZ   rQ   rk   s    ` r    r   r   o   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   )rK   r   r$   rb   r   )rc   rd   
start_timerg   funcrQ   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   rQ   s   ` r    rk   profile.<locals>.wrap   s     	t	 
	  r#   r,   )rQ   rk   s   ` r    r   r      s    ( Kr#   rH   rI   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   rL   )rH   rI   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   rH   rI   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  )rK   rN   )rz   end_times     r    r   r      s     yy{H0D899r#   r   )Ntorchelastic)r}   )"r4   rK   collectionsr   	functoolsr   typingr   typing_extensionsr   __all__r   r   ABCr	   r
   r   r   rO   r)   r*   __annotations__rP   r   r   r]   r   FutureWarningr   rN   r   r   floatr   r,   r#   r    <module>r      s@     "   (  &RS
 CGG 
= 
 

 
 *,d3%& +*;*= - =&} &Xc] &(S (
) )X -F  G FAC As A# A S7 73 7c 7	7
:u :r#   