
    9i%                         S SK r S SKrS SKJrJr  S SKJrJrJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKJrJr  S	S
KJr   " S S\5      r\R.                  " SS9 " S S\5      5       rg)    N)ABCabstractmethod)CallableDictOptional)check_local_model_is_latest)snapshot_download)TRAINERS)Config)Invoke
ThirdParty   )	LogBufferc                   x    \ rS rSrSrSS\S\\   4S jjr  SS jr	\
S 5       r\
S	\S
\\\4   4S j5       rSrg)BaseTrainer   zBase 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                 2   [         R                  " U5      U l        U(       a!  U R                  R                  U5      U l        OSU l        [        5       U l        [        5       U l        [        R                  " S[        R                  " 5       5      U l        g)zTrainer 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      X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/trainers/base.py__init__BaseTrainer.__init__   sb     ##H-((6DIDI#+$-K!8HI    c                    [         R                  R                  U5      (       a  [         R                  R                  U5      (       a  UO[         R                  R	                  U5      n[        U[        R                  [        R                  [        R                  U0S9  U$ [        UU[        R                  [        R                  [        R                  U0S9nU$ )a  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_dir%BaseTrainer.get_or_download_model_dir(   s     77>>%  ')ww}}( (eGGOOE2 'JJ 4 4NNK  0'JJNNKO r$   c                     g)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!   trainBaseTrainer.trainG   s     	r$   checkpoint_pathreturnc                     g)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
Nr8   )r    r<   r   r9   s       r!   evaluateBaseTrainer.evaluateQ   s     	r$   )r   r   r   r   r   N)NN)__name__
__module____qualname____firstlineno____doc__strr   r   r"   r4   r   r:   r   floatr@   __static_attributes__r8   r$   r!   r   r      so    J JHX4F J$ 26.2>    "3:. r$   r   dummy)module_namec                   X   ^  \ rS rSrS\4U 4S jjrS r S	S\S\\\4   4S jjr	Sr
U =r$ )
DummyTrainer]   r   c                 $   > [         TU ]  U5        g)z@Dummy Trainer.

Args:
    cfg_file: Path to configuration file.
N)superr"   )r    r   r   r9   	__class__s       r!   r"   DummyTrainer.__init__`   s     	"r$   c                 L    U R                   R                  n[        SU 35        g)r7   z
train cfg N)r   r:   print)r    r   r9   r   s       r!   r:   DummyTrainer.trainh   s      hhnn
3% !r$   r<   r=   c                 h    U R                   R                  n[        SU 35        [        SU 35        g)r?   z	eval cfg zcheckpoint_path N)r   
evaluationrU   )r    r<   r   r9   r   s        r!   r@   DummyTrainer.evaluater   s3     hh!!	#   123r$   r8   rB   )rC   rD   rE   rF   rH   r"   r:   r   rI   r@   rJ   __classcell__)rR   s   @r!   rN   rN   ]   s>    # #" )-4"%4 #3:.4 4r$   rN   )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_modulerN   r8   r$   r!   <module>rd      s]    
  # + + B > 0 * 8 'J# JZ 
g. 4;  4 / 4r$   