
    bCiV                        S SK r S SKrS SKrS SKrS SKrS SKJrJr  S SKJ	r	  S SK
Jr  S SKJrJrJrJr  SSK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  SSKJr  SSK J!r!  SSK"J"r"  \" 5       (       a  S SK#r$S SK#J%r%  S SK#J&r'   " S S\%5      r(\	RR                  " 5       RT                  r+\" \,5      RZ                  RZ                  q.[\        RZ                  RZ                  q/S\+ S3Ra                  5       r1 " S S5      r2S\\3\Rh                  4   S\3S\34S jr5S\2S\3S\3S \6\7\3\84      4S! jr9S"\3S#\6\3   4S$ jr:S%\3S\3S\34S& jr;S%\3S\3S \6\7\3\84      4S' jr<S(\3S)\=4S* jr>S(\3S\2S+\3S)\7\3\3\64   4S, jr?S\2S\3S \6\7\3\84      S)\34S- jr@S\2S \6\7\3\84      4S. jrAS\2S\3S\3S \6\7\3\84      S/\84
S0 jrB   S=S1\3S2\\3   S3\\   S4\\3   S)\4
S5 jjrCS6\3S)\84S7 jrDS8 rES9\4S: jrF " S; S<\!5      rGg)>    N)ArgumentParser	Namespace)date)Path)AnyCallableOptionalUnion   )CONFIG_MAPPING_NAMESMODEL_NAMES_MAPPING)FEATURE_EXTRACTOR_MAPPING_NAMES)IMAGE_PROCESSOR_MAPPING_NAMES)PROCESSOR_MAPPING_NAMES)TOKENIZER_MAPPING_NAMES)VIDEO_PROCESSOR_MAPPING_NAMES)is_libcst_available   )BaseTransformersCLICommand)add_fast_image_processor)
CSTVisitor)matchersc                       \ rS rSrSrS rS\R                  SS4S jrS\R                  4S jr	S\R                  4S	 jrS
rg)ClassFinder*   z3
A visitor to find all classes in a python module.
c                 .    / U l         / U l        SU l        g NF)classespublic_classesis_in_classselfs    b/home/james-whalen/.local/lib/python3.13/site-packages/transformers/commands/add_new_model_like.py__init__ClassFinder.__init__/   s    !#DL(*D$D    nodereturnNc                 p    U R                   R                  UR                  R                  5        SU l        g)zwRecord class names. We assume classes always only appear at top-level (i.e. no class definition in function or similar)TN)r   appendnamevaluer    r"   r'   s     r#   visit_ClassDefClassFinder.visit_ClassDef4   s$    LL		0#Dr&   c                     SU l         g r   )r    r-   s     r#   leave_ClassDefClassFinder.leave_ClassDef9   s
    $Dr&   c                    [         R                  " [         R                  " [         R                  " [         R                  " 5       S9/S9/S9nU R
                  (       d  [         R                  " X5      (       a  UR                  S   R                  S   R                  R                  nUS:X  aO  UR                  S   R                  R                  nU Vs/ s H  oUR                  R                  PM     snU l        ggggs  snf )z:Record all public classes inside the `__all__` assignment.)target)targets)bodyr   __all__N)mSimpleStatementLineAssignAssignTargetNamer    matchesr6   r5   r4   r,   elementsr   )r"   r'   !simple_top_level_assign_structureassigned_variabler>   elements         r#   visit_SimpleStatementLine%ClassFinder.visit_SimpleStatementLine<   s    010E0Ehhaffh(G'HIJ1- ##		$(Z(Z$(IIaL$8$8$;$B$B$H$H!$	1#yy|11::HNV*Wh7==+>+>h*WD' 2 )[# +Xs   D)r   r    r   )__name__
__module____qualname____firstlineno____doc__r$   cstClassDefr.   r1   r9   rB   __static_attributes__ r&   r#   r   r   *   sG    		%
	$s|| 	$ 	$
	%s|| 	%		X#2I2I 		Xr&   r   z
# coding=utf-8
# Copyright aN   the HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
c                   &    \ rS rSrSrS\4S jrSrg)
ModelInfos^   zA
Retrieve the basic information about an existing model classes.
lowercase_namec                    UR                  5       R                  SS5      R                  SS5      U l        U R                  [        ;  a  U R                  R                  SS5        U R                  [        ;  a  [	        U S35      e[
        U R                     U l        [        U R                     U l        U R                  R                  SS5      U l        U R                  [        ;   aD  [        U R                     u  U l
        U l        U R                  S:X  a  S OU R                  U l        OSu  U l
        U l        [        R                  " U R                  S5      u  U l        U l        [         R                  " U R                  S 5      U l        [$        R                  " U R                  S 5      U l        [(        R                  " U R                  S 5      U l        g )	N _-z is not a valid model nameConfig PreTrainedTokenizerFast)NN)lowerreplacerP   r   
ValueErrorr   
paper_nameconfig_classcamelcase_namer   tokenizer_classfast_tokenizer_classr   getimage_processor_classfast_image_processor_classr   video_processor_classr   feature_extractor_classr   processor_class)r"   rP   s     r#   r$   ModelInfos.__init__c   s   ,224<<S#FNNsTWX&::''S1&:://IJKK-d.A.AB01D1DE"//77"E "99>UVZViVi>j;D $";115NNTXTmTm % ?I;D $";FcFgFgG
C"D$C &C%F%FtGZGZ\`%a"'F'J'J4K^K^`d'e$6::4;N;NPTUr&   )r]   r\   rb   r_   rd   ra   rP   r[   re   r^   rc   N)rD   rE   rF   rG   rH   strr$   rK   rL   r&   r#   rN   rN   ^   s    Vs Vr&   rN   	file_namenew_content	add_afterc                    [        U SSS9 nUR                  5       nSSS5        WR                  US5      u  pVXR-   U-   U-   n[        U SSS9 nUR                  U5        SSS5        g! , (       d  f       NR= f! , (       d  f       g= f)a?  
A utility to add some content inside a given file.

Args:
    file_name (`str` or `os.PathLike`):
        The name of the file in which we want to insert some content.
    new_content (`str`):
        The content to add.
   add_after (`str`):
       The new content is added just after the first instance matching it.
rutf-8encodingNr   w)openreadsplitwrite)rh   ri   rj   fold_contentbeforeafters          r#   add_content_to_filery      s~     
iw	/1ffh 
0  %%i3MF${2U:K	iw	/1	 
0	/ 
0	/ 
0	/s   A)A:)
A7:
Bold_model_infosnew_lowercase_namenew_model_paper_namefilenames_to_addc           	         SR                  S UR                  SS5      R                  S5       5       5      nU R                  nU R                  nUSS  VVs/ s H  u  pxUR                  US5      U4PM     nnn/ n	U HK  u  p[
        R                  " SU
5      (       a  U	S	   u  pX=(       d    U4U	S	'   M9  U	R                  X45        MM     [        [        S
-  S-  S-  SU SU S3SS9  [        [        S
-  S-  S-  SU SU S3SS9  U	 H  u  pxU(       d  M  UR                  SS5      n[        [        S
-  S-  U-  5       nUR                  5       n
SSS5        [
        R                  " SU S3W
[
        R                  5      nU H9  n[        [        S
-  S-  U-  UR                  XQ5      R                  Xd5      US9  M;     M     gs  snnf ! , (       d  f       N= f)a  
Add a model to all the relevant mappings in the auto module.

Args:
    old_model_infos (`ModelInfos`):
        The structure containing the class information of the old model.
    new_lowercase_name (`str`):
        The new lowercase model name.
    new_model_paper_name (`str`):
        The fully cased name (as in the official paper name) of the new model.
    filenames_to_add (`list[tuple[str, bool]]`):
        A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we
        should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]
rV   c              3   @   #    U  H  oR                  5       v   M     g 7fNtitle.0xs     r#   	<genexpr>-add_model_to_auto_mappings.<locals>.<genexpr>        `0_1WWYY0_   rT   rS   r   Nautoz2(?:tokenization)|(?:image_processing)_auto_fast.pymodelszconfiguration_auto.pyz
        ("z", "z
Config"),
zOCONFIG_MAPPING_NAMES = OrderedDict[str, str](
    [
        # Add configs here
ri   rj   z"),
zcMODEL_NAMES_MAPPING = OrderedDict[str, str](
    [
        # Add full (and cased) model names here
_fast.py.pyz( {8,12}\(\s*"z",.*?\),\n)(?: {4,12}\(|\]))joinrY   rs   rP   r]   researchr*   ry   TRANSFORMERS_PATHrq   rr   findallDOTALL)rz   r{   r|   r}   new_cased_nameold_lowercase_nameold_cased_namefilenameto_addcorrected_filenames_to_addfileprevious_fileprevious_to_addru   matching_linesmatchs                   r#   add_model_to_auto_mappingsr      s   ( WW`0B0J0J3PS0T0Z0Z[^0_``N(77$33NWghihjWkWkCS8		,f	5v>Wk   "$(99JDQQ-G-K*M.;=VPV-W&r*&--tn= ) H$v-0GG !3 4D8HTf
 H$v-0GG !3 4D9M8NeTz 76''
E:H'(2V;hFG1vvx H  ZZ#$6#77TUW[]_]f]fN (#%069HD %.@ U ] ]&! $ ( 718 HGs    GG
G!	new_paper_namer   c                 ,   Sn[         R                  " SS[        5      R                  SS5      U-   n[        R
                  " SU  SU  S35      n/ nU H'  nS	U S
U 3nSU;   a  US-  nUR                  U5        M)     SR                  U5      nX4-   U-   $ )a  
Create a new doc file to fill for the new model.

Args:
    new_paper_name (`str`):
        The fully cased name (as in the official paper name) of the new model.
    public_classes (`list[str]`):
        A list of all the public classes that the model will have in the library.
u   

⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer.

-->

z# ?rV   zcoding=utf-8
z<!--z
        # z#

        ## Overview

        The a<   model was proposed in [<INSERT PAPER NAME HERE>](<INSERT PAPER LINK HERE>) by <INSERT AUTHORS HERE>.
        <INSERT SHORT SUMMARY HERE>

        The abstract from the paper is the following:

        <INSERT PAPER ABSTRACT HERE>

        Tips:

        <INSERT TIPS ABOUT MODEL HERE>

        This model was contributed by [INSERT YOUR HF USERNAME HERE](https://huggingface.co/<INSERT YOUR HF USERNAME HERE>).
        The original code can be found [here](<INSERT LINK TO GITHUB REPO HERE>).

        ## Usage examples

        <INSERT SOME NICE EXAMPLES HERE>

        z## z

[[autodoc]] Modelz
    - forward

)r   sub	COPYRIGHTrY   textwrapdedentr*   r   )	r   r   
added_notecopyright_for_markdowndoc_templatedoc_for_classesclass_doc	class_docs	            r#   create_doc_filer      s    	K   VVFB	:BBCSU[\_ii??
   		L8 O F8+F84f$$Cs#	 ! O,I!09<<r&   r   c                 .   [         S-  S-  S-  S-  n[        US5       nUR                  5       nSSS5        [        R                  " SU  S3W5      R                  S	5      nS
U SU S3n[        [         S-  S-  S-  S-  XvS9  g! , (       d  f       N\= f)a\  
Insert the new model in the doc `_toctree.yaml`, in the same section as the old model.

Args:
    old_lowercase_name (`str`):
        The old lowercase model name.
    new_lowercase_name (`str`):
        The old lowercase model name.
    new_model_paper_name (`str`):
        The fully cased name (as in the official paper name) of the new model.
docssourceenz_toctree.ymlrl   Nz- local: model_doc/z\n {8}title: .*?\nr   z      - local: model_doc/z
        title: 
r   )	REPO_PATHrq   rr   r   r   groupry   )r   r{   r|   toc_fileru   contentold_model_tocnew_tocs           r#   insert_model_in_doc_tocr     s     6!H,t3nDH	h	&&( 
 II!45G4HH\]_fgmmnopM)*<)==NOcNddfgGFX%,~=7 
	s   B
Bc                     U VVs/ s H(  u  p4UR                  X5      R                  SS5      U4PM*     nnnSR                  S U 5       5      n[        [        R                  " SU S35      -   nU$ s  snnf )a  
Create the `__init__.py` file to add in the new model folder.

Args:
    old_lowercase_name (`str`):
        The old lowercase model name.
    new_lowercase_name (`str`):
        The new lowercase model name.
    filenames_to_add (`list[tuple[str, bool]]`):
        A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we
        should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]
r   rV   
            c              3   D   #    U  H  u  pU(       d  M  S U S3v   M     g7f)zfrom .z	 import *NrL   )r   r   r   s      r#   r   #create_init_file.<locals>.<genexpr>9  s#     #lQaek$<fTF)$<Qas     z
        from typing import TYPE_CHECKING

        from ...utils import _LazyModule
        from ...utils.import_utils import define_import_structure


        if TYPE_CHECKING:
            z
        else:
            import sys

            _file = globals()["__file__"]
            sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
        )rY   r   r   r   r   )r   r{   r}   r   r   imports	init_files          r#   create_init_filer   (  s     !1 0H 
		,	A	I	I%QS	TV\] 0   ###lQa#llGHOO I 		 I" -s   /A3module_namer(   c                     [        U SSS9 nUR                  5       nSSS5        [        R                  " W5      n[	        5       nUR                  U5        UR                  UR                  4$ ! , (       d  f       NW= f)z
Find the name of all classes defined in `module_name`, including public ones (defined in `__all__`).

Args:
    module_name (`str`):
        The full path to the python module from which to extract classes.
rl   rm   rn   N)rq   rr   rI   parse_moduler   visitr   r   )r   r   source_codemodulevisitors        r#   find_all_classes_from_filer   N  sc     
k3	1Tiik 
2k*FmG
LL??G2222 
2	1s   A..
A<r   c                 \  ^^	 [        U 5      u  p4SR                  U R                  SS 5      R                  SS5      nUR                  m	SU SSR                  S	 U 5       5       3nS
R                  UU	4S jU 5       5      nU Vs/ s H  oR                  T	T5      PM     nnXgU4$ s  snf )ak  
Extract the modular structure that will be needed to copy a file `module_name` using modular.

Args:
    module_name (`str`):
        The full path to the python module to copy with modular.
    old_model_infos (`ModelInfos`):
        The structure containing the class information of the old model.
    new_cased_name (`str`):
        The new cased model name.
.Nr   rV   zfrom ..z import z, c              3   $   #    U  H  ov   M     g 7fr   rL   )r   r   s     r#   r   )find_modular_structure.<locals>.<genexpr>o  s     :\P[f6P[s   r   c              3   V   >#    U  H  nS UR                  TT5       SU S3v   M      g7f)zclass (z):
    passN)rY   )r   r   r   r   s     r#   r   r   p  s1      "ep[a&?@&Veps   &))r   r   partsrY   r]   )
r   rz   r   all_classesr   import_locationr   modular_classesr   r   s
     `      @r#   find_modular_structurer   ^  s     #=["IKhh{0056>>ubIO$33N(:\P[:\1\0]^Gkk "ep" O TbbSann^^DSaNb^33 cs   B)c                    SR                  S UR                  SS5      R                  S5       5       5      nU R                  n[        S-  U-  nSnSn/ nU H@  u  pU
(       d  M  [        XY-  X5      u  pnUSU 3-  nUSU 3-  nUR                  U5        MB     SR                  S	 U 5       5      n[        R                  " S
U S35      n[        U-   U-   U-   nU Vs/ s H  nUR                  SS5      PM     nnUU4$ s  snf )am  
Create a new modular file which will copy the old model, based on the new name and the different filenames
(modules) to add.

Args:
    old_model_infos (`ModelInfos`):
        The structure containing the class information of the old model.
    new_lowercase_name (`str`):
        The new lowercase model name.
    filenames_to_add (`list[tuple[str, bool]]`):
        A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we
        should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]
rV   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r   s     r#   r   &create_modular_file.<locals>.<genexpr>  r   r   rT   rS   r   r   r   r   c              3   *   #    U  H	  o S 3v   M     g7f),NrL   )r   public_classs     r#   r   r     s     4o\nL~Q5G\ns   z"

        __all__ = [
            z
        ]
        ")
r   rY   rs   rP   r   r   extendr   r   r   )rz   r{   r}   r   r   old_folder_rootall_imports
all_bodiesall_public_classesr   r   r   r6   r   public_classes_formattedall_statementmodular_filer   s                     r#   create_modular_filer   w  sE   $ WW`0B0J0J3PS0T0Z0Z[^0_``N(77'(25GGO KJ,6,B*O-)G> Ry>)KD-'J%%n5 -  0444o\n4ooOO && '		M {*Z7-GLL^_L^L,..sB7L^_+++ `s   !Dc           	         SR                  S UR                  SS5      R                  S5       5       5      nU R                  nU R                  nUSS  VVs/ s H  u  pgSUR                  XA5      -   U4PM     nnn/ nU HO  u  p[
        R                  " SU S	3U	5      (       a  US
   u  pX=(       d    U4US
'   M=  UR                  X45        MQ     0 nU H  u  pU(       d  M  UR                  X5      n[        S-  S-  U-  U-  nUR                  5       (       d  MH  [        US5       nUR                  5       nSSS5        WR                  S5      nSnUU   R                  S5      (       a   US-  nUU   R                  S5      (       a  M   [        SR                  UUS 5      -   nUR                  XS5      X'   M     U$ s  snnf ! , (       d  f       N= f)aa  
Create the test files for the new model. It basically copies over the old test files and adjust the class names.

Args:
    old_model_infos (`ModelInfos`):
        The structure containing the class information of the old model.
    new_lowercase_name (`str`):
        The new lowercase model name.
    filenames_to_add (`list[tuple[str, bool]]`):
        A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we
        should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]
rV   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r   s     r#   r   $create_test_files.<locals>.<genexpr>  r   r   rT   rS   r   Ntest_z+test_(?:tokenization)|(?:image_processing)_r   r   testsr   rl   r   r   #)r   rY   rs   rP   r]   r   r   r*   r   is_filerq   rr   
startswithr   )rz   r{   r}   r   r   r   r   r   r   r   r   r   
test_filesnew_fileoriginal_test_fileoriginal_test_pathru   	test_code
test_linesidxs                       r#   create_test_filesr     s    WW`0B0J0J3PS0T0Z0Z[^0_``N(77$33N !1 4 4H 
8##$6K	KVT 4  
 "$(99CDVCWW_`bfgg-G-K*M.;=VPV-W&r*&--tn= ) J66!)!1!12D!Y!*W!4x!?BT!TWi!i%--//(#.!FFH	 / #.JCS/,,S11q S/,,S11!DIIj.>$??I#,#4#4^#TJ  7" ?* /.s   "G,G
G	create_fast_image_processorc                    [        5       (       d  [        S5      eU R                  n[        S-  U-  n[        R
                  " USS9  [        XU5      u  px[        USU S3-  S5       n	U	R                  U5        SSS5        [        XQU5      n
[        US	-  S5       n	U	R                  U
5        SSS5        [        [        S-  S	-  S
U S3SS9  [        XX#5        [        S-  S-  U-  n[        R
                  " USS9  [        US	-  S5          SSS5        [        XU5      nUR                  5        H-  u  p[        X-  S5       n	U	R                  U5        SSS5        M/     [        X(5      n[        [        S-  S-  S-  S-  U S3-  S5       n	U	R                  U5        SSS5        [!        XQU5        U(       a	  [#        US9  [        S-  S	-  n[$        R&                  " SSXkUS/[        [$        R(                  S9  [$        R&                  " SSXkU/[        [$        R(                  S9  [$        R&                  " / SQ[        [$        R(                  S9  [$        R&                  " SS/[        [$        R(                  S9  [$        R&                  " SSU/[        [$        R(                  S9  g! , (       d  f       GN;= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GM  = f! , (       d  f       GNY= f)aC  
Creates a new model module like a given model of the Transformers library.

Args:
    old_model_infos (`ModelInfos`):
        The structure containing the class information of the old model.
    new_lowercase_name (`str`):
        The new lowercase model name.
    new_model_paper_name (`str`):
        The fully cased name (as in the official paper name) of the new model.
    filenames_to_add (`list[tuple[str, bool]]`):
        A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we
        should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]
    create_fast_image_processor (`bool`):
        If it makes sense, whether to add a fast processor as well, even if the old model does not have one.
zHYou need to install `libcst` to run this command -> `pip install libcst`r   T)exist_okmodular_r   rp   Nz__init__.pyz
    from .z
 import *
zif TYPE_CHECKING:
r   r   r   r   r   	model_docz.md)
model_nameruffcheckz--fix)cwdstdoutformat)pythonzutils/check_doc_toc.pyz--fix_and_overwriter  zutils/sort_auto_mappings.pyz utils/modular_model_converter.py)r   rZ   rP   r   osmakedirsr   rq   rt   r   ry   r   r   r   itemsr   r   r   
subprocessrunDEVNULL)rz   r{   r|   r}   r   r   new_module_folderr   r   ru   r   tests_folderr   r   r   doc_filemodel_init_files                    r#   create_new_model_liker    s   0   cdd(77 *H47IIKK!D1 $7\l#m L	H-?,@"DDc	Ja	 
K !!3IYZI	-/	5		 
6 H$}4 !3 4K@' DXk w&14FFLKKt,	l]*C	0 
1"?HXYJ'--/,)3/1GGG 0/ 0
 3DH	i& 8+d2[@FXEYY\C]]_b	cgh	 
d.DXY # ,>? ((2]BONN	+?GT!!
 NN	,OL!!
 NNC[e[m[m NNH;<)T^TfTfg NN	57IJPYblbtbts 
K	J
 
6	5" 
1	0 0/
 
d	cs<   )J/KK	K%K8/
J>
K
K"%
K5	8
Lquestiondefault_value
convert_tofallback_messagec                    U R                  S5      (       d  U S-   n Ub  U  SU S3n SnU(       dK  [        U 5      nUb  [        U5      S:X  a  UnUb   U" U5      nSnOSnU(       d  [	        U5        U(       d  MK  W$ ! [         a    Sn N+f = f)a  
A utility function that asks a question to the user to get an answer, potentially looping until it gets a valid
answer.

Args:
    question (`str`):
        The question to ask the user.
    default_value (`str`, *optional*):
        A potential default value that will be used when the answer is empty.
    convert_to (`Callable`, *optional*):
        If set, the answer will be passed to this function. If this function raises an error on the provided
        answer, the question will be asked again.
    fallback_message (`str`, *optional*):
        A message that will be displayed each time the question is asked again to the user.

Returns:
    `Any`: The answer provided by the user (or the default), passed through the potential conversion function.
rR   z [z] Fr   T)endswithinputlen	Exceptionprint)r  r  r  r  valid_answeranswers         r#   get_user_fieldr  >  s    0 S!!c> Zr-3Lx$V)9"F!%#F+#  L"# l  M  %$%s   
A= =BBr   c                 r    U R                  5       S;   a  gU R                  5       S;   a  g[        U  S35      e)z
Converts a string to a bool.
)1yyestrueT)0nnofalseFz0 is not a value that can be converted to a bool.)rX   rZ   )r   s    r#   convert_to_boolr&  o  s;     	wwy--wwy--
sJK
LLr&   c                     [        [        R                  " 5       5      n SnU(       d~  [        S5      nX ;   a  SnOb[	        U S35        [
        R                  " X 5      n[        U5      S:  a/  [        U5      S:  a  SR                  U5      n[	        SU S35        U(       d  M~  [        W5      n[        S	5      n[        S
SR                  S UR                  S5       5       5      S9nSnSnSn	Sn
SnSnSnUR                  b  [        SU S3[        SS9nUR                  b  [        SU S3[        SS9nUR                  b  [        SU S3[        SS9n	UR                   b  [        SU S3[        SS9n
UR"                  b  [        SU S3[        SS9nUR$                  b  [        SU S3[        SS9nUR&                  b  [        SU S3[        SS9nUR(                  nSU S3S4SU S3S4SU S3U4SU S3U4SU S3U	4SU S3U
4SU S3U4S U S3U4S!U S3U44	nSnU	(       a  U
(       d  [        S"[        S#S$S%9nXEXoU4$ )&z=
Ask the user for the necessary inputs to add the new model.
FzWWhat model would you like to duplicate? Please provide it as lowercase, e.g. `llama`): Tz is not a valid model type.r   z or zDid you mean ?zSWhat is the new model name? Please provide it as snake lowercase, e.g. `new_model`?zUWhat is the fully cased name you would like to appear in the doc (e.g. `NeW ModEl`)? rV   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r   s     r#   r   !get_user_input.<locals>.<genexpr>  s     O1NAggii1Nr   rS   )r  zHDo you want to create a new tokenizer? If `no`, it will use the same as z (y/n)?z.Please answer yes/no, y/n, true/false or 1/0. )r  r  zMDo you want to create a new fast tokenizer? If `no`, it will use the same as zNDo you want to create a new image processor? If `no`, it will use the same as zSDo you want to create a new fast image processor? If `no`, it will use the same as zNDo you want to create a new video processor? If `no`, it will use the same as zPDo you want to create a new feature extractor? If `no`, it will use the same as zHDo you want to create a new processor? If `no`, it will use the same as configuration_r   	modeling_tokenization_r   image_processing_video_processing_feature_extraction_processing_zA fast image processor can be created from the slow one, but modifications might be needed. Should we add a fast image processor class for this model (recommended) (y/n)? r  z-Please answer yes/no, y/n, true/false or 1/0.)r  r  r  )listr   keysr  r  difflibget_close_matchesr  r   rN   r  rs   r^   r&  r_   ra   rb   rc   rd   re   rP   )model_typesvalid_model_typeold_model_typenear_choicesrz   r{   r|   add_tokenizeradd_fast_tokenizeradd_image_processorr   add_video_processoradd_feature_extractoradd_processorr   r}   r   s                    r#   get_user_inputr@  z  sS    *//12K e
 (#^$$?@A"44^QL< A%|$q(#);;|#<Ll^156  !0O (] *_ggO1C1I1I#1NOO M$!M&&2&VWeVffmn&M

 ++7+[\j[kkrs&M

 ,,8,\]k\llst&M

 11=#1abpaqqxy&M$
 
 ,,8,\]k\llst&M

 ..: .^_m^nnuv&M!

 &&2&VWeVffmn&M
 )77 ,-S	148'(	,d3+,C	0-@+,H	57IJ/0	46IJ/0	9;ST/0	46IJ12#	68MN)*#	.>
 #(#;&4^&L'
# 0DXsssr&   argsc                 (    [        U R                  S9$ )N)path_to_repo)AddNewModelLikeCommandrC  )rA  s    r#   "add_new_model_like_command_factoryrE    s    !t/@/@AAr&   c                   <    \ rS rSr\S\4S j5       rSS jrS rSr	g)	rD  i  parserc                 v    U R                  S5      nUR                  S[        SS9  UR                  [        S9  g )Nzadd-new-model-likez--path_to_repozFWhen not using an editable install, the path to the Transformers repo.)typehelp)func)
add_parseradd_argumentrg   set_defaultsrE  )rG  add_new_model_like_parsers     r#   register_subcommand*AddNewModelLikeCommand.register_subcommand  sC    $*$5$56J$K!!..3-u 	/ 	
 	"..4V.Wr&   Nc                 b    [        5       u  U l        U l        U l        U l        U l        Xl        g r   )r@  rz   r{   r|   r}   r   rC  )r"   rC  kwargss      r#   r$   AddNewModelLikeCommand.__init__  s3     	
 #%!,(r&   c                     U R                   b!  [        U R                   5      q[        S-  S-  q[	        U R
                  U R                  U R                  U R                  U R                  S9  g )Nsrctransformers)rz   r{   r|   r}   r   )
rC  r   r   r   r  rz   r{   r|   r}   r   r!   s    r#   r	  AddNewModelLikeCommand.run   se    (
 T../I )E 1N B 00#66!%!:!:!22(,(H(H	
r&   )r   r}   r{   r|   rz   rC  r   )
rD   rE   rF   rG   staticmethodr   rP  r$   r	  rK   rL   r&   r#   rD  rD    s(    XN X X)
r&   rD  )NNN)Hr4  r  r   r  r   argparser   r   datetimer   pathlibr   typingr   r   r	   r
   models.auto.configuration_autor   r   #models.auto.feature_extraction_autor   !models.auto.image_processing_autor   models.auto.processing_autor   models.auto.tokenization_autor   !models.auto.video_processing_autor   utilsr   rV   r   r   libcstrI   r   r   r8   r   todayyearCURRENT_YEAR__file__parentr   r   lstripr   rN   rg   PathLikery   r2  tupleboolr   r   r   r   setr   r   r   r   r  r  r&  r@  rE  rD  rL   r&   r#   <module>rp     s    	 	   .   1 1 V Q M A C M ' ( >
 !$Xj X< zz|  N))00 $$++	N  FH 
$V VD5bkk)9#:  Y\ ,@@@ @ 5d+,	@F5=C 5=c 5=p  dg .# ## #Y]^cdgimdm^nYo #L3C 3C 3 44'14CF4
3T>421,1,1, 5d+,1, 		1,h/z /Y]^cdgimdm^nYo /d^^^ ^ 5d+,	^
 "&^F $(%)&*	..C=. ". sm	.
 	.bMs Mt Mlt^BY B"
7 "
r&   