
    9iq                     r    S SK JrJrJr  S SKJr  S SKJr   " S S\5      r " S S\5      r	 " S S	\	5      r
g
)    )ActionArgumentDefaultsHelpFormatterArgumentParser)fields)Listc                   h   ^  \ rS rSrSrS
U 4S jjrS r  SS\4U 4S jjjrS
U 4S jjr	S r
S	rU =r$ )CliArgumentParser   zArgument Parser to define and parse command-line args for training.

Args:
    training_args: dict or list of dict which defines different
        parameters for training.
c                 p   > SU;  a	  [         US'   [        TU ]  " S0 UD6  Xl        U R	                  5         g )Nformatter_class )r   super__init__training_argsdefine_args)selfr   kwargs	__class__s      g/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/trainers/cli_argument_parser.pyr   CliArgumentParser.__init__   s8    F*(EF$%"6"*    c                 f    U Vs/ s H  o"R                  S5      (       d  M  USS  PM!     sn$ s  snf )N--   )
startswith)r   argsargs      r   get_manual_args!CliArgumentParser.get_manual_args   s+    #'@4C>>$+?AB4@@@s   .	.r   c                    > Ub  UR                   OS U l        SU;   a  XR                  S5      S-      U l        U R                  U5      U l        [
        TU ]  " X/UQ70 UD6$ )Nz--model   )modelmodel_idindexr   manual_argsr   _parse_known_args)r   r   	namespace
args_extrar   r   s        r   r&   #CliArgumentParser._parse_known_args   sm    
 ,5+@	d I!6!:;DM//5w( 3: 3+13 	3r   c                 "   > [         TU ]  U5      $ N)r   
print_help)r   filer   s     r   r,   CliArgumentParser.print_help$   s    w!$''r   c                    U R                   b  [        U R                   5       H  nUR                  n[        U R                   UR                  5      nSU 3n[	        UR
                  UR                  S   S9nX5S'   SUR                  ;   a  UR                  S   US'   [        US'   U R                  " U40 UD6  M     g g )Nr   help)typer0   defaultchoicesaction)	r   r   namegetattrdictr1   metadataSingleActionadd_argument)r   farg_namearg_attrr5   r   s         r   r   CliArgumentParser.define_args'   s    )D../66"4#5#5qvv>H:166

60BC$,y!

*()

9(=F9%#/x !!$1&1 0 *r   )r%   r#   r   r+   )NN)__name__
__module____qualname____firstlineno____doc__r   r   r   r&   r,   r   __static_attributes____classcell__)r   s   @r   r	   r	      s<    A (,$(
3 $
3 
3(2 2r   r	   c                   >    \ rS rSrSr\S 5       r\S 5       rS rSr	g)
DictAction7   a:  
argparse action to split an argument into KEY=VALUE form
on the first = and append to a dictionary. List options can
be passed as comma separated values, i.e 'KEY=V1,V2,V3', or with explicit
brackets, i.e. 'KEY=[V1,V2,V3]'. It also support nested brackets to build
list/tuple values. e.g. 'KEY=[(V1,V2),(V3,V4)]'
c                      [        U 5      $ ! [         a     Of = f [        U 5      $ ! [         a     Of = fU R                  5       S;   a  U R                  5       S:H  $ U S:X  a  g U $ )N)truefalserJ   None)int
ValueErrorfloatlower)vals    r   parse_int_float_bool_str#DictAction.parse_int_float_bool_str@   sr    	s8O 			: 		99;++99;&((&=
s   
 

) 
66c                 ,   S nU R                  S5      R                  SS5      n SnU R                  S5      (       a  U R                  S5      (       a  SnU S	S
 n OMU R                  S5      (       a  U R                  S5      (       a  U S	S
 n OSU ;  a  [        R                  U 5      $ / n[        U 5      S:  aI  U" U 5      n[        R                  U SU 5      nUR                  U5        XS	-   S n [        U 5      S:  a  MI  U(       a  [        U5      nU$ )a  Parse iterable values in the string.
All elements inside '()' or '[]' are treated as iterable values.
Args:
    val (str): Value string.
Returns:
    list | tuple: The expanded list or tuple from the string.
Examples:
    >>> DictAction._parse_iterable('1,2,3')
    [1, 2, 3]
    >>> DictAction._parse_iterable('[a, b, c]')
    ['a', 'b', 'c']
    >>> DictAction._parse_iterable('[(1, 2, 3), [a, b], c]')
    [(1, 2, 3), ['a', 'b'], 'c']
c                    U R                  S5      U R                  S5      :X  a$  U R                  S5      U R                  S5      :X  d
   SU  35       e[        U 5      n[        U 5       Ha  u  p#U SU nUS:X  d  M  UR                  S5      UR                  S5      :X  d  M8  UR                  S5      UR                  S5      :X  d  M^  Un  U$    U$ )zFind the position of next comma in the string.
If no ',' is found in the string, return the string length. All
chars inside '()' and '[]' are treated as one element and thus ','
inside these brackets are ignored.
()[]zImbalanced brackets exist in N,)countlen	enumerate)stringendidxcharpres        r   find_next_comma2DictAction.parse_iterable.<locals>.find_next_commaa   s     LL%c)::S!<<$%P)Fvh'OP & f+C&v.	TclS[syy~3'G YYs^syy~=CJ / Jr   z'"  FrV   rW   Tr!   rX   rY   rZ   r   N)
stripreplacer   endswithrG   rR   r\   parse_iterableappendtuple)rQ   rc   is_tuplevalues	comma_idxelements         r   rk   DictAction.parse_iterableP   s    "	( ii''R0>>#3<<#4#4Ha)C^^C  S\\#%6%6a)C^66s;;#hl',I //JY@GMM'"!mn%C	 #hl
 6]Fr   c                     0 nU H(  nUR                  SSS9u  pxU R                  U5      XW'   M*     [        X R                  U5        g )N=r!   )maxsplit)splitrk   setattrdest)	r   parserr'   ro   option_stringoptionskvkeyrQ   s	            r   __call__DictAction.__call__   sG    Bxxax0HC..s3GL  		99g.r   r   N)
r?   r@   rA   rB   rC   staticmethodrR   rk   r~   rD   r   r   r   rG   rG   7   s5       7 7r/r   rG   c                       \ rS rSrSrS rSrg)r9      zArgparse action to convert value to tuple or list or nested structure of
list and tuple, i.e 'V1,V2,V3', or with explicit brackets, i.e. '[V1,V2,V3]'.
It also support nested brackets to build list/tuple values. e.g. '[(V1,V2),(V3,V4)]'
c                     [        U[        5      (       a&  [        X R                  U R	                  U5      5        g [        X R                  U5        g r+   )
isinstancestrrw   rx   rk   )r   ry   r'   valuerz   s        r   r~   SingleAction.__call__   s6    eS!!Iyy$*=*=e*DEIyy%0r   r   N)r?   r@   rA   rB   rC   r~   rD   r   r   r   r9   r9      s    
1r   r9   N)argparser   r   r   dataclassesr   typingr   r	   rG   r9   r   r   r   <module>r      s9    J J  .2 .2bX/ X/v
1: 
1r   