o
    Ti                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ ejejej	ej
ejdZG dd dZejdejdZe ddd	 Zee_d
d ZdejfddZdddZdd Zdd ZdS )    N)required_torch_version)debuginfowarningerrorcriticalc                   @   s    e Zd ZedejfddZdS )LoggerFactoryNc           	      C   s   | du rt dtd}t| }|| d|_tjtjd}|| |	| |
| tddrctdd	d
krcdd tdddD }h d| }|D ]}t||}tjjj| qS|S )zcreate a logger

        Args:
            name (str): name of the logger
            level: level of logger

        Raises:
            ValueError is name is None
        Nzname for logger cannot be NonezP[%(asctime)s] [%(levelname)s] [%(filename)s:%(lineno)d:%(funcName)s] %(message)sF)streamg@)min_versionDISABLE_LOGS_WHILE_COMPILING01c                 S   s   h | ]}|  qS  )strip).0itemr   r   K/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/utils/logging.py	<setcomp>2   s    z.LoggerFactory.create_logger.<locals>.<setcomp>&LOGGER_METHODS_TO_EXCLUDE_FROM_DISABLE ,>   r   r   r   r   r   	exceptionisEnabledFor)
ValueErrorlogging	Formatter	getLoggersetLevel	propagateStreamHandlersysstdoutsetFormatter
addHandlerr   osgetenvsplitgetattrtorch_dynamoconfigignore_logger_methodsadd)	namelevel	formatterlogger_chexcluded_set
ignore_setmethodoriginal_loggerr   r   r   create_logger   s&   






zLoggerFactory.create_logger)__name__
__module____qualname__staticmethodr   INFOr6   r   r   r   r   r      s    r   	DeepSpeed)r-   r.   c                  O   s   t j| i | dS )a  
    This method is identical to `logger.warning()`, but will emit the warning with the same message only once

    Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the cache.
    The assumption here is that all warning messages are unique across the code. If they aren't then need to switch to
    another type of cache that includes the caller frame information in the hashing function.
    N)loggerr   )argskwargsr   r   r   warning_once@   s   	r@   c              
   C   sP   t d| tt| D ]}ddt|  }t d||t| | qd S )Nz{}:.   z
  {} {} {})r=   r   formatsortedvarslenr'   )r>   r-   argdotsr   r   r   print_configurationO   s
   rI   c                 C   s|   ddl m} 	 |  }|pg }| r| nd}|r,|s,|d dk}|p+|t|v }|r<d|| }t|| d S d S )Nr   commz[Rank {}] {})	deepspeedrK   is_initializedget_ranksetrC   r=   log)messageranksr.   dist
should_logmy_rankfinal_messager   r   r   log_distV   s   
rX   c                 C   s   ddl m} 	 |  }|pg }| r| nd}|r,|s,|d dk}|p+|t|v }|rY|| d< dd l}t|d}|| | t	| W d    d S 1 sRw   Y  d S d S )Nr   rJ   rL   rankw)
rM   rK   rN   rO   rP   jsonopendumpr$   fsync)rR   rS   pathrT   rU   rV   r[   outfiler   r   r   print_json_distn   s    
"ra   c                   C   s   t  S )z+
    Return logger's current log level
    )r=   getEffectiveLevelr   r   r   r   get_current_level   s   rc   c                 C   sD   t | tst|  d|  } | tvrt|  dt t|  kS )aH  
    Args:
        max_log_level_str: maximum log level as a string

    Returns ``True`` if the current log_level is less or equal to the specified log level. Otherwise ``False``.

    Example:

        ``should_log_le("info")`` will return ``True`` if the current log level is either ``logging.INFO`` or ``logging.DEBUG``
    z is not a stringz! is not one of the logging levels)
isinstancestrr   lower
log_levelsrc   )max_log_level_strr   r   r   should_log_le   s   
ri   )NN)	functoolsr   r    r$   r(   deepspeed.utils.torchr   DEBUGr;   WARNINGERRORCRITICALrg   r   r6   r=   	lru_cacher@   rI   rX   ra   rc   ri   r   r   r   r   <module>   s,   	'

