
    Vh                     R   U d dl Z d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dlmc mZ d dlmZ  ej                          Zg Zee   ed<    ej,                  e      a ed      Z ed      Zd	eeef   fd
Zd	eeef   fdZ	 ddeded	eeeef   geeef   f   fdZdefdZ y)    N)AnyCallableTypeVar)	ParamSpec)uuid4)DCP_LOGGER_NAME__all___T_Preturnc                     i }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|s|xs |x}rt        |dd      }|t        |      n||d<   t        t               j                        |d<   |r|j
                  j                  |d<   |r|j
                  j                  |d<   |r|j
                  j                  |d<   |S )z0
    Extracts log data from dcp method args
    storage_writerNstorage_readerplannercheckpoint_iduuid)getgetattrstrr   int	__class____name__)argskwargsmsg_dictr   r   r   r   
serializers           S/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributed/checkpoint/logger.py_msg_dict_from_dcp_method_argsr      s     H ZZ 0$7NZZ 0$7NjjD)GJJ5MN,LnLjL
OTB ,7M] _
 57;;'HV%3%=%=%F%F!"%3%=%=%F%F!"%//88O    c                 l    t        |i |}|j                  t        j                  | g|i |       |S )N)r   updatec10d_logger_get_msg_dict)	func_namer   r   r   s       r   r#   r#   ;   s7    -t>v>HOOK--iI$I&IJOr   log_exceptionswrapper_kwargsc                 >     dt         t        t        f   f fd}|S )zKThis method decorator logs the start, end, and exception of wrapped events.funcc                      t        j                         dt        j                  dt        j                  dt
        f fd       }|S )Nr   r   r   c                     t        j                  g| i i 	|}d|d<   t        j                         }||d<   |d<   t        j                  |       	  | i |}d|d<   t        j                         }t        j                         |d<   ||z
  |d<   t        j                  |       |S # t        $ r?}r7d|d<   | |d<   t        j                         |d<   t        j                  |        d }~ww xY w)	Nstarteventtimer%   	exceptionerrorendtimes_spent)r#   r   r-   time_ns_dcp_loggerdebugBaseExceptionr/   )
r   r   r   t0resultr/   t1r(   r%   r&   s
          r   wrapperz6_dcp_method_logger.<locals>.decorator.<locals>.wrapperH   s   $ $(D>(DV(DH
 !(HWB!HV)7H%&h't.v. !&HWB#||~HV&(2gH]#h'M ! !(3HW%+0'HW%'+||~HV$%%h/s   B/ /	C78:C22C7)	functoolswrapsr   r   r   r
   )r(   r9   r%   r&   s   ` r   	decoratorz%_dcp_method_logger.<locals>.decoratorG   sC    			277 	bii 	B 	 
	@ r   )r   r   r
   )r%   r&   r<   s   `` r   _dcp_method_loggerr=   B   s!    
"R( "H r   rankc                 .   t         j                  t        j                         t        j                         }|j                  t        j                         t        j
                  d|  d      }|j                  |       t         j                  |       y )N[z6] %(asctime)s - %(name)s - %(levelname)s - %(message)s)loggersetLevelloggingINFOStreamHandler	FormattersetFormatter
addHandler)r>   ch	formatters      r   _init_loggerrK   n   si    
OOGLL!				 BKK!!
D6GHI OOI
br   )F)!r:   rC   r-   typingr   r   r   typing_extensionsr   r   r   torch.distributed.c10d_loggerdistributedr"   -torch.distributed.checkpoint.logging_handlersr   	getLoggerrA   r	   listr   __annotations___get_or_create_loggerr3   r
   r   dictr   r#   boolr=   r   rK    r   r   <module>rX      s       ) ) '  3 3 I 
			 c  0k//@T]t_tCH~ Dc3h  !))47)xB (2r6"223)Xs r   