o
    ॵi/
                  	   @   s   d dl mZmZmZmZ d dlmZ dddddddd	d
igiZdddddZdefddZ	dedee fddZ
dedefddZdedededee fddZdedededefddZdedeeef fdd Zd!S )"    )DictListOptionalTuple)Configztrain.hooksCheckpointHook   )typeintervalTextLoggerHook
   r	   IterTimerHookztrain.loggingztrain.checkpoint.periodztrain.checkpoint.bestzevaluation.period)r   r   BestCkptSaverHookEvaluationHookcfgc                 C   s   | j tdd dS )zMerge the default config into the input cfg.

    This function will pop the default CheckpointHook when the BestCkptSaverHook exists in the input cfg.

    Aegs:
        cfg: The input cfg to be merged into.
    FforceN)merge_from_dictDEFAULT_HOOKS_CONFIG)r    r   V/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/trainers/default_config.py	merge_cfg   s   r   returnc                 C   sF   t | jdg  }t D ]\}}t| ||}|d ur || q|S )Nhooks)getattrtraincopy_HOOK_KEY_CHAIN_MAPitems_key_chain_to_hookappend)r   r   	hook_type	key_chainhookr   r   r   merge_hooks&   s   
r$   c                 C   sx   d| j vr| S i }| j jD ]}|sqt|\}}|tvrq||t| < |  qttt| j j| j _| j|dd | S )Nr   Fr   )	r   r   _hook_splitr   clearlistfilterboolr   )r   key_chain_mapr#   keyvaluer   r   r   
update_cfg/   s   

r-   r"   r!   c                 C   s0   t | ||sd S | |}d|i}|| |S Nr	   )_check_basic_hooksafe_getupdate)r   r"   r!   hook_paramsr#   r   r   r   r   @   s   

r   c                    sX   |  |d u r	dS tt fddt| jdg }t|dks*J d| d  dd	S )
NFc                    s   | d  kS r.   r   r#   r!   r   r   <lambda>N   s    z#_check_basic_hook.<locals>.<lambda>r   r   zThe key_chain zG and the traditional hook cannot exist at the same time, please delete z in the configuration file.T)r0   r'   r(   r   r   len)r   r"   r!   r   r   r4   r   r/   J   s   
r/   r#   c                 C   s   |   } | d| fS r.   )r   popr3   r   r   r   r%   V   s   r%   N)typingr   r   r   r   modelscope.utils.configr   r   r   r   r$   r-   strr   r)   r/   r%   r   r   r   r   <module>   s8   	


