§
    \�’jù‹  ã                   óø  — d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZ dd	lmZmZmZmZmZmZmZmZmZmZ d
dlmZmZmZ  e¦   «         rddl m!Z!  ej"        e#¦  «        Z$ ed¦  «        Z%e&e'e
         dz  e'e
         dz  f         Z(dZ)dZ*dZ+d„ Z, G d„ d¦  «        Z- G d„ de-¦  «        Z.d"de/fd„Z0d#de/de/fd„Z1d„ Z2d„ Z3d„ Z4 G d„ d ee'e         e(f         ¦  «        Z5d!gZ6dS )$z-Factory function to build auto-model classes.é    N)ÚOrderedDict)ÚIterator)ÚAnyÚTypeVaré   )ÚPreTrainedConfig)Úget_class_from_dynamic_moduleÚresolve_trust_remote_code)
ÚCONFIG_NAMEÚcached_fileÚ	copy_funcÚextract_commit_hashÚfind_adapter_config_fileÚhf_apiÚis_peft_availableÚis_torch_availableÚloggingÚrequires_backendsé   )Ú
AutoConfigÚmodel_type_to_module_nameÚ!replace_list_option_in_docstrings)ÚGenerationMixinÚ_TaJ  
    This is a generic model class that will be instantiated as one of the model classes of the library when created
    with the [`~BaseAutoModelClass.from_pretrained`] class method or the [`~BaseAutoModelClass.from_config`] class
    method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
aù  
        Instantiates one of the model classes of the library from a configuration.

        Note:
            Loading a model from its configuration file does **not** load the model weights. It only affects the
            model's configuration. Use [`~BaseAutoModelClass.from_pretrained`] to load the model weights.

        Args:
            config ([`PreTrainedConfig`]):
                The model class to instantiate is selected based on the configuration class:

                List options
            attn_implementation (`str`, *optional*):
                The attention implementation to use in the model (if relevant). Can be any of `"eager"` (manual implementation of the attention), `"sdpa"` (using [`F.scaled_dot_product_attention`](https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html)), `"flash_attention_2"` (using [Dao-AILab/flash-attention](https://github.com/Dao-AILab/flash-attention)), or `"flash_attention_3"` (using [Dao-AILab/flash-attention/hopper](https://github.com/Dao-AILab/flash-attention/tree/main/hopper)). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual `"eager"` implementation.

        Examples:

        ```python
        >>> from transformers import AutoConfig, BaseAutoModelClass

        >>> # Download configuration from huggingface.co and cache.
        >>> config = AutoConfig.from_pretrained("checkpoint_placeholder")
        >>> model = BaseAutoModelClass.from_config(config)
        ```
a™  
        Instantiate one of the model classes of the library from a pretrained model.

        The model class to instantiate is selected based on the `model_type` property of the config object (either
        passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's missing, by
        falling back to using pattern matching on `pretrained_model_name_or_path`:

        List options

        The model is set in evaluation mode by default using `model.eval()` (so for instance, dropout modules are
        deactivated). To train the model, you should first set it back in training mode with `model.train()`

        Args:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
            model_args (additional positional arguments, *optional*):
                Will be passed along to the underlying model `__init__()` method.
            config ([`PreTrainedConfig`], *optional*):
                Configuration for the model to use instead of an automatically loaded configuration. Configuration can
                be automatically loaded when:

                    - The model is a model provided by the library (loaded with the *model id* string of a pretrained
                      model).
                    - The model was saved using [`~PreTrainedModel.save_pretrained`] and is reloaded by supplying the
                      save directory.
                    - The model is loaded by supplying a local directory as `pretrained_model_name_or_path` and a
                      configuration JSON file named *config.json* is found in the directory.
            state_dict (*dict[str, torch.Tensor]*, *optional*):
                A state dictionary to use instead of a state dictionary loaded from saved weights file.

                This option can be used if you want to create a model from a pretrained configuration but load your own
                weights. In this case though, you should check if using [`~PreTrainedModel.save_pretrained`] and
                [`~PreTrainedModel.from_pretrained`] is not a simpler option.
            cache_dir (`str` or `os.PathLike`, *optional*):
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force the (re-)download of the model weights and configuration files, overriding the
                cached versions if they exist.
            proxies (`dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
            output_loading_info(`bool`, *optional*, defaults to `False`):
                Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
            local_files_only(`bool`, *optional*, defaults to `False`):
                Whether or not to only look at local files (e.g., not try downloading the model).
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
                identifier allowed by git.
            trust_remote_code (`bool`, *optional*, defaults to `False`):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            code_revision (`str`, *optional*, defaults to `"main"`):
                The specific revision to use for the code on the Hub, if the code leaves in a different repository than
                the rest of the model. It can be a branch name, a tag name, or a commit id, since we use a git-based
                system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier
                allowed by git.
            kwargs (additional keyword arguments, *optional*):
                Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
                `output_attentions=True`). Behaves differently depending on whether a `config` is provided or
                automatically loaded:

                    - If a configuration is provided with `config`, `**kwargs` will be directly passed to the
                      underlying model's `__init__` method (we assume all relevant updates to the configuration have
                      already been done)
                    - If a configuration is not provided, `kwargs` will be first passed to the configuration class
                      initialization function ([`~PreTrainedConfig.from_pretrained`]). Each key of `kwargs` that
                      corresponds to a configuration attribute will be used to override said attribute with the
                      supplied `kwargs` value. Remaining keys that do not correspond to any configuration attribute
                      will be passed to the underlying model's `__init__` function.

        Examples:

        ```python
        >>> from transformers import AutoConfig, BaseAutoModelClass

        >>> # Download model and configuration from huggingface.co and cache.
        >>> model = BaseAutoModelClass.from_pretrained("checkpoint_placeholder")

        >>> # Update configuration during loading
        >>> model = BaseAutoModelClass.from_pretrained("checkpoint_placeholder", output_attentions=True)
        >>> model.config.output_attentions
        True
        ```
c                 óØ   — |t          | ¦  «                 }t          |t          t          f¦  «        s|S d„ |D ¦   «         }t	          | dg ¦  «        }|D ]}||v r
||         c S Œ|d         S )Nc                 ó   — i | ]
}|j         |“ŒS © ©Ú__name__)Ú.0Úmodels     úSC:\Projects\DSCons\.venv\Lib\site-packages\transformers\models\auto\auto_factory.pyú
<dictcomp>z$_get_model_class.<locals>.<dictcomp>·   s   € ÐIÐIÐI¨u�U”^ UÐIÐIÐIó    Úarchitecturesr   )ÚtypeÚ
isinstanceÚlistÚtupleÚgetattr)ÚconfigÚmodel_mappingÚsupported_modelsÚname_to_modelr%   Úarchs         r"   Ú_get_model_classr0   ²   s’   € Ø$¥T¨&¡\¤\Ô2ÐÝÐ&­­u¨Ñ6Ô6ð  ØÐàIÐIÐ8HÐIÑIÔI€MÝ˜F O°RÑ8Ô8€MØð 'ð 'ˆØ�=Ð Ð Ø  Ô&Ð&Ð&Ð&ð !ð
 ˜AÔÐr$   c                   ó¢   — e Zd ZdZdd„Zed„ ¦   «         Zededefd„¦   «         Zede	e
j        e	         z  fd„¦   «         Zeddd
„¦   «         ZdS )Ú_BaseAutoModelClassNÚreturnc                 ón   — t          | j        j        › d| j        j        › d| j        j        › d�¦  «        ‚)Nz+ is designed to be instantiated using the `z5.from_pretrained(pretrained_model_name_or_path)` or `z.from_config(config)` methods.)ÚOSErrorÚ	__class__r   )ÚselfÚargsÚkwargss      r"   Ú__init__z_BaseAutoModelClass.__init__Æ   sV   € ÝØŒ~Ô&ð Hð HØœ.Ô1ðHð Hà”Ô'ðHð Hð Hñ
ô 
ð 	
r$   c                 óh  — |                      dd ¦  «        }t          |d¦  «        o| j        |j        v }t	          |¦  «        | j        v }|o-t          || j        ¦  «        j                             d¦  «         }|rM|j        | j                 }d|v r| 	                    d¦  «        d         }nd }t          ||j        |||¬¦  «        }|rœ|rš|s˜d|v r| 	                    d¦  «        \  }	}n|j        }	t          ||	fi |¤Ž}
|                      |j        |
d¬¦  «         |
                     | ¬	¦  «         |                      d
d ¦  «        }t#          |
¦  «        }
 |
j        |fi |¤ŽS |r…t          || j        ¦  «        }
|j                             dd ¦  «        }|�Et+          |
dd ¦  «        |k    r0|}|                     ¦   «         }t+          |dd ¦  «        }|�||_         |
j        |fi |¤ŽS t1          d|j        › d| j        › dd                     d„ | j        D ¦   «         ¦  «        › d�¦  «        ‚)NÚtrust_remote_codeÚauto_mapútransformers.ú--r   ©Úupstream_repoT©Úexist_ok©Ú
auto_classÚcode_revisionÚtext_configÚconfig_classÚquantization_configú!Unrecognized configuration class ú for this kind of AutoModel: ú.
Model type should be one of ú, c              3   ó$   K  — | ]}|j         V — Œd S ©Nr   ©r    Úcs     r"   ú	<genexpr>z2_BaseAutoModelClass.from_config.<locals>.<genexpr>ü   ó$   è è € Ð4\Ð4\ÀA°Q´ZÐ4\Ð4\Ð4\Ð4\Ð4\Ð4\r$   ú.)ÚpopÚhasattrr   r=   r&   Ú_model_mappingr0   Ú
__module__Ú
startswithÚsplitr
   Ú_name_or_pathÚname_or_pathr	   Úregisterr6   Úregister_for_auto_classÚ$add_generation_mixin_to_remote_modelÚ_from_configÚsub_configsÚgetr*   Úget_text_configrI   Ú
ValueErrorÚjoin)Úclsr+   r9   r<   Úhas_remote_codeÚhas_local_codeÚexplicit_local_codeÚ	class_refrA   Úrepo_idÚmodel_classÚ_Útext_config_classÚparent_configÚparent_quants                  r"   Úfrom_configz_BaseAutoModelClass.from_configÍ   s¼  € à"ŸJšJÐ':¸DÑAÔAÐÝ! &¨*Ñ5Ô5ÐY¸#¼,È&Ì/Ð:YˆÝ˜f™œ¨Ô);Ð;ˆØ,ð 1Õ5EØ�CÔ&ñ6
ô 6
ä
—Z’Z Ñ0Ô0ð21Ðð ð 	Øœ¨¬Ô5ˆIØ�yÐ Ð Ø )§¢°Ñ 5Ô 5°aÔ 8��à $�Ý 9Ø! 6Ô#7¸ÈÐhuð!ñ !ô !Ðð ð 	>Ð0ð 	>Ð9Lð 	>Ø�yÐ Ð Ø%.§_¢_°TÑ%:Ô%:Ñ"�˜˜à Ô-�Ý7¸	À7ÐUÐUÈfÐUÐUˆKØ�LŠL˜Ô)¨;ÀˆLÑFÔFÐFØ×/Ò/¸3Ð/Ñ?Ô?Ð?Ø—
’
˜?¨DÑ1Ô1ˆAÝ>¸{ÑKÔKˆKØ+�;Ô+¨FÐ=Ð=°fÐ=Ð=Ð=Øð 	>Ý*¨6°3Ô3EÑFÔFˆKØ &Ô 2× 6Ò 6°}ÀdÑ KÔ KÐà Ð,µ¸ÀnÐVZÑ1[Ô1[Ð_pÒ1pÐ1pð !'�Ø×/Ò/Ñ1Ô1�õ  ' }Ð6KÈTÑRÔR�ØÐ+Ø1=�FÔ.Ø+�;Ô+¨FÐ=Ð=°fÐ=Ð=Ð=åð`°Ô0@ð `ð `Ð_bÔ_kð `ð `Ø+/¯9ª9Ð4\Ð4\ÈÔI[Ð4\Ñ4\Ô4\Ñ+\Ô+\ð`ð `ð `ñ
ô 
ð 	
r$   r+   c                 ó   — |S )z`Additional autoclass-specific config post-loading manipulation. May be overridden in subclasses.r   )rf   r+   s     r"   Ú_prepare_config_for_auto_classz2_BaseAutoModelClass._prepare_config_for_auto_classÿ   s	   € ð ˆr$   Úpretrained_model_name_or_pathc                 ó4
  ‡— ‰                      dd ¦  «        }‰                     d¦  «        }d‰d<   g d¢}ˆfd„|D ¦   «         }‰                      dd ¦  «        }‰                      dd ¦  «        }	‰                      d	d ¦  «        }
|                      d
d ¦  «        }|�||d
<   |	€Nt          |t          ¦  «        s(t	          |t
          fddddœ|¤Ž}t          ||	¦  «        }	nt          |dd ¦  «        }	t          ¦   «         rÜ|
€i }
|
 	                    ¦   «         }
|�||
d
<   t          |fd|	i|
¤Ž}|�¬t          |dd¬¦  «        5 }t          j        |¦  «        }||
d<   t          j                             |¦  «        rBt          j                             t          j                             |t
          ¦  «        ¦  «        s|d         }d d d ¦  «         n# 1 swxY w Y   t          |t          ¦  «        �st          j        ‰¦  «        }‰                     d¦  «        dk    r‰                      d¦  «        }‰                     d¦  «        dk    r‰                      d¦  «        }‰                     d¦  «        �‰                      d¦  «        }t'          j        |fd||	dœ|¤‰¤Ž\  }Š|                     dd ¦  «        �|d         ‰d<   |                     dd ¦  «        �|d         ‰d<   |                     dd ¦  «        �|d         ‰d<   t+          |d¦  «        o| j        |j        v }t1          |¦  «        | j        v }|o-t5          || j        ¦  «        j                             d¦  «         }d }|r1|j        | j                 }d|v r|                     d¦  «        d         }t=          |||||¬¦  «        }|‰d<   |
‰d	<   |rƒ|r�|st?          ||fd|i|¤‰¤Ž}|                      dd ¦  «        }|                       |j!        |d¬¦  «         | "                    | ¬¦  «         tG          |¦  «        } |j        |g|¢R d|i|¤‰¤ŽS |rŒt5          || j        ¦  «        }|j$                             dd ¦  «        }|�Et          |dd ¦  «        |k    r0|}| %                    ¦   «         }t          |dd ¦  «        }|�||_&         |j        |g|¢R d|i|¤‰¤ŽS tO          d |j!        › d!| j        › d"d#                     d$„ | j        D ¦   «         ¦  «        › d%�¦  «        ‚)&Nr+   r<   TÚ
_from_auto)Ú	cache_dirÚforce_downloadÚlocal_files_onlyÚproxiesÚrevisionÚ	subfolderÚtokenc                 óD   •— i | ]}|‰v ¯|‰                      |¦  «        “ŒS r   )rU   )r    Únamer9   s     €r"   r#   z7_BaseAutoModelClass.from_pretrained.<locals>.<dictcomp>  s-   ø€ Ð\Ð\Ð\°ÈTÐU[È^È^�d˜FŸJšJ tÑ,Ô,È^È^È^r$   rF   Ú_commit_hashÚadapter_kwargsr}   F)Ú _raise_exceptions_for_gated_repoÚ%_raise_exceptions_for_missing_entriesÚ'_raise_exceptions_for_connection_errorsÚrzutf-8)ÚencodingÚ_adapter_model_pathÚbase_model_name_or_pathÚtorch_dtypeÚautoÚdtyperI   )Úreturn_unused_kwargsrF   r€   r=   r>   r?   r   r@   rB   rD   rG   rH   rJ   rK   rL   rM   c              3   ó$   K  — | ]}|j         V — Œd S rO   r   rP   s     r"   rR   z6_BaseAutoModelClass.from_pretrained.<locals>.<genexpr>—  rS   r$   rT   )(rU   rb   r'   r   r   r   r   r*   r   Úcopyr   ÚopenÚjsonÚloadÚosÚpathÚexistsre   Údeepcopyr   Úfrom_pretrainedrV   r   r=   r&   rW   r0   rX   rY   rZ   r
   r	   r]   r6   r^   r_   ra   rc   rI   rd   )rf   rt   Ú
model_argsr9   r+   r<   Úhub_kwargs_namesÚ
hub_kwargsrF   Úcommit_hashr�   r}   Úresolved_config_fileÚmaybe_adapter_pathÚfÚadapter_configÚkwargs_origrm   rg   rh   ri   rA   rj   rl   rn   ro   rp   s      `                       r"   r–   z#_BaseAutoModelClass.from_pretrained  sÕ  ø€ à—’˜H dÑ+Ô+ˆØ"ŸJšJÐ':Ñ;Ô;ÐØ#ˆˆ|Ñð
ð 
ð 
Ðð ]Ð\Ð\Ð\Ð9IÐ\Ñ\Ô\ˆ
ØŸ
š
 ?°DÑ9Ô9ˆØ—j’j °Ñ6Ô6ˆØŸšÐ$4°dÑ;Ô;ˆà—’˜w¨Ñ-Ô-ˆàÐØ"'ˆJ�wÑàÐÝ˜fÕ&6Ñ7Ô7ð Då'2Ø1Ýð(ð 6;Ø:?Ø<Að(ð (ð !ð(ð (Ð$õ 2Ð2FÈÑTÔT��å% f¨n¸dÑCÔC�åÑÔð 	bØÐ%Ø!#�Ø+×0Ò0Ñ2Ô2ˆNØÐ Ø*/�˜wÑ'å!9Ø-ð"ð "Ø<Gð"ØKYð"ð "Ðð "Ð-ÝÐ,¨c¸GÐDÑDÔDð bÈÝ%)¤Y¨q¡\¤\�Nà<Y�NÐ#8Ñ9õ
 œ7Ÿ>š>Ð*GÑHÔHð bÕPRÔPW×P^ÒP^ÝœŸšÐ%BÅKÑPÔPñQô Qð bð 9GÐG`Ô8aÐ5ðbð bð bñ bô bð bð bð bð bð bð bøøøð bð bð bð bõ ˜&Õ"2Ñ3Ô3ñ 	SÝœ-¨Ñ/Ô/ˆKð �zŠz˜-Ñ(Ô(¨FÒ2Ð2Ø—J’J˜}Ñ-Ô-�Ø�zŠz˜'Ñ"Ô" fÒ,Ð,Ø—J’J˜wÑ'Ô'�à�zŠzÐ/Ñ0Ô0Ð<Ø—J’JÐ4Ñ5Ô5�å'Ô7Ø-ðà%)Ø+Ø(ð	ð ð
 ðð ðð ‰NˆF�Fð �Š˜}¨dÑ3Ô3Ð?Ø(3°MÔ(B��}Ñ%Ø�Š˜w¨Ñ-Ô-Ð9Ø"-¨gÔ"6��w‘Ø�ŠÐ4°dÑ;Ô;ÐGØ0;Ð<QÔ0R�Ð,Ñ-å! &¨*Ñ5Ô5ÐY¸#¼,È&Ì/Ð:YˆÝ˜f™œ¨Ô);Ð;ˆØ,ð 1Õ5EØ�CÔ&ñ6
ô 6
ä
—Z’Z Ñ0Ô0ð21Ðð ˆØð 	9Øœ¨¬Ô5ˆIØ�yÐ Ð Ø )§¢°Ñ 5Ô 5°aÔ 8�Ý5ØØ)ØØØ'ð
ñ 
ô 
Ðð '8ˆÐ"Ñ#ð $2ˆÐÑ àð 	Ð0ð 	Ð9Lð 	Ý7ØÐ8ðð ØHUðØYcðØgmðð ˆKð —’˜°Ñ5Ô5ˆAØ�LŠL˜Ô)¨;ÀˆLÑFÔFÐFØ×/Ò/¸3Ð/Ñ?Ô?Ð?Ý>¸{ÑKÔKˆKØ.�;Ô.Ø-ðØ0:ðð ð ØCIðØMWðØ[aðð ð ð ð 	Ý*¨6°3Ô3EÑFÔFˆKØ &Ô 2× 6Ò 6°}ÀdÑ KÔ KÐà Ð,µ¸ÀnÐVZÑ1[Ô1[Ð_pÒ1pÐ1pð !'�Ø×/Ò/Ñ1Ô1�õ  ' }Ð6KÈTÑRÔR�ØÐ+Ø1=�FÔ.Ø.�;Ô.Ø-ðØ0:ðð ð ØCIðØMWðØ[aðð ð õ ð`°Ô0@ð `ð `Ð_bÔ_kð `ð `Ø+/¯9ª9Ð4\Ð4\ÈÔI[Ð4\Ñ4\Ô4\Ñ+\Ô+\ð`ð `ð `ñ
ô 
ð 	
s   ÅBGÇGÇGFc                 óÀ   — t          |d¦  «        r0|j        j        |j        k    rt          d|j        › d|› d�¦  «        ‚| j                             |||¬¦  «         dS )a  
        Register a new model for this class.

        Args:
            config_class ([`PreTrainedConfig`]):
                The configuration corresponding to the model to register.
            model_class ([`PreTrainedModel`]):
                The model to register.
        rH   z‚The model class you are passing has a `config_class` attribute that is not consistent with the config class you passed (model has z and you passed z!. Fix one of those so they match!rB   N)rV   rH   r   rd   rW   r]   )rf   rH   rl   rC   s       r"   r]   z_BaseAutoModelClass.registerš  s‰   € õ �; Ñ/Ô/ð 	°KÔ4LÔ4UÐYeÔYnÒ4nÐ4nÝð.Ø6AÔ6Nð.ð .Ø`lð.ð .ð .ñô ð ð
 	Ô×#Ò# L°+ÈÐ#ÑQÔQÐQÐQÐQr$   ©r3   N©F)r   rX   Ú__qualname__rW   r:   Úclassmethodrq   r   rs   Ústrr’   ÚPathLiker–   r]   r   r$   r"   r2   r2   Â   sÞ   € € € € € à€Nð
ð 
ð 
ð 
ð ð/
ð /
ñ „[ð/
ðb ðÐ4Dð ÐIYð ð ð ñ „[ðð ðS
¸CÀ"Ä+ÈcÔBRÑ<Rð S
ð S
ð S
ñ „[ðS
ðj ðRð Rð Rð Rñ „[ðRð Rð Rr$   r2   c                   óL   ‡ — e Zd ZdZeˆ fd„¦   «         Zeˆ fd„¦   «         Zˆ xZS )Ú_BaseAutoBackboneClassNc                 ó&  •— t          | ddg¦  «         ddlm} |                     d |¦   «         ¦  «        }|                     d¦  «        �t          d¦  «        ‚|                     dd	¦  «        rt          d
¦  «        ‚|                     d|j        ¦  «        }|                     d|j        ¦  «        }|                     d|j        ¦  «        } |||||¬¦  «        }|                     dd ¦  «          t          ¦   «         j
        |fddi|¤ŽS )NÚvisionÚtimmr   )ÚTimmBackboneConfigr+   Úout_featuresz0Cannot specify `out_features` for timm backbonesÚoutput_loading_infoFz@Cannot specify `output_loading_info=True` when loading from timmÚnum_channelsÚfeatures_onlyÚout_indices)Úbackboner¯   r°   r±   Úuse_pretrained_backboneÚ
pretrainedT)r   Úmodels.timm_backboner¬   rU   rb   rd   r¯   r°   r±   Úsuperrq   )
rf   rt   r—   r9   r¬   r+   r¯   r°   r±   r6   s
            €r"   Ú#_load_timm_backbone_from_pretrainedz:_BaseAutoBackboneClass._load_timm_backbone_from_pretrained²  s/  ø€ å˜# ¨&Ð1Ñ2Ô2Ð2Ø>Ð>Ð>Ð>Ð>Ð>à—’˜HÐ&8Ð&8Ñ&:Ô&:Ñ;Ô;ˆà�:Š:�nÑ%Ô%Ð1ÝÐOÑPÔPÐPà�:Š:Ð+¨UÑ3Ô3ð 	aÝÐ_Ñ`Ô`Ð`à—z’z .°&Ô2EÑFÔFˆØŸ
š
 ?°FÔ4HÑIÔIˆØ—j’j °Ô0BÑCÔCˆØ#Ð#Ø2Ø%Ø'Ø#ð	
ñ 
ô 
ˆð 	�
Š
Ð,¨dÑ3Ô3Ð3Ø"�u‰wŒwÔ" 6ÐEÐE°dÐE¸fÐEÐEÐEr$   c                 óÎ   •— |                      dd ¦  «         t          ¦   «                              |¦  «        s | j        |g|¢R i |¤ŽS  t	          ¦   «         j        |g|¢R i |¤ŽS )NÚuse_timm_backbone)rU   r   Úrepo_existsr·   r¶   r–   )rf   rt   r—   r9   r6   s       €r"   r–   z&_BaseAutoBackboneClass.from_pretrainedÌ  sƒ   ø€ à�
Š
Ð&¨Ñ-Ô-Ð-Ý‰xŒx×#Ò#Ð$AÑBÔBð 	qØ:�3Ô:Ð;XÐpÐ[eÐpÐpÐpÐioÐpÐpÐpà&�u‰wŒwÔ&Ð'DÐ\ÀzÐ\Ð\Ð\ÐU[Ð\Ð\Ð\r$   )r   rX   r£   rW   r¤   r·   r–   Ú__classcell__)r6   s   @r"   r¨   r¨   ®  sz   ø€ € € € € à€NàðFð Fð Fð Fñ „[ðFð2 ð]ð ]ð ]ð ]ñ „[ð]ð ]ð ]ð ]ð ]r$   r¨   Ú Úhead_docc                 óˆ   — t          |¦  «        dk    r|                      dd|› d�¦  «        S |                      dd¦  «        S )Nr   z(one of the model classes of the library z0one of the model classes of the library (with a z head) z-one of the base model classes of the library )ÚlenÚreplace)Ú	docstringr½   s     r"   Úinsert_head_docrÂ   Õ  s\   € Ý
ˆ8�}„}�qÒÐØ× Ò Ø6ØP¸xÐPÐPÐPñ
ô 
ð 	
ð ×ÒØ2Ð4cñô ð r$   úgoogle-bert/bert-base-casedÚcheckpoint_for_examplec                 ól  — | j         }| j        }t          t          |¬¦  «        }|                     d|¦  «        | _        t          t          j        ¦  «        }t          t          |¬¦  «        }|                     d|¦  «        }|                     d|¦  «        }||_         t          |j         d¬¦  «        |¦  «        }t          |¦  «        | _        t          }t          t          j        ¦  «        }	t          ||¬¦  «        }|                     d|¦  «        }|                     d|¦  «        }|                     d¦  «        d                              d¦  «        d	         }
|                     d
|
¦  «        }||	_         t          |j         ¦  «        |	¦  «        }	t          |	¦  «        | _        | S )N)r½   ÚBaseAutoModelClassÚcheckpoint_placeholderF)Úuse_model_typesú/éÿÿÿÿú-r   Úshortcut_placeholder)rW   r   rÂ   ÚCLASS_DOCSTRINGrÀ   Ú__doc__r   r2   rq   ÚFROM_CONFIG_DOCSTRINGr   r¤   ÚFROM_PRETRAINED_TORCH_DOCSTRINGr–   rZ   )rf   rÄ   r½   r,   r   Úclass_docstringrq   Úfrom_config_docstringÚfrom_pretrained_docstringr–   Úshortcuts              r"   Úauto_class_updaterÕ   à  s£  € àÔ&€MØŒ<€DÝ%¥oÀÐIÑIÔI€OØ!×)Ò)Ð*>ÀÑEÔE€C„Kõ Õ/Ô;Ñ<Ô<€KÝ+Õ,AÈHÐUÑUÔUÐØ1×9Ò9Ð:NÐPTÑUÔUÐØ1×9Ò9Ð:RÐTjÑkÔkÐØ/€KÔØhÕ3°MÔ4PÐbgÐhÑhÔhÐitÑuÔu€KÝ! +Ñ.Ô.€C„Oå ?ÐÝÕ 3Ô CÑDÔD€OÝ /Ð0IÐT\Ð ]Ñ ]Ô ]ÐØ 9× AÒ AÐBVÐX\Ñ ]Ô ]ÐØ 9× AÒ AÐBZÐ\rÑ sÔ sÐØ%×+Ò+¨CÑ0Ô0°Ô4×:Ò:¸3Ñ?Ô?ÀÔB€HØ 9× AÒ AÐBXÐZbÑ cÔ cÐØ7€OÔØUÕ7¸Ô8TÑUÔUÐVeÑfÔf€OÝ% oÑ6Ô6€CÔØ€Jr$   c                 óÀ   — g }|                       ¦   «         D ]F}t          |t          t          f¦  «        r|t          |¦  «        z  }Œ1|                     |¦  «         ŒG|S rO   )Úvaluesr'   r(   r)   Úappend)r,   Úresultr!   s      r"   Ú
get_valuesrÚ   þ  sd   € Ø€FØ×%Ò%Ñ'Ô'ð !ð !ˆÝ�e�d¥E˜]Ñ+Ô+ð 	!Ø•d˜5‘k”kÑ!ˆFˆFà�MŠM˜%Ñ Ô Ð Ð à€Mr$   c           
      óæ  ‡ — |€d S t          |t          ¦  «        rt          ˆ fd„|D ¦   «         ¦  «        S t          |t          ¦  «        r ˆ fd„|                     ¦   «         D ¦   «         S t	          ‰ |¦  «        rt          ‰ |¦  «        S t          j        d¦  «        }‰ |k    r8	 t          ||¦  «        S # t          $ r t          d|› d‰ › d|› d�¦  «        ‚w xY wt          d|› d|› d�¦  «        ‚)	Nc              3   ó8   •K  — | ]}t          ‰|¦  «        V — Œd S rO   ©Úgetattribute_from_module)r    ÚaÚmodules     €r"   rR   z+getattribute_from_module.<locals>.<genexpr>  s.   øè è € ÐGÐG¸QÕ-¨f°aÑ8Ô8ÐGÐGÐGÐGÐGÐGr$   c                 ó8   •— i | ]\  }}|t          ‰|¦  «        “ŒS r   rÝ   )r    ÚkÚvrà   s      €r"   r#   z,getattribute_from_module.<locals>.<dictcomp>  s*   ø€ ÐPÐPÐP¹4¸1¸a�Õ+¨F°AÑ6Ô6ÐPÐPÐPr$   ÚtransformerszCould not find z neither in z nor in ú!z in )
r'   r)   ÚdictÚitemsrV   r*   Ú	importlibÚimport_modulerÞ   rd   )rà   ÚattrÚtransformers_modules   `  r"   rÞ   rÞ   	  s?  ø€ Ø€|ØˆtÝ�$�ÑÔð HÝÐGÐGÐGÐGÀ$ÐGÑGÔGÑGÔGÐGÝ�$�ÑÔð QØPÐPÐPÐPÀ4Ç:Â:Á<Ä<ÐPÑPÔPÐPÝˆv�tÑÔð %Ý�v˜tÑ$Ô$Ð$õ $Ô1°.ÑAÔAÐàÐ$Ò$Ð$ð	iÝ+Ð,?ÀÑFÔFÐFøÝð 	ið 	ið 	iÝÐg¨tÐgÐgÀÐgÐgÐQdÐgÐgÐgÑhÔhÐhð	iøøøõ ÐK¨4ÐKÐKÐ5HÐKÐKÐKÑLÔLÐLs   Â&B6 Â6$Cc                 óv  — dt          | j        ¦  «        vr| S dt          | j        ¦  «        v r| S t          | d¦  «        odt          t	          | d¦  «        ¦  «        v}t          | d¦  «        odt          t	          | d¦  «        ¦  «        v}|s|r&t          | j        | t          fi | j        ¥¦  «        }|S | S )a©  
    Adds `GenerationMixin` to the inheritance of `model_class`, if `model_class` is a PyTorch model.

    This function is used for backwards compatibility purposes: in v4.45, we've started a deprecation cycle to make
    `PreTrainedModel` stop inheriting from `GenerationMixin`. Without this function, older models dynamically loaded
    from the Hub may not have the `generate` method after we remove the inheritance.
    ztorch.nn.modules.module.Moduler   ÚgenerateÚprepare_inputs_for_generation)	r¥   Ú__mro__Ú	__bases__rV   r*   r&   r   r   Ú__dict__)rl   Úhas_custom_generate_in_classÚhas_custom_prepare_inputsÚ!model_class_with_generation_mixins       r"   r_   r_     s   € ð (­s°;Ô3FÑ/GÔ/GÐGÐGØÐð �C Ô 5Ñ6Ô6Ð6Ð6ØÐõ $+¨;¸
Ñ#CÔ#Cð $ÐHYÕadÝ�˜ZÑ(Ô(ñbô bð IÐ õ !(¨Ð5TÑ UÔ Uð !ÐZkÕsvÝ�Ð<Ñ=Ô=ñtô tð [Ðð $ð 1Ð'@ð 1Ý,0ØÔ  ;µÐ"@ÐBZÀ[ÔEYÐBZñ-
ô -
Ð)ð 1Ð0ØÐr$   c                   ób  — e Zd ZdZdd„Zdefd„Zdee         de	fd„Z
d„ Zdeee                  fd	„Zdee         d
ede	ez  fd„Zdefd„Zdee	         fd„Zdeeee         e	f                  fd„Zdeee                  fd„Zdedefd„Zddee         ez  de	ddfd„Zd„ Zed„ ¦   «         ZdS )Ú_LazyAutoMappinga  
    A mapping config to object (model or tokenizer for instance) that will load keys and values when it is accessed.

    Args:
        - config_mapping: The map model type to config class
        - model_mapping: The map model type to model (or tokenizer) class
    r3   Nc                 óœ   — || _         d„ |                     ¦   «         D ¦   «         | _        || _        | | j        _        i | _        i | _        d S )Nc                 ó   — i | ]\  }}||“Œ	S r   r   )r    râ   rã   s      r"   r#   z-_LazyAutoMapping.__init__.<locals>.<dictcomp>J  s   € Ð'PÐ'PÐ'P±°°A¨¨1Ð'PÐ'PÐ'Pr$   )Ú_config_mappingrç   Ú_reverse_config_mappingrW   Ú_extra_contentÚ_modules)r7   Úconfig_mappingr,   s      r"   r:   z_LazyAutoMapping.__init__H  sR   € Ø-ˆÔØ'PÐ'P¸×9MÒ9MÑ9OÔ9OÐ'PÑ'PÔ'PˆÔ$Ø+ˆÔØ-1ˆÔÔ*Ø ˆÔØˆŒˆˆr$   c                 óê   — t          | j                             ¦   «         ¦  «                             | j                             ¦   «         ¦  «        }t          |¦  «        t          | j        ¦  «        z   S rO   )Úsetrù   ÚkeysÚintersectionrW   r¿   rû   )r7   Úcommon_keyss     r"   Ú__len__z_LazyAutoMapping.__len__P  sY   € Ý˜$Ô.×3Ò3Ñ5Ô5Ñ6Ô6×CÒCÀDÔDW×D\ÒD\ÑD^ÔD^Ñ_Ô_ˆÝ�;ÑÔ¥# dÔ&9Ñ":Ô":Ñ:Ð:r$   Úkeyc                 óz  ‡— ‰| j         v r| j         ‰         S | j        ‰j                 }|| j        v r#| j        |         }|                      ||¦  «        S ˆfd„| j                             ¦   «         D ¦   «         }|D ]0}|| j        v r%| j        |         }|                      ||¦  «        c S Œ1t          ‰¦  «        ‚)Nc                 ó0   •— g | ]\  }}|‰j         k    ¯|‘ŒS r   r   )r    râ   rã   r  s      €r"   ú
<listcomp>z0_LazyAutoMapping.__getitem__.<locals>.<listcomp>]  s)   ø€ ÐWÐWÐW™T˜Q ÀQÈ#Ì,ÒEVÐEV�qÐEVÐEVÐEVr$   )rû   rú   r   rW   Ú_load_attr_from_modulerù   rç   ÚKeyError)r7   r  Ú
model_typeÚ
model_nameÚmodel_typesÚmtypes    `    r"   Ú__getitem__z_LazyAutoMapping.__getitem__T  så   ø€ Ø�$Ô%Ð%Ð%ØÔ& sÔ+Ð+ØÔ1°#´,Ô?ˆ
Ø˜Ô,Ð,Ð,ØÔ,¨ZÔ8ˆJØ×.Ò.¨z¸:ÑFÔFÐFð XÐWÐWÐW TÔ%9×%?Ò%?Ñ%AÔ%AÐWÑWÔWˆØ ð 	Fð 	FˆEØ˜Ô+Ð+Ð+Ø!Ô0°Ô7�
Ø×2Ò2°5¸*ÑEÔEÐEÐEÐEð ,õ �s‰mŒmÐr$   c                 ó¨   — t          |¦  «        }|| j        vr t          j        d|› �d¦  «        | j        |<   t	          | j        |         |¦  «        S )NrT   ztransformers.models)r   rü   rè   ré   rÞ   )r7   r
  rê   Úmodule_names       r"   r  z'_LazyAutoMapping._load_attr_from_moduled  sV   € Ý/°
Ñ;Ô;ˆØ˜dœmÐ+Ð+Ý)2Ô)@ÐARÀ[ÐARÐARÐTiÑ)jÔ)jˆDŒM˜+Ñ&Ý'¨¬°kÔ(BÀDÑIÔIÐIr$   c                 ó    ‡ — ˆ fd„‰ j                              ¦   «         D ¦   «         }|t          ‰ j                             ¦   «         ¦  «        z   S )Nc                 óT   •— g | ]$\  }}|‰j         v ¯‰                     ||¦  «        ‘Œ%S r   )rW   r  ©r    r  r   r7   s      €r"   r  z)_LazyAutoMapping.keys.<locals>.<listcomp>k  sE   ø€ ð 
ð 
ð 
á��TØ�dÔ)Ð)Ð)ð ×'Ò'¨¨TÑ2Ô2à)Ð)Ð)r$   )rù   rç   r(   rû   r   )r7   Úmapping_keyss   ` r"   r   z_LazyAutoMapping.keysj  s^   ø€ ð
ð 
ð 
ð 
à!Ô1×7Ò7Ñ9Ô9ð
ñ 
ô 
ˆð
 �d 4Ô#6×#;Ò#;Ñ#=Ô#=Ñ>Ô>Ñ>Ð>r$   Údefaultc                 óR   — 	 |                       |¦  «        S # t          $ r |cY S w xY wrO   )r  r	  )r7   r  r  s      r"   rb   z_LazyAutoMapping.getr  s?   € ð	Ø×#Ò# CÑ(Ô(Ð(øÝð 	ð 	ð 	ØˆNˆNˆNð	øøøs   ‚ —&¥&c                 óD   — t          |                      ¦   «         ¦  «        S rO   )Úboolr   ©r7   s    r"   Ú__bool__z_LazyAutoMapping.__bool__x  ó   € Ý�D—I’I‘K”KÑ Ô Ð r$   c                 ó    ‡ — ˆ fd„‰ j                              ¦   «         D ¦   «         }|t          ‰ j                             ¦   «         ¦  «        z   S )Nc                 óT   •— g | ]$\  }}|‰j         v ¯‰                     ||¦  «        ‘Œ%S r   )rù   r  r  s      €r"   r  z+_LazyAutoMapping.values.<locals>.<listcomp>|  sE   ø€ ð 
ð 
ð 
á��TØ�dÔ*Ð*Ð*ð ×'Ò'¨¨TÑ2Ô2à*Ð*Ð*r$   )rW   rç   r(   rû   r×   )r7   Úmapping_valuess   ` r"   r×   z_LazyAutoMapping.values{  s^   ø€ ð
ð 
ð 
ð 
à!Ô0×6Ò6Ñ8Ô8ð
ñ 
ô 
ˆð
 ¥ TÔ%8×%?Ò%?Ñ%AÔ%AÑ BÔ BÑBÐBr$   c                 ó|   ‡ — ˆ fd„‰ j         D ¦   «         }|t          ‰ j                             ¦   «         ¦  «        z   S )Nc                 ó¦   •— g | ]M}|‰j         v ¯‰                     |‰j         |         ¦  «        ‰                     |‰j        |         ¦  «        f‘ŒNS r   )rù   r  rW   )r    r  r7   s     €r"   r  z*_LazyAutoMapping.items.<locals>.<listcomp>„  sm   ø€ ð 
ð 
ð 
ð
 Ø�dÔ*Ð*Ð*ð	 ×+Ò+¨C°Ô1EÀcÔ1JÑKÔKØ×+Ò+¨C°Ô1DÀSÔ1IÑJÔJðð
 +Ð*Ð*r$   )rW   r(   rû   rç   )r7   Úmapping_itemss   ` r"   rç   z_LazyAutoMapping.itemsƒ  sT   ø€ ð
ð 
ð 
ð 
ð
 Ô*ð
ñ 
ô 
ˆð �t DÔ$7×$=Ò$=Ñ$?Ô$?Ñ@Ô@Ñ@Ð@r$   c                 óD   — t          |                      ¦   «         ¦  «        S rO   )Úiterr   r  s    r"   Ú__iter__z_LazyAutoMapping.__iter__Ž  r  r$   Úitemc                 óŽ   — || j         v rdS t          |d¦  «        r|j        | j        vrdS | j        |j                 }|| j        v S )NTr   F)rû   rV   r   rú   rW   )r7   r%  r
  s      r"   Ú__contains__z_LazyAutoMapping.__contains__‘  sX   € Ø�4Ô&Ð&Ð&Ø�4Ý�t˜ZÑ(Ô(ð 	¨D¬MÀÔA]Ð,]Ð,]Ø�5ØÔ1°$´-Ô@ˆ
Ø˜TÔ0Ð0Ð0r$   FÚvaluec                 ó  — t          |d¦  «        r>|j        | j        v r0| j        |j                 }|| j        v r|st	          d|› d�¦  «        ‚t          |dd¦  «                             d¦  «        rdS || j        |<   dS )z7
        Register a new model in this mapping.
        r   ú'z*' is already used by a Transformers model.rX   r¼   r>   N)rV   r   rú   rW   rd   r*   rY   rû   )r7   r  r(  rC   r
  s        r"   r]   z_LazyAutoMapping.register™  s    € õ �3˜
Ñ#Ô#ð 	V¨¬¸Ô8TÐ(TÐ(TØÔ5°c´lÔCˆJØ˜TÔ0Ð0Ð0¸Ð0Ý Ð!T SÐ!TÐ!TÐ!TÑUÔUÐUõ �3˜ bÑ)Ô)×4Ò4°_ÑEÔEð 	ØˆFð $)ˆÔ˜CÑ Ð Ð r$   c                 ó\   — | j         j        | j        | j        t	          | j        ¦  «        ffS rO   )r6   Ú_from_picklerù   rW   ræ   rû   r  s    r"   Ú
__reduce__z_LazyAutoMapping.__reduce__®  s/   € àŒNÔ'ØÔ! 4Ô#6½¸TÔ=PÑ8QÔ8QÐRð
ð 	
r$   c                 ó,   —  | ||¦  «        }||_         |S rO   )rû   )rf   rý   r,   Úextra_contentÚobjs        r"   r,  z_LazyAutoMapping._from_pickle´  s    € àˆc�. -Ñ0Ô0ˆØ*ˆÔØˆ
r$   r¡   r¢   )r   rX   r£   rÎ   r:   Úintr  r&   r   Ú_LazyAutoMappingValuer  r  r(   r   r   rb   r  r  r×   r)   rç   r   r$  r'  r¥   r]   r-  r¤   r,  r   r$   r"   rö   rö   ?  s  € € € € € ðð ðð ð ð ð;˜ð ;ð ;ð ;ð ;ð˜tÐ$4Ô5ð Ð:Oð ð ð ð ð Jð Jð Jð?�d˜4Ð 0Ô1Ô2ð ?ð ?ð ?ð ?ð�tÐ,Ô-ð ¸ð Ð?TÐWYÑ?Yð ð ð ð ð!˜$ð !ð !ð !ð !ðC˜Ð2Ô3ð Cð Cð Cð Cð	A�t˜E $Ð'7Ô"8Ð:OÐ"OÔPÔQð 	Að 	Að 	Að 	Að!˜( 4Ð(8Ô#9Ô:ð !ð !ð !ð !ð1 ð 1¨$ð 1ð 1ð 1ð 1ð)ð )˜DÐ!1Ô2°SÑ8ð )ÐAVð )Ðkoð )ð )ð )ð )ð*
ð 
ð 
ð ðð ñ „[ðð ð r$   rö   rÚ   )r¼   )rÃ   r¼   )7rÎ   rŽ   rè   r�   r’   Úcollectionsr   Úcollections.abcr   Útypingr   r   Úconfiguration_utilsr   Údynamic_module_utilsr	   r
   Úutilsr   r   r   r   r   r   r   r   r   r   Úconfiguration_autor   r   r   Ú
generationr   Ú
get_loggerr   Úloggerr   r)   r&   r2  rÍ   rÏ   rÐ   r0   r2   r¨   r¥   rÂ   rÕ   rÚ   rÞ   r_   rö   Ú__all__r   r$   r"   ú<module>r>     sú  ðð 4Ð 3à €€€Ø Ð Ð Ð Ø €€€Ø 	€	€	€	Ø #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ð Ð à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø \Ð \Ð \Ð \Ð \Ð \Ð \Ð \ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð iÐ hÐ hÐ hÐ hÐ hÐ hÐ hÐ hÐ hð ÐÑÔð .Ø-Ð-Ð-Ð-Ð-Ð-ð 
ˆÔ	˜HÑ	%Ô	%€à€WˆT�]„]€à˜d 3œi¨$Ñ.°°S´	¸DÑ0@Ð@ÔAÐ ð€ðÐ ð4Z#Ð ðzð ð ð iRð iRð iRð iRð iRñ iRô iRð iRðX$]ð $]ð $]ð $]ð $]Ð0ñ $]ô $]ð $]ðNð ¨ð ð ð ð ðð °3ð Ðbeð ð ð ð ð<ð ð ðMð Mð Mð,ð ð ð@yð yð yð yð y�{ 4Ð(8Ô#9Ð;PÐ#PÔQñ yô yð yðx ˆ.€€€r$   