
    vj%                         d dl Z d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZ d	d
lmZ  G d de          Z ej        d           G d de                      ZdS )    N)ABCabstractmethod)CallableDictOptional)check_local_model_is_latest)snapshot_download)TRAINERS)Config)Invoke
ThirdParty   )	LogBufferc                       e Zd ZdZddedee         fdZ	 	 ddZe	d             Z
e	ded	eeef         fd
            ZdS )BaseTrainerz Base class for trainer which can not be instantiated.

    BaseTrainer defines necessary interface
    and provide default implementation for basic initialization
    such as parsing config file and parsing commandline args.
    Ncfg_filearg_parse_fnc                 ,   t          j        |          | _        |r | j                            |          | _        nd| _        t                      | _        t                      | _        t          j	        dt          j
                              | _        dS )z Trainer basic init, should be called in derived class

        Args:
            cfg_file: Path to configuration file.
            arg_parse_fn: Same as ``parse_fn`` in :obj:`Config.to_args`.
        Nz%Y%m%d_%H%M%S)r   	from_filecfgto_argsargsr   
log_buffervisualization_buffertimestrftime	localtime	timestamp)selfr   r   s      h/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/trainers/base.py__init__zBaseTrainer.__init__   st     #H-- 	((66DIIDI#++$-KK!8H8HII    c                    t           j                            |          rtt           j                            |          r|nt           j                            |          }t          |t          j        t          j        t          j        |i           n4t          ||t          j        t          j        t          j        |i          }|S )aH   Get local model directory or download model if necessary.

        Args:
            model (str): model id or path to local model directory.
            model_revision  (str, optional): model version number.
            third_party (str, optional): in which third party library
                this function is called.
        )
user_agent)revisionr$   )ospathexistsisdirdirnamer   r   KEYLOCAL_TRAINERr   r	   TRAINER)r   modelmodel_revisionthird_partymodel_cache_dirs        r    get_or_download_model_dirz%BaseTrainer.get_or_download_model_dir(   s     7>>%   	')w}}( ( 3eeGOOE22 'J 4NK     0'JNK  O r"   c                     dS ) Train (and evaluate) process

        Train process should be implemented for specific task or
        model, related parameters have been initialized in
        ``BaseTrainer.__init__`` and should be used in this function
        N )r   r   kwargss      r    trainzBaseTrainer.trainG   s	     	r"   checkpoint_pathreturnc                     dS ) Evaluation process

        Evaluation process should be implemented for specific task or
        model, related parameters have been initialized in
        ``BaseTrainer.__init__`` and should be used in this function
        Nr5   )r   r8   r   r6   s       r    evaluatezBaseTrainer.evaluateQ   s	     	r"   N)NN)__name__
__module____qualname____doc__strr   r   r!   r2   r   r7   r   floatr<   r5   r"   r    r   r      s         J J JHX4F J J J J$ 26.2   >   ^  "3:.   ^  r"   r   dummy)module_namec                   N     e Zd Zdef fdZd Z	 ddedeeef         fdZ xZ	S )	DummyTrainerr   c                 J    t                                          |           dS )zY Dummy Trainer.

        Args:
            cfg_file: Path to configuration file.
        N)superr!   )r   r   r   r6   	__class__s       r    r!   zDummyTrainer.__init__`   s#     	"""""r"   c                 B    | j         j        }t          d|            dS )r4   z
train cfg N)r   r7   print)r   r   r6   r   s       r    r7   zDummyTrainer.trainh   s*     hn 3  !!!!!r"   Nr8   r9   c                 f    | j         j        }t          d|            t          d|            dS )r;   z	eval cfg zcheckpoint_path N)r   
evaluationrL   )r   r8   r   r6   r   s        r    r<   zDummyTrainer.evaluater   sB     h!#   22233333r"   r=   )
r>   r?   r@   rB   r!   r7   r   rC   r<   __classcell__)rJ   s   @r    rG   rG   ]   s        # # # # # # #" " " )-4 4"%4 #3:.4 4 4 4 4 4 4 4r"   rG   )r&   r   abcr   r   typingr   r   r   modelscope.hub.check_modelr    modelscope.hub.snapshot_downloadr	   modelscope.trainers.builderr
   modelscope.utils.configr   modelscope.utils.constantr   r   utils.log_bufferr   r   register_modulerG   r5   r"   r    <module>rY      sE   
			  # # # # # # # # + + + + + + + + + + B B B B B B > > > > > > 0 0 0 0 0 0 * * * * * * 8 8 8 8 8 8 8 8 ' ' ' ' ' 'J J J J J# J J JZ g... 4  4  4  4  4;  4  4 /. 4  4  4r"   