ó
    ‡Ž¡jæ~  ã                   ór  • 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  S SKJr  S SK	J
r
  S SKJrJrJr  S SK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\R0                  " 5       R2                  r\
" \5      R8                  S   rS\ S3R=                  5       rSSSSS.r  S9S\\!S-  \RD                  " SS94   4S jjr# " S S5      r$S\!\RJ                  -  S\!S\!4S jr&S\
S\$S\!S \!S!\'\(\!\)4      4
S" jr*S#\!S$\'\!   4S% jr+S\
S&\!S\!S \!4S' jr,S&\!S\!S!\'\(\!\)4      4S( jr-S)\!S*\.4S+ jr/S)\
S\$S,\!S*\(\!\!\'4   4S- jr0S\
S\$S\!S!\'\(\!\)4      S*\!4
S. jr1S\
S\$S!\'\(\!\)4      4S/ jr2S\
S\$S\!S \!S!\'\(\!\)4      4
S0 jr3   S:S1\!S2\!S-  S3\S-  S4\!S-  S*\4
S5 jjr4S6\!S*\)4S7 jr5S8 r6g);é    N)ÚCallable)Údate)ÚPath)Ú	AnnotatedÚAnyÚcasté   )Úis_libcst_available)Ú
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    Ú±C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/cli/add_new_model_like.pyÚ__init__ÚClassFinder.__init__)   s   € Ø!#ˆDŒLØ(*ˆ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_ClassDef.   s$   € à�L‰L×Ñ §	¡	§¡Ô0Ø#ˆDÕr   c                 ó   • SU l         g r   )r   r    s     r   Úleave_ClassDefÚClassFinder.leave_ClassDef3   s
   € Ø$ˆDÕr   c                 óº  • [         R                  " [         R                  " [         R                  " [         R                  " 5       S9/S9/S9nU R
                  (       dø  [         R                  " X5      (       aÜ  [        [        R                  UR                  S   5      n[        [        R                  UR                  S   R                  5      R                  nUS:X  as  [        [        R                  UR                  5      R                  nU Vs/ s H1  n[        [        R                  UR                  5      R                  PM3     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   Úmatchesr   Úcstr)   r(   r'   r   ÚTupleÚelementsÚSimpleStringr   )r   r   Ú!simple_top_level_assign_structureÚstmtÚassigned_variabler3   Úelements          r   Úvisit_SimpleStatementLineÚ%ClassFinder.visit_SimpleStatementLine6   sñ   € ä01×0EÒ0EÜ—h’h¬¯ª¼a¿fºf»hÑ(GÐ'HÑIÐJñ1Ð-ð ×#×#¬¯	ª	°$×(ZÑ(ZÜœCŸJ™J¨¯	©	°!©Ó5�Ü$(¬¯©°4·<±<À±?×3IÑ3IÓ$J×$PÑ$PÐ!Ø$¨	Ó1Ü#¤C§I¡I¨t¯z©zÓ:×CÑC�HÙfnÓ*oÒfnÐ[b¬4´×0@Ñ0@À'Ç-Á-Ó+P×+VÔ+VÑfnÑ*o�DÕ'ð 2ð )[Ð#ùò
 +ps   Ä8E)r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r1   ÚClassDefr!   r$   r,   r9   Ú__static_attributes__© r   r   r   r   $   sG   † ñ	ò	%ð
	$ s§|¡|ð 	$¸ô 	$ð
	% s§|¡|ô 	%ð
	p°#×2IÑ2I÷ 
	p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.
ÚIMAGE_PROCESSOR_MAPPING_NAMESÚVIDEO_PROCESSOR_MAPPING_NAMESÚPROCESSOR_MAPPING_NAMESÚFEATURE_EXTRACTOR_MAPPING_NAMES)zimage_processing_auto.pyzvideo_processing_auto.pyzprocessing_auto.pyzfeature_extraction_auto.pyÚ	repo_pathzFWhen not using an editable install, the path to the Transformers repo.)Úhelpc                 ó`   • [        5       u  nnnn[        U b  [        U 5      O[        UUUUS9  g)z;
Add a new model to the library, based on an existing one.
N©rH   Úold_model_infosÚnew_lowercase_nameÚnew_model_paper_nameÚfilenames_to_add)Úget_user_inputÚ_add_new_model_like_internalr   Ú	REPO_PATHrK   s        r   Úadd_new_model_likerS   b   s?   € ô 	ÓñØØØØô !Ø%.Ñ%:”$�y”/Ä	Ø'Ø-Ø1Ø)ór   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                 ót  • SSK Jn  SSKJn  SSKJn  SSKJn  SSKJ	n  SSK
Jn  UR                  5       R                  SS	5      R                  S
S	5      U l        U R                  U;  a  U R                  R                  S	S
5        U R                  U;  a  [        U S35      eX R                     U l        U R                   R                  SS5      U l        U R                  U;   a>  S U l        X`R                     U l        U R&                  S:X  a  S OU R&                  U l        OSu  U l        U l        UR)                  U R                  S 5      U l        UR)                  U R                  S 5      U l        UR)                  U R                  S 5      U l        UR)                  U R                  S 5      U l        g )Nr	   ©ÚCONFIG_MAPPING_NAMES)rG   )rD   )rF   )ÚTOKENIZER_MAPPING_NAMES)rE   Ú Ú_Ú-z is not a valid model nameÚConfigÚ ÚPreTrainedTokenizerFast)NN)Úmodels.auto.configuration_autorZ   Ú#models.auto.feature_extraction_autorG   Ú!models.auto.image_processing_autorD   Úmodels.auto.processing_autorF   Úmodels.auto.tokenization_autor[   Ú!models.auto.video_processing_autorE   ÚlowerÚreplacerW   Ú
ValueErrorÚconfig_classÚcamelcase_nameÚtokenizer_classÚfast_tokenizer_classÚgetÚimage_processor_classesÚvideo_processor_classÚfeature_extractor_classÚprocessor_class)r   rW   rZ   rG   rD   rF   r[   rE   s           r   r   ÚModelInfos.__init__‚   s…  € ÝIÝYÝUÝIÝKÝUð -×2Ñ2Ó4×<Ñ<¸SÀ#ÓF×NÑNÈsÐTWÓXˆÔØ×ÑÐ&:Ó:Ø×Ñ×'Ñ'¨¨SÔ1Ø×ÑÐ&:Ó:Ü Ð/Ð/IÐJÓKÐKà0×1DÑ1DÑEˆÔØ"×/Ñ/×7Ñ7¸À"ÓEˆÔð ×ÑÐ"9Ó9Ø#'ˆDÔ Ø(?×@SÑ@SÑ(TˆDÔ%à×1Ñ1Ð5NÓN‘ÐTX×TmÑTmð Õ%ð ?IÑ;ˆDÔ  $Ô";à'D×'HÑ'HÈ×I\ÑI\Ð^bÓ'cˆÔ$Ø%B×%FÑ%FÀt×GZÑGZÐ\`Ó%aˆÔ"Ø'F×'JÑ'JÈ4×K^ÑK^Ð`dÓ'eˆÔ$Ø6×:Ñ:¸4×;NÑ;NÐPTÓUˆÕr   )	rl   rk   rn   rr   rp   rW   rs   rm   rq   N)r;   r<   r=   r>   r?   Ústrr   rA   rB   r   r   rU   rU   }   s   † ñðV s÷ Vr   rU   Ú	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©ÚencodingNé   Úw)ÚopenÚreadÚsplitÚwrite)rv   rw   rx   ÚfÚold_contentÚbeforeÚafters          r   Úadd_content_to_filerˆ   ¤   s~   € ô 
ˆi˜ wÒ	/°1Ø—f‘f“hˆ÷ 
0ð  ×%Ñ% i°Ó3�M€FØÑ$ {Ñ2°UÑ:€Kä	ˆi˜ wÒ	/°1Ø	�‰�Ô÷ 
0Ð	/÷ 
0Õ	/ú÷ 
0Õ	/ús   ŒA)ÁA:Á)
A7Á:
BrL   rM   rN   rO   c           	      óX  • 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  p‰UR                  US5      U	4PM     nnn	/ n
U H5  u  p¹SU;   a  U
S	   u  pÍXÍ=(       d    U	4U
S	'   M#  U
R                  X¹45        M7     [        U S
-  S-  S-  S-  S-  SU SU S3SS9  U S
-  S-  S-  S-  S-  R                  5       nU
 GH&  u  p‰U	(       d  M  U[        ;   aq  [        U   nSn[        R                  " SU S3U[        R                  5      nUR                  S5      n[        R                  " SU S3U[        R                  5      nO[UR                  SS5      nU S
-  S-  S-  S-  U-  R                  5       n[        R                  " SU S3U[        R                  5      nU H;  n[        U S
-  S-  S-  S-  U-  UR                  Xb5      R                  Xu5      US9  M=     GM)     gs  sn	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),...]
r`   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_¨1ŸW™WŸY˜YÒ0_ùó   ‚r^   r]   r~   NÚautoztokenization_auto_fast.pyéÿÿÿÿÚsrcÚtransformersÚmodelszauto_mappings.pyz("z", "zConfig"),
        z2CONFIG_MAPPING_NAMES = OrderedDict(
    [
        ©rw   rx   z[^\w_]z%\s*=\s*OrderedDict\(\s*\[(.*?)\]\s*\)z( {8,12}\(\s*"z",.*?\),\n)(?: {4,12}\(|\])ú_fast.pyú.py)Újoinri   r‚   rW   rl   r   rˆ   Ú	read_textÚ_AUTO_MAPPING_NAMESÚreÚsearchÚDOTALLÚgroupÚfindall)rH   rL   rM   rN   rO   Únew_cased_nameÚold_lowercase_nameÚold_cased_nameÚfilenameÚto_addÚcorrected_filenames_to_addÚfileÚprevious_fileÚprevious_to_addÚautofileÚmapping_nameÚblock_matchÚblockÚmatching_linesÚmatchs                       r   Úadd_model_to_auto_mappingsr´   º   sƒ  € ð* —W‘WÑ`Ð0B×0JÑ0JÈ3ÐPSÓ0T×0ZÑ0ZÐ[^Ô0_Ó`Ó`€NØ(×7Ñ7ÐØ$×3Ñ3€NàWgÐhiÐhjÑWkôÚWkÑCSÀ8ˆ×	Ñ	Ð,¨fÓ	5°vÓ>ÑWkð ñ ð "$ÐÛ(‰ˆØ&¨$Ó.Ø-GÈÑ-KÑ*ˆMØ.;×=VÐPVÐ-WÐ& rÓ*à&×-Ñ-¨t¨nÖ=ñ )ô Ø�EÑ˜NÑ*¨XÑ5¸Ñ>ÐASÑSØÐ+Ð,¨D°Ð0@Ð@SÐTØHòð
 ˜EÑ! NÑ2°XÑ=ÀÑFÐI[Ñ[×fÑfÓh€Hä6Ñˆßˆ6ØÔ.Ó.ä2°8Ñ<�Ø-�Ü ŸišiØ˜l˜^Ð+PÐQÐS[Ô]_×]fÑ]fó�ð $×)Ñ)¨!Ó,�Ü!#§¢Ø'Ð(:Ð';Ð;XÐYÐ[`Ôbd×bkÑbkó"‘ð
 $×+Ñ+¨J¸Ó>�Ø! EÑ)¨NÑ:¸XÑEÈÑNÐQYÑY×dÑdÓf�ä!#§¢Ø'Ð(:Ð';Ð;XÐYÐ[_Ôac×ajÑajó"�ó (�Ü#Ø Ñ%¨Ñ6¸ÑAÀFÑJÈXÑUØ %§¡Ð.@Ó U× ]Ñ ]Ø&ó!ð $ôô (ò- 7ùó)s   Á H&Ú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# ?r`   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Ú	COPYRIGHTri   Ú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ð ô  ŸVšV F¨B´	Ó:×BÑBÐCSÐU[Ó\Ð_iÑiÐä—?’?ðØÐ
ð ð Ðð 	ð	ó€Lð8 €OÛ ˆØ�F�8Ð+¨F¨8Ð4ˆØ�fÓØÐ$Ñ$ˆCØ×Ñ˜sÖ#ñ	 !ð —‘˜OÓ,€Ià!Ñ0°9Ñ<Ð<r   r¦   c                 óD  • U S-  S-  S-  S-  n[        US5       nUR                  5       nSSS5        [        R                  " SU S3W5      nUc  [	        S	U 35      eUR                  S
5      nSU SU S3n	[        U S-  S-  S-  S-  X˜S9  g! , (       d  f       Nk= 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 new 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.ymlrz   Nz- local: model_doc/z\n {8}title: .*?\nzCould not find TOC entry for r   z      - local: model_doc/z
        title: Ú
rš   )r€   r�   r    r¡   rj   r£   rˆ   )
rH   r¦   rM   rN   Útoc_filer„   ÚcontentÚ	toc_matchÚold_model_tocÚnew_tocs
             r   Úinsert_model_in_doc_tocrÏ   >  sÆ   € ð ˜6Ñ! HÑ,¨tÑ3°nÑD€HÜ	ˆh˜Ô	 Ø—&‘&“(ˆ÷ 
ô —	’	Ð0Ð1CÐ0DÐDXÐYÐ[bÓc€IØÑÜÐ8Ð9KÐ8LÐMÓNÐNØ—O‘O AÓ&€MØ)Ð*<Ð)=Ð=NÐOcÐNdÐdfÐg€GÜØ�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œ   r`   ú
            c              3   óD   #   • U  H  u  pU(       d  M  S U S3v •  M     g7f)zfrom .z	 import *NrB   )r�   r«   r©   s      r   r‘   Ú#create_init_file.<locals>.<genexpr>k  s#   é € Ð#lÒQaÁÀÔekÓ$< f¨T¨F°)Õ$<ÒQaùs   ‚ “ 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__)
        )ri   r�   rº   r»   r¼   )r¦   rM   rO   r¨   r©   ÚimportsÚ	init_files          r   Úcreate_init_filerÖ   Z  s˜   € ñ !1ôâ 0ÑˆHð 
×	Ñ	Ð,Ó	A×	IÑ	IÈ%ÐQSÓ	TÐV\Ó]Ù 0ð ñ ð ×#Ñ#Ñ#lÑQaÓ#lÓl€GÜœHŸOšOðð ˆ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.
rz   r{   r|   N)r€   r�   r1   Úparse_moduler   Úvisitr   r   )r×   r«   Úsource_codeÚmoduleÚvisitors        r   Úfind_all_classes_from_filerÞ   €  sc   € ô 
ˆk˜3¨Ò	1°TØ—i‘i“kˆ÷ 
2ä×Ò˜kÓ*€FÜ‹m€GØ
‡L�L�ÔØ�?‰?˜G×2Ñ2Ð2Ð2÷ 
2Õ	1ús   Œ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  oˆR                  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œ   r`   zfrom ..z import z, c              3   ó$   #   • U  H  ov •  M     g 7fr‹   rB   )r�   rÁ   s     r   r‘   Ú)find_modular_structure.<locals>.<genexpr>¡  s   é € Ð:\ÒP[Àf¼6ÒP[ù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)ri   )r�   rÁ   r¥   r§   s     €€r   r‘   rã   ¢  s1   øé € ð "ÚepÐ[aˆ&�—‘ °Ó?Ð@ÀÀ&ÀÈÕVÒepùs   ƒ&))rÞ   r�   Úpartsri   rl   )
r×   rL   r¥   Úall_classesr   Úimport_locationrÔ   Úmodular_classesrÁ   r§   s
     `      @r   Úfind_modular_structurerê   �  s¸   ù€ ô #=¸[Ó"IÑ€KØ—h‘h˜{×0Ñ0°°Ð5Ó6×>Ñ>¸uÀbÓI€OØ$×3Ñ3€NØ˜Ð(¨°·±Ñ:\ÑP[Ó:\Ó1\Ð0]Ð^€GØ—k‘kõ "Ùepó"ó €Oñ TbÓbÒSaÈ—n‘n ^°^ÖDÑSa€NÐbØ ^Ð3Ð3ùò cs   ÂB)c                 ó  • SR                  S UR                  SS5      R                  S5       5       5      nUR                  nU S-  S-  S-  U-  nSnSn/ n	U H@  u  p«U(       d  M  [	        Xj-  X5      u  pÍn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),...]
r`   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”   r^   r]   r—   r˜   r™   rÉ   r¸   rÑ   c              3   ó*   #   • U  H	  o S 3v •  M     g7f)Ú,NrB   )r�   Úpublic_classs     r   r‘   rí   Î  s   é € Ð4oÒ\nÈL°~ÀQÕ5GÒ\nùs   ‚z"

        __all__ = [
            z
        ]
        Ú")	r�   ri   r‚   rW   rê   Úextendr»   r¼   rº   )rH   rL   rM   rO   r¥   r¦   Úold_folder_rootÚall_importsÚ
all_bodiesÚall_public_classesr¨   r©   rÔ   r)   r   Úpublic_classes_formattedÚall_statementÚmodular_filerð   s                      r   Úcreate_modular_filerú   ©  sO  € ð& —W‘WÑ`Ð0B×0JÑ0JÈ3ÐPSÓ0T×0ZÑ0ZÐ[^Ô0_Ó`Ó`€NØ(×7Ñ7ÐØ %Ñ'¨.Ñ8¸8ÑCÐFXÑX€Oð €KØ€JØÐÛ,Ñˆßˆ6Ü,BØÑ*¨Oó-Ñ)ˆG˜>ð ˜R ˜y˜>Ñ)ˆKØ˜D  ˜-Ñ'ˆJØ×%Ñ% nÖ5ñ -ð  0×4Ñ4Ñ4oÑ\nÓ4oÓoÐÜ—O’Oðð &Ð&ð '	ð	ó€Mô ˜{Ñ*¨ZÑ7¸-ÑG€LáL^Ó_ÒL^¸L˜,×.Ñ.¨s°BÖ7ÑL^ÐÐ_ØÐ+Ð+Ð+ùò `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  pxSUR                  XR5      -   U4PM     nnn/ n	U HO  u  p¨[
        R                  " SU S	3U
5      (       a  U	S
   u  p¼X¼=(       d    U4U	S
'   M=  U	R                  X¨45        MQ     0 nU	 Hã  u  pèU(       d  M  UR                  X%5      nU S-  S-  U-  U-  nUR                  5       (       d  MD  [        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                  Xd5      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),...]
r`   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”   r^   r]   r~   NÚtest_z+test_(?:tokenization)|(?:image_processing)_r›   r–   Útestsr™   rz   rÉ   r   Ú#)r�   ri   r‚   rW   rl   r    r¡   r   Úis_filer€   r�   Ú
startswithrº   )rH   rL   rM   rO   r¥   r¦   r§   r¨   r©   rª   r«   r¬   r­   Ú
test_filesÚnew_fileÚoriginal_test_fileÚoriginal_test_pathr„   Ú	test_codeÚ
test_linesÚidxs                        r   Úcreate_test_filesr
  Þ  só  € ð —W‘WÑ`Ð0B×0JÑ0JÈ3ÐPSÓ0T×0ZÑ0ZÐ[^Ô0_Ó`Ó`€NØ(×7Ñ7ÐØ$×3Ñ3€Nð !1°°Ñ 4ôâ 4ÑˆHð 
�8×#Ñ#Ð$6ÓKÑ	KÈVÓTÙ 4ð ñ ð
 "$ÐÛ(‰ˆÜ�9Š9ÐCÐDVÐCWÐW_Ð`Ðbf×gÑgØ-GÈÑ-KÑ*ˆMØ.;×=VÐPVÐ-WÐ& rÓ*à&×-Ñ-¨t¨nÖ=ñ )ð €JÛ6Ñˆßˆ6Ø!)×!1Ñ!1Ð2DÓ!YÐØ!*¨WÑ!4°xÑ!?ÐBTÑ!TÐWiÑ!iÐà%×-Ñ-×/Ñ/ÙÜÐ(¨#Ô.°!ØŸF™F›H�	÷ /ð #Ÿ™¨Ó.ˆJØˆCØ˜S‘/×,Ñ,¨S×1Ñ1Ø�q‘�ð ˜S‘/×,Ñ,¨S×1Ó1ä! D§I¡I¨j¸¸Ð.>Ó$?Ñ?ˆIØ#,×#4Ñ#4°^Ó#TˆJÓ ñ 7ð" Ðùó?÷* /Õ.ús   Á"GÄ(GÇ
G	c                 óÊ  • [        5       (       d  [        S5      eUR                  nU S-  S-  S-  U-  n[        R                  " USS9  [        XX$5      u  px[        USU S3-  S	5       n	U	R                  U5        S
S
S
5        [        XRU5      n
[        US-  S	5       n	U	R                  U
5        S
S
S
5        [        U S-  S-  S-  S-  SU S3SS9  [        XX#U5        U S-  S-  U-  n[        R                  " USS9  [        US-  S	5          S
S
S
5        [        XX$5      nUR                  5        H-  u  pÞ[        X½-  S	5       n	U	R                  U5        S
S
S
5        M/     [        X85      n[        U S-  S-  S-  S-  U S3-  S	5       n	U	R                  U5        S
S
S
5        [        XX#5        U S-  S-  S-  S-  n[        R                   " SSXkUS/U [        R"                  S9  [        R                   " SSXkU/U [        R"                  S9  [        R                   " / SQU [        R"                  S9  [        R                   " SS/U [        R"                  S9  [        R                   " SSU/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N7= f)a  
Creates a new model module like a given model of the Transformers library.

Args:
    repo_path (`Path`):
        The path to the root of the Transformers repository.
    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),...]
zHYou need to install `libcst` to run this command -> `pip install libcst`r—   r˜   r™   T)Úexist_okÚmodular_rœ   r   Nz__init__.pyz
    from .z
 import *
zif TYPE_CHECKING:
rš   rÿ   rÆ   rÇ   rÈ   Ú	model_docz.mdÚ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
   rj   rW   ÚosÚmakedirsrú   r€   rƒ   rÖ   rˆ   r´   r
  ÚitemsrÄ   rÏ   Ú
subprocessÚrunÚDEVNULL)rH   rL   rM   rN   rO   r¦   Únew_module_folderrù   r   r„   rÕ   Útests_folderr  r¨   rË   Údoc_fileÚmodel_init_files                    r   rQ   rQ     sã  € ô0 × Ñ ÜÐcÓdÐdà(×7Ñ7Ðð " EÑ)¨NÑ:¸XÑEÐHZÑZÐÜ‡K‚KÐ!¨DÒ1ô $7ØÐ$6ó$Ñ €Lô 
Ð HÐ-?Ð,@ÀÐ"DÑDÀcÔ	JÈaØ	�‰�Ô÷ 
Kô !Ð!3ÐIYÓZ€IÜ	Ð -Ñ/°Ô	5¸Ø	�‰�	Ô÷ 
6ô Ø�EÑ˜NÑ*¨XÑ5¸ÑEØ Ð!3Ð 4°KÐ@Ø'òô ˜yÐ;MÐeuÔvð ˜wÑ&¨Ñ1Ð4FÑF€LÜ‡K‚K� tÒ,ä	ˆl˜]Ñ*¨CÕ	0Ø÷ 
1ä" 9Ð?QÓd€JØ'×-Ñ-Ö/ÑˆÜ�,Ñ)¨3Ô/°1Ø�G‰G�GÔ÷ 0Ñ/ñ 0ô
 Ð3ÓD€HÜ	ˆi˜&Ñ  8Ñ+¨dÑ2°[Ñ@ÐFXÐEYÐY\ÐC]Ñ]Ð_bÔ	cÐghØ	�‰�Ô÷ 
dä˜IÐ;MÔdð   %Ñ'¨.Ñ8¸8ÑCÀmÑS€OÜ‡N‚NØ	�Ð+¸?ÈGÐTØÜ×!Ñ!òô
 ‡N‚NØ	�Ð,¸OÐLØÜ×!Ñ!òô
 ‡N‚NÚCÈÔ[e×[mÑ[mòô ‡N‚N�HÐ;Ð<À)ÔT^×TfÑTfÒgô ‡N‚NØ	Ð5Ð7IÐJÐPYÔbl×btÑbtó÷k 
KÖ	Jú÷
 
6Ö	5ú÷" 
1Ö	0ú÷ 0×/ú÷
 
dÖ	cús<   Á+J
Â JÄJ.Å
K ÆKÊ

JÊ
J+Ê.
J=Ë 
K	Ë
K"Ú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.
r\   z [z] Fr   T)ÚendswithÚinputÚlenÚ	ExceptionÚprint)r  r   r!  r"  Úvalid_answerÚanswers         r   Úget_user_fieldr+  q  s®   € ð0 ×Ñ˜S×!Ñ!Ø˜c‘>ˆØÑ Ø�Z˜r - °Ð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.)rh   rj   )r�   s    r   Úconvert_to_boolr5  ¢  s;   € ð 	‡w�wƒyÐ-Ó-ØØ‡w�wƒyÐ-Ó-ØÜ
˜�sÐJÐKÓ
LÐLr   c            
      ó  • SSK Jn   [        U R                  5       5      nSnU(       d~  [	        S5      nX1;   a  SnOb[        U S35        [        R                  " X15      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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4nXVX4$ )#z=
Ask the user for the necessary inputs to add the new model.
r   rY   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`)? r`   c              3   ó@   #   • U  H  oR                  5       v •  M     g 7fr‹   rŒ   rŽ   s     r   r‘   Ú!get_user_input.<locals>.<genexpr>Í  s   é € ÐOÒ1N¨AŸg™gŸi˜iÒ1Nùr”   r]   )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 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_)Ú+transformers.models.auto.configuration_autorZ   ÚlistÚkeysr%  r(  ÚdifflibÚget_close_matchesr&  r�   rU   r+  r‚   rm   r5  rn   rp   rq   rr   rs   rW   )rZ   Úmodel_typesÚvalid_model_typeÚold_model_typeÚnear_choicesrL   rM   rN   Úadd_tokenizerÚadd_fast_tokenizerÚadd_image_processorÚadd_video_processorÚadd_feature_extractorÚadd_processorr¦   rO   s                   r   rP   rP   ­  sä  € õ QäÐ+×0Ñ0Ó2Ó3€Kð ÐÞÜØeó
ˆð Ó(Ø#Ñä�^Ð$Ð$?Ð@ÔAÜ"×4Ò4°^ÓQˆLÜ�<Ó  AÓ%Ü�|Ó$ qÓ(Ø#)§;¡;¨|Ó#<�LÜ˜ l ^°1Ð5Ô6÷ Ðô ! Ó0€Oô (Ø]óÐô *Ø_Ø—g‘gÑOÐ1C×1IÑ1IÈ#Ô1NÓOÓOñÐð €MØÐØÐØÐØ!ÐØ€MØ×&Ñ&Ñ2Ü&ØVÐWeÐVfÐfmÐnÜ&ØMñ
ˆð
 ×+Ñ+Ñ7Ü+Ø[Ð\jÐ[kÐkrÐsÜ&ØMñ
Ðð
 ×.Ñ.Ñ:Ü,Ø\Ð]kÐ\lÐlsÐtÜ&ØMñ
Ðð
 ×,Ñ,Ñ8Ü,Ø\Ð]kÐ\lÐlsÐtÜ&ØMñ
Ðð
 ×.Ñ.Ñ:Ü .Ø^Ð_mÐ^nÐnuÐvÜ&ØMñ!
Ðð
 ×&Ñ&Ñ2Ü&ØVÐWeÐVfÐfmÐnÜ&ØMñ
ˆð )×7Ñ7Ðð Ð,Ð-¨SÐ	1°4Ð8ØÐ'Ð(¨Ð	,¨dÐ3ØÐ+Ð,¨CÐ	0°-Ð@ØÐ+Ð,¨HÐ	5Ð7IÐJØÐ/Ð0°Ð	4Ð6IÐJØÐ/Ð0°Ð	4Ð6IÐJØÐ1Ð2°#Ð	6Ð8MÐNØÐ)Ð*¨#Ð	.°Ð>ð	Ðð Ð0DÐVÐVr   r‹   )NNN)7rD  r  r    r  r»   Úcollections.abcr   Údatetimer   Úpathlibr   Útypingr   r   r   ÚtyperÚutilsr
   Úlibcstr1   r   r   r+   r   ÚtodayÚyearÚCURRENT_YEARÚ__file__ÚparentsrR   Úlstriprº   rŸ   ru   ÚArgumentrS   rU   ÚPathLikerˆ   rB  ÚtupleÚboolr´   rÄ   rÏ   rÖ   ÚsetrÞ   rê   rú   r
  rQ   r+  r5  rP   rB   r   r   Ú<module>rb     s#  ðó Û 	Û 	Û Û Ý $Ý Ý ß 'Ñ 'ã å 'ñ
 ×ÑÛÝ!Ý$ôp�jô pð> �zŠz‹|× Ñ €Ù�‹N×"Ñ" 1Ñ%€	ðàˆNð ð÷ �FƒHð 
ð& !@Ø ?Ø3Ø"Cñ	Ð ð 	ñØØˆd‰
�E—N’NÐ(pÑqÐqñõ÷6$Vñ $VðN 3¨¯©Ñ#4ð À3ð ÐSVô ð,IØðIàðIð ðIð ð	Ið
 ˜5  d Ñ+Ñ,ôIðX5= Cð 5=¸¸c¹ô 5=ðpØðØ),ðØBEðØ]`ôð8#¨ð #À#ð #ÐY]Ð^cÐdgÐimÐdmÑ^nÑYoô #ðL3¨Cð 3°Cô 3ð 4Øð4Ø(2ð4ØDGð4à
ˆ3��Tˆ>Ñô4ð22,Øð2,àð2,ð ð2,ð ˜5  d Ñ+Ñ,ð	2,ð
 	ô2,ðj1Øð1Ø&0ð1ØX\Ð]bÐcfÐhlÐclÑ]mÑXnô1ðh\Øð\àð\ð ð\ð ð	\ð
 ˜5  d Ñ+Ñ,ô\ðB !%Ø"&Ø#'ñ	.Øð.à˜‘:ð.ð ˜4‘ð.ð ˜D‘jð	.ð
 	õ.ðbM�sð M˜tô Mó\Wr   