Ë
    S^(h‚¯  ã                   ó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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j8                  e«      ZdZdZ dZ!dZ"dZ#d„ Z$ G d„ d«      Z% G d„ de%«      Z&dd„Z'dd„Z(d„ Z)d„ Z*d„ Z+ G d„ de«      Z,y)z-Factory function to build auto-model classes.é    N)ÚOrderedDicté   )ÚPretrainedConfig)Úget_class_from_dynamic_moduleÚresolve_trust_remote_code)	ÚCONFIG_NAMEÚcached_fileÚ	copy_funcÚextract_commit_hashÚfind_adapter_config_fileÚis_peft_availableÚis_torch_availableÚloggingÚrequires_backendsé   )Ú
AutoConfigÚmodel_type_to_module_nameÚ!replace_list_option_in_docstrings)ÚGenerationMixinaJ  
    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).
ax  
        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)), or `"flash_attention_2"` (using [Dao-AILab/flash-attention](https://github.com/Dao-AILab/flash-attention)). 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)
        ```
ac  
        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/`.
                    - A path or url to a *tensorflow index checkpoint file* (e.g, `./tf_model/model.ckpt.index`). In
                      this case, `from_tf` should be set to `True` and a configuration object should be provided as
                      `config` argument. This loading path is slower than converting the TensorFlow checkpoint in a
                      PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
            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.
            from_tf (`bool`, *optional*, defaults to `False`):
                Load the model weights from a TensorFlow checkpoint save file (see docstring of
                `pretrained_model_name_or_path` argument).
            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.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            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 ot 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

        >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
        >>> config = AutoConfig.from_pretrained("./tf_model/shortcut_placeholder_tf_model_config.json")
        >>> model = BaseAutoModelClass.from_pretrained(
        ...     "./tf_model/shortcut_placeholder_tf_checkpoint.ckpt.index", from_tf=True, 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

        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/`.
                    - A path or url to a *PyTorch state_dict save file* (e.g, `./pt_model/pytorch_model.bin`). In this
                      case, `from_pt` should be set to `True` and a configuration object should be provided as `config`
                      argument. This loading path is slower than converting the PyTorch model in a TensorFlow model
                      using the provided conversion scripts and loading the TensorFlow model afterwards.
            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.
            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.
            from_pt (`bool`, *optional*, defaults to `False`):
                Load the model weights from a PyTorch checkpoint save file (see docstring of
                `pretrained_model_name_or_path` argument).
            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.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            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 ot 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

        >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
        >>> config = AutoConfig.from_pretrained("./pt_model/shortcut_placeholder_pt_model_config.json")
        >>> model = BaseAutoModelClass.from_pretrained(
        ...     "./pt_model/shortcut_placeholder_pytorch_model.bin", from_pt=True, config=config
        ... )
        ```
c                 ó  — |t        | «         }t        |t        t        f«      s|S |D �ci c]  }|j                  |“Œ }}t        | dg «      }|D ]/  }||v r||   c S d|› �|v r
|d|› �   c S d|› �|v sŒ'|d|› �   c S  |d   S c c}w )NÚarchitecturesÚTFÚFlaxr   )ÚtypeÚ
isinstanceÚlistÚtupleÚ__name__Úgetattr)ÚconfigÚmodel_mappingÚsupported_modelsÚmodelÚname_to_modelr   Úarchs          úc/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.pyÚ_get_model_classr'   ƒ  sÃ   € Ø$¤T¨&£\Ñ2ÐÜÐ&¬¬u¨Ô6ØÐà8HÖI¨u�U—^‘^ UÑ*ÐI€MÐIÜ˜F O°RÓ8€MØò 0ˆØ�=Ñ Ø  Ñ&Ò&Ø�$�ˆ[˜MÑ)Ø  2 d V Ñ-Ò-Ø�D�6ˆ]˜mÒ+Ø  4¨ v Ñ/Ò/ð0ð ˜AÑÐùò Js   «Bc                   ób   — e Zd ZdZd„ Zed„ «       Zededefd„«       Zed„ «       Z	ed	d„«       Z
y)
Ú_BaseAutoModelClassNc                 ó¢   — 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.)ÚEnvironmentErrorÚ	__class__r   )ÚselfÚargsÚkwargss      r&   Ú__init__z_BaseAutoModelClass.__init__›  sR   € ÜØ�~‰~×&Ñ&Ð'ð (ØŸ.™.×1Ñ1Ð2ð 3Ø—‘×'Ñ'Ð(Ð(FðHó
ð 	
ó    c                 óp  — |j                  dd «      }t        |d«      xr | j                  |j                  v }t	        |«      | j
                  j                  «       v }t        ||j                  ||«      }|r›|r™|j                  | j                     }d|v r|j                  d«      \  }}n|j                  }t        ||fi |¤Ž}| j                  |j                  |d¬«       |j                  dd «      }	t        |«      } |j                  |fi |¤ŽS t	        |«      | j
                  j                  «       v r)t!        || j
                  «      } |j                  |fi |¤ŽS t#        d|j                  › d| j                  › d	d
j%                  d„ | j
                  j                  «       D «       «      › d�«      ‚)NÚtrust_remote_codeÚauto_mapz--T©Úexist_okÚcode_revisionú!Unrecognized configuration class ú for this kind of AutoModel: ú.
Model type should be one of ú, c              3   ó4   K  — | ]  }|j                   –— Œ y ­w©N©r   ©Ú.0Úcs     r&   ú	<genexpr>z2_BaseAutoModelClass.from_config.<locals>.<genexpr>¼  ó   è ø€ Ò4cÀA°Q·ZµZÑ4cùó   ‚ú.)ÚpopÚhasattrr   r4   r   Ú_model_mappingÚkeysr   Ú_name_or_pathÚsplitÚname_or_pathr   Úregisterr,   Ú$add_generation_mixin_to_remote_modelÚ_from_configr'   Ú
ValueErrorÚjoin)
Úclsr    r/   r3   Úhas_remote_codeÚhas_local_codeÚ	class_refÚrepo_idÚmodel_classÚ_s
             r&   Úfrom_configz_BaseAutoModelClass.from_config¢  s¦  € à"ŸJ™JÐ':¸DÓAÐÜ! &¨*Ó5ÒY¸#¿,¹,È&Ï/É/Ð:YˆÜ˜f›¨×);Ñ);×)@Ñ)@Ó)BÐBˆÜ5Ø˜v×3Ñ3°^À_ó
Ðñ Ñ0ØŸ™¨¯©Ñ5ˆIØ�yÑ Ø%.§_¡_°TÓ%:Ñ"�™à ×-Ñ-�Ü7¸	À7ÑUÈfÑUˆKØ�L‰L˜×)Ñ)¨;ÀˆLÔFØ—
‘
˜?¨DÓ1ˆAÜ>¸{ÓKˆKØ+�;×+Ñ+¨FÑ=°fÑ=Ð=Ü�&‹\˜S×/Ñ/×4Ñ4Ó6Ñ6Ü*¨6°3×3EÑ3EÓFˆKØ+�;×+Ñ+¨FÑ=°fÑ=Ð=äØ/°×0@Ñ0@Ð/AÐA^Ð_b×_kÑ_kÐ^lð m+Ø+/¯9©9Ñ4cÈ×I[ÑI[×I`ÑI`ÓIbÔ4cÓ+cÐ*dÐdeðgó
ð 	
r1   r    Úreturnc                 ó   — |S )z`Additional autoclass-specific config post-loading manipulation. May be overridden in subclasses.© )rR   r    s     r&   Ú_prepare_config_for_auto_classz2_BaseAutoModelClass._prepare_config_for_auto_class¿  s	   € ð ˆr1   c                 ó(  — |j                  dd «      }|j                  dd «      }d|d<   g d¢}|D �ci c]  }||v sŒ||j                  |«      “Œ }}|j                  dd «      }	|j                  dd «      }
|j                  dd «      }|j                  d	d «      }|j                  d
d «      }|�)t        j                  dt        «       |�t	        d«      ‚|}|�||d	<   |
€?t        |t        «      s"t        |t        fddddœ|¤Ž}t        ||
«      }
nt        |dd «      }
t        «       rQ|€	i }|�||d	<   t        |fd|
i|¤Ž}|�6t        |dd¬«      5 }t        j                  |«      }||d<   |d   }d d d «       t        |t        «      s²t!        j"                  |«      }|j%                  dd «      dk(  r|j                  d«      }|j%                  dd «      �|j                  d«      }t'        j(                  |fd||	|
dœ|¤|¤Ž\  }}|j%                  dd «      dk(  rd|d<   |j%                  dd «      �|d   |d<   t+        |d«      xr | j,                  |j.                  v }t1        |«      | j2                  j5                  «       v }t7        ||||«      }||d<   |r�|r|j.                  | j,                     }t9        ||fd|	i|¤|¤Ž}|j                  dd «      }| j;                  |j<                  |d¬«       t?        |«      } |j(                  |g|¢­d|i|¤|¤ŽS t1        |«      | j2                  j5                  «       v ritA        || j2                  «      }|jB                  |jD                  j%                  dd «      k(  r|jG                  «       } |j(                  |g|¢­d|i|¤|¤ŽS t	        d|j<                  › d| j,                  › ddjI                  d„ | j2                  j5                  «       D «       «      › d �«      ‚c c}w # 1 sw Y   �Œ—xY w)!Nr    r3   TÚ
_from_auto)	Ú	cache_dirÚforce_downloadÚlocal_files_onlyÚproxiesÚresume_downloadÚrevisionÚ	subfolderÚuse_auth_tokenÚtokenr7   Ú_commit_hashÚadapter_kwargsrh   rg   zrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.zV`token` and `use_auth_token` are both specified. Please set only the argument `token`.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Úquantization_config)Úreturn_unused_kwargsr3   r7   ri   r4   r5   Útext_configr8   r9   r:   r;   c              3   ó4   K  — | ]  }|j                   –— Œ y ­wr=   r>   r?   s     r&   rB   z6_BaseAutoModelClass.from_pretrained.<locals>.<genexpr>@  rC   rD   rE   )%rF   ÚwarningsÚwarnÚFutureWarningrP   r   r   r	   r   r   r   r   r   ÚopenÚjsonÚloadÚcopyÚdeepcopyÚgetr   Úfrom_pretrainedrG   r   r4   r   rH   rI   r   r   rM   r,   rN   r'   Úconfig_classÚsub_configsÚget_text_configrQ   )rR   Úpretrained_model_name_or_pathÚ
model_argsr/   r    r3   Úhub_kwargs_namesÚnameÚ
hub_kwargsr7   Úcommit_hashrj   rh   rg   Úresolved_config_fileÚmaybe_adapter_pathÚfÚadapter_configÚkwargs_origrX   rS   rT   rU   rW   s                           r&   r�   z#_BaseAutoModelClass.from_pretrainedÄ  sÍ  € à—‘˜H dÓ+ˆØ"ŸJ™JÐ':¸DÓAÐØ#ˆˆ|Ñò

Ðð :JÖ\°ÈTÐU[Ê^�d˜FŸJ™J tÓ,Ñ,Ð\ˆ
Ð\ØŸ
™
 ?°DÓ9ˆØ—j‘j °Ó6ˆØŸ™Ð$4°dÓ;ˆà—‘˜w¨Ó-ˆØ#Ÿ™Ð(8¸$Ó?ˆØÐ%Ü�M‰Mð EÜôð Ð Ü Ølóð ð #ˆEàÐØ"'ˆJ�wÑàÐÜ˜fÔ&6Ô7ä'2Ø1Üð(ð 6;Ø:?Ø<Añ(ð !ñ(Ð$ô 2Ð2FÈÓT‘ä% f¨n¸dÓC�äÔØÐ%Ø!#�ØÐ$Ø.3�N 7Ñ+ä!9Ø-ñ"Ø<Gð"ØKYñ"Ðð "Ð-ÜÐ,¨c¸GÔDð ^ÈÜ%)§Y¡Y¨q£\�Nà<Y�NÐ#8Ñ9Ø4BÐC\Ñ4]Ð1÷	^ô ˜&Ô"2Ô3ÜŸ-™-¨Ó/ˆKð �z‰z˜-¨Ó.°&Ò8Ø—J‘J˜}Ó-�à�z‰zÐ/°Ó6ÐBØ—J‘JÐ4Ó5�ä'×7Ñ7Ø-ðà%)Ø"3Ø+Ø(ñð ðð ñ‰NˆF�Fð �‰˜}¨dÓ3°vÒ=Ø(.��}Ñ%Ø�‰Ð4°dÓ;ÐGØ0;Ð<QÑ0R�Ð,Ñ-ä! &¨*Ó5ÒY¸#¿,¹,È&Ï/É/Ð:YˆÜ˜f›¨×);Ñ);×)@Ñ)@Ó)BÐBˆÜ5ØÐ<¸nÈoó
Ðð
 $2ˆÐÑ áÑ0ØŸ™¨¯©Ñ5ˆIÜ7ØÐ8ñØHUðØYcðØgmñˆKð —‘˜°Ó5ˆAØ�L‰L˜×)Ñ)¨;ÀˆLÔFÜ>¸{ÓKˆKØ.�;×.Ñ.Ø-ðØ0:òØCIðØMWðØ[añð ô �&‹\˜S×/Ñ/×4Ñ4Ó6Ñ6Ü*¨6°3×3EÑ3EÓFˆKØ×'Ñ'¨6×+=Ñ+=×+AÑ+AÀ-ÐQUÓ+VÒVØ×/Ñ/Ó1�Ø.�;×.Ñ.Ø-ðØ0:òØCIðØMWðØ[añð ô Ø/°×0@Ñ0@Ð/AÐA^Ð_b×_kÑ_kÐ^lð m+Ø+/¯9©9Ñ4cÈ×I[ÑI[×I`ÑI`ÓIbÔ4cÓ+cÐ*dÐdeðgó
ð 	
ùòU ]÷^^ñ ^ús   ²	P¼PÅ PÐPc                 óÖ   — t        |d«      r?|j                  j                  |j                  k7  rt        d|j                  › d|› d�«      ‚| j                  j                  |||¬«       y)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.
        r‚   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!r5   N)rG   r‚   r   rP   rH   rM   )rR   r‚   rW   r6   s       r&   rM   z_BaseAutoModelClass.registerC  sw   € ô �; Ô/°K×4LÑ4L×4UÑ4UÐYe×YnÑYnÒ4nÜð6Ø6A×6NÑ6NÐ5OÐO_Ð`lÐ_mð n.ð.óð ð
 	×Ñ×#Ñ# L°+ÈÐ#ÕQr1   ©F)r   Ú
__module__Ú__qualname__rH   r0   ÚclassmethodrY   r   r]   r�   rM   r\   r1   r&   r)   r)   —  sq   „ à€Nò
ð ñ
ó ð
ð8 ðÐ4Dð ÐIYò ó ðð ñ|
ó ð|
ð| òRó ñRr1   r)   c                   ó@   ‡ — 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} |j                  d |«       «      }|j	                  dd «      �t        d«      ‚|j	                  dd	«      rt        d
«      ‚|j                  d|j                  «      }|j                  d|j                  «      }|j                  d|j                  «      }|j                  d|j                  «      }	 ||||||	¬«      }t        ‰
| �,  |f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Úuse_pretrained_backboneÚout_indices)Úbackboner�   rž   rŸ   r    )r   Úmodels.timm_backbonerš   rF   r€   rP   r�   rž   rŸ   r    ÚsuperrY   )rR   r…   r†   r/   rš   r    r�   rž   rŸ   r    r,   s             €r&   Ú#_load_timm_backbone_from_pretrainedz:_BaseAutoBackboneClass._load_timm_backbone_from_pretrained[  së   ø€ ä˜# ¨&Ð1Ô2Ý>à—‘˜HÑ&8Ó&:Ó;ˆà�:‰:�n dÓ+Ð7ÜÐOÓPÐPà�:‰:Ð+¨UÔ3ÜÐ_Ó`Ð`à—z‘z .°&×2EÑ2EÓFˆØŸ
™
 ?°F×4HÑ4HÓIˆØ"(§*¡*Ð-FÈ×HfÑHfÓ"gÐØ—j‘j °×0BÑ0BÓCˆÙ#Ø2Ø%Ø'Ø$;Ø#ô
ˆô ‰wÑ" 6Ñ4¨VÑ4Ð4r1   c                 ó~   •— |j                  dd«      }|r | j                  |g|¢­i |¤ŽS t        ‰| �  |g|¢­i |¤ŽS )NÚuse_timm_backboneF)rF   r¤   r£   r�   )rR   r…   r†   r/   r¦   r,   s        €r&   r�   z&_BaseAutoBackboneClass.from_pretrainedu  sT   ø€ à"ŸJ™JÐ':¸EÓBÐÙØ:�3×:Ñ:Ð;XÐpÐ[eÒpÐioÑpÐpä‰wÑ&Ð'DÐ\ÀzÒ\ÐU[Ñ\Ð\r1   )r   r’   r“   rH   r”   r¤   r�   Ú__classcell__)r,   s   @r&   r–   r–   W  s0   ø„ à€Nàó5ó ð5ð2 ó]ó ô]r1   r–   c                 ón   — t        |«      dkD  r| j                  dd|› d�«      S | j                  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)Ú	docstringÚhead_docs     r&   Úinsert_head_docr­   ~  sK   € Ü
ˆ8ƒ}�qÒØ× Ñ Ø6Ø>¸x¸jÈÐPó
ð 	
ð ×ÑØ2Ð4cóð r1   c                 ó^  — | j                   }| j                  }t        t        |¬«      }|j	                  d|«      | _        t        t        j                  «      }t        t        |¬«      }|j	                  d|«      }|j	                  d|«      }||_         t        |j                   d¬«      |«      }t        |«      | _        |j                  d«      rt        }n|j                  d«      rt        }nt        }t        t        j                   «      }	t        ||¬«      }|j	                  d|«      }|j	                  d|«      }|j#                  d«      d	   j#                  d
«      d   }
|j	                  d|
«      }||	_         t        |j                   «      |	«      }	t        |	«      | _        | S )N)r¬   ÚBaseAutoModelClassÚcheckpoint_placeholderF)Úuse_model_typesr   r   ú/éÿÿÿÿú-r   Úshortcut_placeholder)rH   r   r­   ÚCLASS_DOCSTRINGrª   Ú__doc__r
   r)   rY   ÚFROM_CONFIG_DOCSTRINGr   r”   Ú
startswithÚFROM_PRETRAINED_TF_DOCSTRINGÚFROM_PRETRAINED_FLAX_DOCSTRINGÚFROM_PRETRAINED_TORCH_DOCSTRINGr�   rK   )rR   Úcheckpoint_for_exampler¬   r!   rˆ   Úclass_docstringrY   Úfrom_config_docstringÚfrom_pretrained_docstringr�   Úshortcuts              r&   Úauto_class_updaterÂ   ‰  s“  € à×&Ñ&€MØ�<‰<€DÜ%¤oÀÔI€OØ!×)Ñ)Ð*>ÀÓE€C„Kô Ô/×;Ñ;Ó<€KÜ+Ô,AÈHÔUÐØ1×9Ñ9Ð:NÐPTÓUÐØ1×9Ñ9Ð:RÐTjÓkÐØ/€KÔØhÔ3°M×4PÑ4PÐbgÔhÐitÓu€KÜ! +Ó.€C„Oà‡��tÔÜ$@Ñ!Ø	�‰˜Ô	 Ü$BÑ!ä$CÐ!ÜÔ 3× CÑ CÓD€OÜ /Ð0IÐT\Ô ]ÐØ 9× AÑ AÐBVÐX\Ó ]ÐØ 9× AÑ AÐBZÐ\rÓ sÐØ%×+Ñ+¨CÓ0°Ñ4×:Ñ:¸3Ó?ÀÑB€HØ 9× AÑ AÐBXÐZbÓ cÐØ7€OÔØUÔ7¸×8TÑ8TÓUÐVeÓf€OÜ% oÓ6€CÔØ€Jr1   c                 ó    — g }| j                  «       D ]8  }t        |t        t        f«      r|t        |«      z  }Œ(|j	                  |«       Œ: |S r=   )Úvaluesr   r   r   Úappend)r!   Úresultr#   s      r&   Ú
get_valuesrÇ   ¬  sN   € Ø€FØ×%Ñ%Ó'ò !ˆÜ�eœd¤E˜]Ô+Ø”d˜5“kÑ!‰Fà�M‰M˜%Õ ð	!ð €Mr1   c           
      ó8  ‡ — |€y t        |t        «      rt        ˆ fd„|D «       «      S t        ‰ |«      rt        ‰ |«      S t	        j
                  d«      }‰ |k7  r	 t        ||«      S t        d|› d|› d�«      ‚# t        $ r t        d|› d‰ › d|› d�«      ‚w xY w)Nc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­wr=   )Úgetattribute_from_module)r@   ÚaÚmodules     €r&   rB   z+getattribute_from_module.<locals>.<genexpr>»  s   øè ø€ ÒG¸QÔ-¨f°a×8ÑGùs   ƒÚtransformerszCould not find z neither in z nor in ú!z in )r   r   rG   r   Ú	importlibÚimport_modulerÊ   rP   )rÌ   ÚattrÚtransformers_modules   `  r&   rÊ   rÊ   ·  sÁ   ø€ Ø€|ØÜ�$œÔÜÓGÀ$ÔGÓGÐGÜˆv�tÔÜ�v˜tÓ$Ð$ô $×1Ñ1°.ÓAÐàÐ$Ò$ð	iÜ+Ð,?ÀÓFÐFô ˜?¨4¨&°Ð5HÐ4IÈÐKÓLÐLøô ò 	iÜ˜¨t¨f°LÀÀÈÐQdÐPeÐefÐgÓhÐhð	iús   ÁA: Á:Bc                 ó$  — dt        | j                  «      vr| S dt        | j                  «      v r| S dt        t        | d«      «      v}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)ÚstrÚ__mro__Ú	__bases__r   r   r   r   Ú__dict__)rW   Úhas_custom_generateÚhas_custom_prepare_inputsÚ!model_class_with_generation_mixins       r&   rN   rN   Ë  s¦   € ð (¬s°;×3FÑ3FÓ/GÑGØÐð œC × 5Ñ 5Ó6Ñ6ØÐð ,´3´w¸{ÈJÓ7WÓ3XÐXÐØ 1¼¼WÀ[ÐRqÓ=rÓ9sÐ sÐÙÑ7Ü,0Ø× Ñ  ;´Ð"@ÐBZÀ[×EYÑEYÐBZó-
Ð)ð 1Ð0ØÐr1   c                   óZ   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zdd„Zy)Ú_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
    c                 ó¼   — || _         |j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        || _        | | j                  _        i | _        i | _        y c c}}w r=   )Ú_config_mappingÚitemsÚ_reverse_config_mappingrH   Ú_extra_contentÚ_modules)r-   Úconfig_mappingr!   ÚkÚvs        r&   r0   z_LazyAutoMapping.__init__ð  sY   € Ø-ˆÔØ9G×9MÑ9MÓ9O×'P±°°A¨¨1©Ó'PˆÔ$Ø+ˆÔØ-1ˆ×ÑÔ*Ø ˆÔØˆ�ùó	 (Qs   ›Ac                 óØ   — t        | j                  j                  «       «      j                  | j                  j                  «       «      }t        |«      t        | j                  «      z   S r=   )Úsetrà   rI   ÚintersectionrH   r©   rã   )r-   Úcommon_keyss     r&   Ú__len__z_LazyAutoMapping.__len__ø  sP   € Ü˜$×.Ñ.×3Ñ3Ó5Ó6×CÑCÀD×DWÑDW×D\ÑD\ÓD^Ó_ˆÜ�;Ó¤# d×&9Ñ&9Ó":Ñ:Ð:r1   c                 óÖ  — || j                   v r| j                   |   S | j                  |j                     }|| j                  v r!| j                  |   }| j	                  ||«      S | j
                  j                  «       D ��cg c]  \  }}||j                  k(  sŒ|‘Œ }}}|D ]3  }|| j                  v sŒ| j                  |   }| j	                  ||«      c S  t        |«      ‚c c}}w r=   )rã   râ   r   rH   Ú_load_attr_from_modulerà   rá   ÚKeyError)r-   ÚkeyÚ
model_typeÚ
model_nameræ   rç   Úmodel_typesÚmtypes           r&   Ú__getitem__z_LazyAutoMapping.__getitem__ü  sí   € Ø�$×%Ñ%Ñ%Ø×&Ñ& sÑ+Ð+Ø×1Ñ1°#·,±,Ñ?ˆ
Ø˜×,Ñ,Ñ,Ø×,Ñ,¨ZÑ8ˆJØ×.Ñ.¨z¸:ÓFÐFð &*×%9Ñ%9×%?Ñ%?Ó%A×W™T˜Q ÀQÈ#Ï,É,ÓEV’qÐWˆÑWØ ò 	FˆEØ˜×+Ñ+Ò+Ø!×0Ñ0°Ñ7�
Ø×2Ñ2°5¸*ÓEÒEð	Fô �s‹mÐùó Xs   ÂC%ÂC%c                 ó²   — t        |«      }|| j                  vr&t        j                  d|› �d«      | j                  |<   t	        | j                  |   |«      S )NrE   ztransformers.models)r   rä   rÏ   rÐ   rÊ   )r-   rñ   rÑ   Úmodule_names       r&   rî   z'_LazyAutoMapping._load_attr_from_module  sQ   € Ü/°
Ó;ˆØ˜dŸm™mÑ+Ü)2×)@Ñ)@À1À[ÀMÐARÐTiÓ)jˆD�M‰M˜+Ñ&Ü'¨¯©°kÑ(BÀDÓIÐIr1   c                 ó
  — | j                   j                  «       D ��cg c]3  \  }}|| j                  j                  «       v r| j	                  ||«      ‘Œ5 }}}|t        | j                  j                  «       «      z   S c c}}w r=   )rà   rá   rH   rI   rî   r   rã   )r-   rð   rˆ   Úmapping_keyss       r&   rI   z_LazyAutoMapping.keys  s~   € ð "×1Ñ1×7Ñ7Ó9÷
á��TØ�d×)Ñ)×.Ñ.Ó0Ñ0ð ×'Ñ'¨¨TÕ2ð
ˆñ 
ð
 œd 4×#6Ñ#6×#;Ñ#;Ó#=Ó>Ñ>Ð>ùó
ó   ž8A?c                 óH   — 	 | j                  |«      S # t        $ r |cY S w xY wr=   )rõ   rï   )r-   rð   Údefaults      r&   r€   z_LazyAutoMapping.get  s,   € ð	Ø×#Ñ# CÓ(Ð(øÜò 	ØŠNð	ús   ‚ “! !c                 ó4   — t        | j                  «       «      S r=   )ÚboolrI   ©r-   s    r&   Ú__bool__z_LazyAutoMapping.__bool__   ó   € Ü�D—I‘I“KÓ Ð r1   c                 ó
  — | j                   j                  «       D ��cg c]3  \  }}|| j                  j                  «       v r| j	                  ||«      ‘Œ5 }}}|t        | j                  j                  «       «      z   S c c}}w r=   )rH   rá   rà   rI   rî   r   rã   rÄ   )r-   rð   rˆ   Úmapping_valuess       r&   rÄ   z_LazyAutoMapping.values#  s~   € ð "×0Ñ0×6Ñ6Ó8÷
á��TØ�d×*Ñ*×/Ñ/Ó1Ñ1ð ×'Ñ'¨¨TÕ2ð
ˆñ 
ð
 ¤ T×%8Ñ%8×%?Ñ%?Ó%AÓ BÑBÐBùó
rú   c           	      óV  — | j                   j                  «       D �cg c]\  }|| j                  j                  «       v r>| j                  || j                  |   «      | j                  || j                   |   «      f‘Œ^ }}|t	        | j
                  j                  «       «      z   S c c}w r=   )rH   rI   rà   rî   r   rã   rá   )r-   rð   Úmapping_itemss      r&   rá   z_LazyAutoMapping.items+  s§   € ð ×*Ñ*×/Ñ/Ó1ö
ð
 Ø�d×*Ñ*×/Ñ/Ó1Ñ1ð	 ×+Ñ+¨C°×1EÑ1EÀcÑ1JÓKØ×+Ñ+¨C°×1DÑ1DÀSÑ1IÓJòð
ˆð 
ð œt D×$7Ñ$7×$=Ñ$=Ó$?Ó@Ñ@Ð@ùò
s   �A!B&c                 ó4   — t        | j                  «       «      S r=   )ÚiterrI   rÿ   s    r&   Ú__iter__z_LazyAutoMapping.__iter__6  r  r1   c                 ó¸   — || j                   v ryt        |d«      r|j                  | j                  vry| j                  |j                     }|| j                  v S )NTr   F)rã   rG   r   râ   rH   )r-   Úitemrñ   s      r&   Ú__contains__z_LazyAutoMapping.__contains__9  sV   € Ø�4×&Ñ&Ñ&ØÜ�t˜ZÔ(¨D¯M©MÀ×A]ÑA]Ñ,]ØØ×1Ñ1°$·-±-Ñ@ˆ
Ø˜T×0Ñ0Ð0Ð0r1   c                 óö   — t        |d«      r^|j                  | j                  v rF| j                  |j                     }|| j                  j	                  «       v r|st        d|› d�«      ‚|| j                  |<   y)z7
        Register a new model in this mapping.
        r   ú'z*' is already used by a Transformers model.N)rG   r   râ   rH   rI   rP   rã   )r-   rð   Úvaluer6   rñ   s        r&   rM   z_LazyAutoMapping.registerA  sq   € ô �3˜
Ô#¨¯©¸×8TÑ8TÑ(TØ×5Ñ5°c·l±lÑCˆJØ˜T×0Ñ0×5Ñ5Ó7Ñ7ÁÜ  1 S EÐ)SÐ!TÓUÐUà#(ˆ×Ñ˜CÒ r1   Nr‘   )r   r’   r“   r·   r0   rì   rõ   rî   rI   r€   r   rÄ   rá   r  r  rM   r\   r1   r&   rÞ   rÞ   ç  sF   „ ñòò;òò Jò?òò!òCò	Aò!ò1ô	)r1   rÞ   )Ú )zgoogle-bert/bert-base-casedr  )-r·   r~   rÏ   r|   rx   Úcollectionsr   Úconfiguration_utilsr   Údynamic_module_utilsr   r   Úutilsr   r	   r
   r   r   r   r   r   r   Úconfiguration_autor   r   r   Ú
generationr   Ú
get_loggerr   Úloggerr¶   r¸   r¼   rº   r»   r'   r)   r–   r­   rÂ   rÇ   rÊ   rN   rÞ   r\   r1   r&   ú<module>r     sÐ   ðñ 4ã Û Û Û Ý #å 3ß \÷
÷ 
õ 
÷ iÑ hñ ÔÝ-ð 
ˆ×	Ñ	˜HÓ	%€ð€ðÐ ð4j#Ð ðXa Ð ðFa"Ð òH÷(}Rñ }Rô@$]Ð0ô $]óNó òFòMò(ô8c)�{õ c)r1   