Ë
    ÛÓ^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jD                  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Z6y)"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 �ci c]  }|j                  |“Œ }}t        | dg «      }|D ]  }||v sŒ||   c S  |d   S c c}w )NÚarchitecturesr   )ÚtypeÚ
isinstanceÚlistÚtupleÚ__name__Úgetattr)ÚconfigÚmodel_mappingÚsupported_modelsÚmodelÚname_to_modelr   Úarchs          úp/var/www/ramen.bs-engineer-server.com/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Øò 'ˆØ�=Ò Ø  Ñ&Ò&ð'ð ˜AÑÐùò Js   «A%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y)Ú_BaseAutoModelClassNÚreturnc                 ó¢   — 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__Æ   sR   € ÜØ�~‰~×&Ñ&Ð'ð (ØŸ.™.×1Ñ1Ð2ð 3Ø—‘×'Ñ'Ð(Ð(FðHó
ð 	
ó    c                 ól  — |j                  dd «      }t        |d«      xr | j                  |j                  v }t	        |«      | j
                  v }|xr0 t        || j
                  «      j                  j                  d«       }|rN|j                  | j                     }d|v r|j                  d«      d   }nd }t        ||j                  |||¬«      }|r–|r”|s’dv r|j                  d«      \  }	}n|j                  }	t        ||	fi |¤Ž}
| j                  |j                  |
d¬«       |
j!                  | ¬	«       |j                  d
d «      }t#        |
«      }
 |
j$                  |fi |¤ŽS |rt        || j
                  «      }
|j&                  j)                  dd «      }|�8t+        |
dd «      |k(  r(|}|j-                  «       }t+        |dd «      }|�||_         |
j$                  |fi |¤ŽS t1        d|j                  › d| j                  › ddj3                  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   ó4   K  — | ]  }|j                   –— Œ y ­w©N©r!   ©Ú.0Úcs     r)   ú	<genexpr>z2_BaseAutoModelClass.from_config.<locals>.<genexpr>ü   ó   è ø€ Ò4\ÀA°Q·ZµZÑ4\ùó   ‚ú.)ÚpopÚhasattrr!   r8   r   Ú_model_mappingr*   Ú
__module__Ú
startswithÚsplitr
   Ú_name_or_pathÚname_or_pathr	   Úregisterr0   Úregister_for_auto_classÚ$add_generation_mixin_to_remote_modelÚ_from_configÚsub_configsÚgetr"   Úget_text_configrD   Ú
ValueErrorÚjoin)Úclsr#   r3   r7   Úhas_remote_codeÚhas_local_codeÚexplicit_local_codeÚ	class_refr<   Úrepo_idÚmodel_classÚ_Útext_config_classÚparent_configÚparent_quants                  r)   Úfrom_configz_BaseAutoModelClass.from_configÍ   sN  € à"ŸJ™JÐ':¸DÓAÐÜ! &¨*Ó5ÒY¸#¿,¹,È&Ï/É/Ð:YˆÜ˜f›¨×);Ñ);Ð;ˆØ,ò 1Ô5EØ�C×&Ñ&ó6
ç
‰*—Z‘Z Ó0ð21Ðñ ØŸ™¨¯©Ñ5ˆIØ�yÑ Ø )§¡°Ó 5°aÑ 8‘à $�Ü 9Ø! 6×#7Ñ#7¸ÈÐhuô!Ðñ Ñ0Ñ9LØ�yÑ Ø%.§_¡_°TÓ%:Ñ"�™à ×-Ñ-�Ü7¸	À7ÑUÈfÑUˆKØ�L‰L˜×)Ñ)¨;ÀˆLÔFØ×/Ñ/¸3Ð/Ô?Ø—
‘
˜?¨DÓ1ˆAÜ>¸{ÓKˆKØ+�;×+Ñ+¨FÑ=°fÑ=Ð=ÙÜ*¨6°3×3EÑ3EÓFˆKØ &× 2Ñ 2× 6Ñ 6°}ÀdÓ KÐà Ð,´¸ÀnÐVZÓ1[Ð_pÒ1pð !'�Ø×/Ñ/Ó1�ô  ' }Ð6KÈTÓR�ØÐ+Ø1=�FÔ.Ø+�;×+Ñ+¨FÑ=°fÑ=Ð=äØ/°×0@Ñ0@Ð/AÐA^Ð_b×_kÑ_kÐ^lð m+Ø+/¯9©9Ñ4\È×I[ÑI[Ô4\Ó+\Ð*]Ð]^ð`ó
ð 	
r5   r#   c                 ó   — |S )z`Additional autoclass-specific config post-loading manipulation. May be overridden in subclasses.© )rd   r#   s     r)   Ú_prepare_config_for_auto_classz2_BaseAutoModelClass._prepare_config_for_auto_classÿ   s	   € ð ˆr5   Úpretrained_model_name_or_pathc                 ó–	  — |j                  dd «      }|j                  d«      }d|d<   g d¢}|D �ci c]  }||v sŒ||j                  |«      “Œ }}|j                  dd «      }	|j                  dd «      }
|j                  dd «      }|j                  d	d «      }|�||d	<   |
€?t        |t        «      s"t	        |t
        fd
d
d
dœ|¤Ž}t        ||
«      }
nt        |dd «      }
t        «       rÁ|€i }|j                  «       }|�||d	<   t        |fd|
i|¤Ž}|�–t        |dd¬«      5 }t        j                  |«      }||d<   t        j                  j!                  |«      rAt        j                  j!                  t        j                  j#                  |t
        «      «      s|d   }d d d «       t        |t        «      sît        j$                  |«      }|j                  d«      dk(  r|j                  d«      }|j                  d«      dk(  r|j                  d«      }|j                  d«      �|j                  d«      }t'        j(                  |fd|	|
dœ|¤|¤Ž\  }}|j                  dd «      �|d   |d<   |j                  dd «      �|d   |d<   |j                  dd «      �|d   |d<   t+        |d«      xr | j,                  |j.                  v }t1        |«      | j2                  v }|xr0 t5        || j2                  «      j6                  j9                  d«       }d }|r1|j.                  | j,                     }d|v r|j;                  d«      d   }t=        |||||¬«      }||d<   ||d<   |r||rz|sxt?        |fd|	i|¤|¤Ž}|j                  dd «      }| jA                  |jB                  |d¬«       |jE                  | ¬«       tG        |«      } |j(                  |g|¢­d|i|¤|¤ŽS |r†t5        || j2                  «      }|jH                  j                  dd «      }|�8t        |dd «      |k(  r(|}|jK                  «       }t        |dd «      }|�||_&         |j(                  |g|¢­d|i|¤|¤ŽS tO        d|jB                  › d | j,                  › d!d"j#                  d#„ | j2                  D «       «      › d$�«      ‚c c}w # 1 sw Y   �ŒxY w)%Nr#   r7   TÚ
_from_auto)Ú	cache_dirÚforce_downloadÚlocal_files_onlyÚproxiesÚrevisionÚ	subfolderÚtokenrA   Ú_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ÚdtyperD   )Úreturn_unused_kwargsrA   r}   r8   r9   r:   r   r;   r=   r?   rB   rC   rE   rF   rG   rH   c              3   ó4   K  — | ]  }|j                   –— Œ y ­wrJ   rK   rL   s     r)   rO   z6_BaseAutoModelClass.from_pretrained.<locals>.<genexpr>—  rP   rQ   rR   )(rS   r`   r   r   r   r   r   r"   r   Úcopyr   ÚopenÚjsonÚloadÚosÚpathÚexistsrc   Údeepcopyr   Úfrom_pretrainedrT   r!   r8   r   rU   r*   rV   rW   rX   r
   r	   r[   r0   r\   r]   r_   ra   rD   rb   )rd   rs   Ú
model_argsr3   r#   r7   Úhub_kwargs_namesÚnameÚ
hub_kwargsrA   Úcommit_hashr~   r|   Úresolved_config_fileÚmaybe_adapter_pathÚfÚadapter_configÚkwargs_origrk   re   rf   rg   r<   rh   rj   rl   rm   rn   s                               r)   r“   z#_BaseAutoModelClass.from_pretrained  s�  € à—‘˜H dÓ+ˆØ"ŸJ™JÐ':Ó;ÐØ#ˆˆ|Ñò
Ðð :JÖ\°ÈTÐU[Ê^�d˜FŸJ™J tÓ,Ñ,Ð\ˆ
Ð\ØŸ
™
 ?°DÓ9ˆØ—j‘j °Ó6ˆØŸ™Ð$4°dÓ;ˆà—‘˜w¨Ó-ˆàÐØ"'ˆJ�wÑàÐÜ˜fÔ&6Ô7ä'2Ø1Üð(ð 6;Ø:?Ø<Añ(ð !ñ(Ð$ô 2Ð2FÈÓT‘ä% f¨n¸dÓC�äÔØÐ%Ø!#�Ø+×0Ñ0Ó2ˆNØÐ Ø*/�˜wÑ'ä!9Ø-ñ"Ø<Gð"ØKYñ"Ðð "Ð-ÜÐ,¨c¸GÔDð bÈÜ%)§Y¡Y¨q£\�Nà<Y�NÐ#8Ñ9ô
 Ÿ7™7Ÿ>™>Ð*GÔHÔPR×PWÑPW×P^ÑP^ÜŸ™Ÿ™Ð%BÄKÓPôQð 9GÐG`Ñ8aÐ5÷bô ˜&Ô"2Ô3ÜŸ-™-¨Ó/ˆKð �z‰z˜-Ó(¨FÒ2Ø—J‘J˜}Ó-�Ø�z‰z˜'Ó" fÒ,Ø—J‘J˜wÓ'�à�z‰zÐ/Ó0Ð<Ø—J‘JÐ4Ó5�ä'×7Ñ7Ø-ðà%)Ø+Ø(ñ	ð
 ðð ñ‰NˆF�Fð �‰˜}¨dÓ3Ð?Ø(3°MÑ(B��}Ñ%Ø�‰˜w¨Ó-Ð9Ø"-¨gÑ"6��w‘Ø�‰Ð4°dÓ;ÐGØ0;Ð<QÑ0R�Ð,Ñ-ä! &¨*Ó5ÒY¸#¿,¹,È&Ï/É/Ð:YˆÜ˜f›¨×);Ñ);Ð;ˆØ,ò 1Ô5EØ�C×&Ñ&ó6
ç
‰*—Z‘Z Ó0ð21Ðð ˆÙØŸ™¨¯©Ñ5ˆIØ�yÑ Ø )§¡°Ó 5°aÑ 8�Ü5ØØ)ØØØ'ô
Ðð '8ˆÐ"Ñ#ð $2ˆÐÑ áÑ0Ñ9LÜ7ØÐ8ñØHUðØYcðØgmñˆKð —‘˜°Ó5ˆAØ�L‰L˜×)Ñ)¨;ÀˆLÔFØ×/Ñ/¸3Ð/Ô?Ü>¸{ÓKˆKØ.�;×.Ñ.Ø-ðØ0:òØCIðØMWðØ[añð ñ Ü*¨6°3×3EÑ3EÓFˆKØ &× 2Ñ 2× 6Ñ 6°}ÀdÓ KÐà Ð,´¸ÀnÐVZÓ1[Ð_pÒ1pð !'�Ø×/Ñ/Ó1�ô  ' }Ð6KÈTÓR�ØÐ+Ø1=�FÔ.Ø.�;×.Ñ.Ø-ðØ0:òØCIðØMWðØ[añð ô Ø/°×0@Ñ0@Ð/AÐA^Ð_b×_kÑ_kÐ^lð m+Ø+/¯9©9Ñ4\È×I[ÑI[Ô4\Ó+\Ð*]Ð]^ð`ó
ð 	
ùòG ]÷Jbñ bús   ±	R9»R9Ä$B R>Ò>S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.
        rC   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!r=   N)rT   rC   r!   rb   rU   r[   )rd   rC   rj   r>   s       r)   r[   z_BaseAutoModelClass.registerš  sw   € ô �; Ô/°K×4LÑ4L×4UÑ4UÐYe×YnÑYnÒ4nÜð6Ø6A×6NÑ6NÐ5OÐO_Ð`lÐ_mð n.ð.óð ð
 	×Ñ×#Ñ# L°+ÈÐ#ÕQr5   ©r-   N©F)r!   rV   Ú__qualname__rU   r4   Úclassmethodro   r   rr   Ústrr�   ÚPathLiker“   r[   rq   r5   r)   r,   r,   Â   sˆ   „ à€Nó
ð ñ/
ó ð/
ðb ðÐ4Dð ÐIYò ó ðð ðS
¸CÀ"Ç+Á+ÈcÑBRÑ<Rò S
ó ðS
ðj óRó ñRr5   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«      �t        d«      ‚|j	                  dd	«      rt        d
«      ‚|j                  d|j                  «      }|j                  d|j                  «      }|j                  d|j                  «      } |||||¬«      }|j                  dd «       t        ‰	| �(  |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ª   rS   r`   rb   r­   r®   r¯   Úsuperro   )
rd   rs   r”   r3   rª   r#   r­   r®   r¯   r0   s
            €r)   Ú#_load_timm_backbone_from_pretrainedz:_BaseAutoBackboneClass._load_timm_backbone_from_pretrained²  sâ   ø€ ä˜# ¨&Ð1Ô2Ý>à—‘˜HÑ&8Ó&:Ó;ˆà�:‰:�nÓ%Ð1ÜÐOÓPÐPà�:‰:Ð+¨UÔ3ÜÐ_Ó`Ð`à—z‘z .°&×2EÑ2EÓFˆØŸ
™
 ?°F×4HÑ4HÓIˆØ—j‘j °×0BÑ0BÓCˆÙ#Ø2Ø%Ø'Ø#ô	
ˆð 	�
‰
Ð,¨dÔ3Ü‰wÑ" 6ÑE°dÐE¸fÑEÐEr5   c                 ó¬   •— |j                  dd «       t        «       j                  |«      s | j                  |g|¢­i |¤ŽS t	        ‰| �  |g|¢­i |¤ŽS )NÚuse_timm_backbone)rS   r   Úrepo_existsrµ   r´   r“   )rd   rs   r”   r3   r0   s       €r)   r“   z&_BaseAutoBackboneClass.from_pretrainedÌ  s_   ø€ à�
‰
Ð&¨Ô-Ü‹x×#Ñ#Ð$AÔBØ:�3×:Ñ:Ð;XÐpÐ[eÒpÐioÑpÐpä‰wÑ&Ð'DÐ\ÀzÒ\ÐU[Ñ\Ð\r5   )r!   rV   r¡   rU   r¢   rµ   r“   Ú__classcell__)r0   s   @r)   r¦   r¦   ®  s2   ø„ à€NàóFó ðFð2 ó]ó ô]r5   r¦   Úhead_docc                 ó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)Ú	docstringrº   s     r)   Úinsert_head_docr¿   Õ  sK   € Ü
ˆ8ƒ}�qÒØ× Ñ Ø6Ø>¸x¸jÈÐPó
ð 	
ð ×ÑØ2Ð4cóð r5   Úcheckpoint_for_examplec                 óþ  — | j                   }| j                  }t        t        |¬«      }|j	                  d|«      | _        t        t        j                  «      }t        t        |¬«      }|j	                  d|«      }|j	                  d|«      }||_         t        |j                   d¬«      |«      }t        |«      | _        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_typesú/éÿÿÿÿú-r   Úshortcut_placeholder)rU   r!   r¿   ÚCLASS_DOCSTRINGr½   Ú__doc__r   r,   ro   ÚFROM_CONFIG_DOCSTRINGr   r¢   ÚFROM_PRETRAINED_TORCH_DOCSTRINGr“   rX   )rd   rÀ   rº   r$   r–   Úclass_docstringro   Úfrom_config_docstringÚfrom_pretrained_docstringr“   Úshortcuts              r)   Úauto_class_updaterÑ   à  so  € à×&Ñ&€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ä ?ÐÜÔ 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ÔØ€Jr5   c                 ó    — g }| j                  «       D ]8  }t        |t        t        f«      r|t        |«      z  }Œ(|j	                  |«       Œ: |S rJ   )Úvaluesr   r   r    Úappend)r$   Úresultr&   s      r)   Ú
get_valuesrÖ   þ  sN   € Ø€FØ×%Ñ%Ó'ò !ˆÜ�eœd¤E˜]Ô+Ø”d˜5“kÑ!‰Fà�M‰M˜%Õ ð	!ð €Mr5   c           
      óÀ  ‡ — |€y t        |t        «      rt        ˆ fd„|D «       «      S t        |t        «      r.|j                  «       D ��ci c]  \  }}|t	        ‰ |«      “Œ c}}S t        ‰ |«      rt        ‰ |«      S t        j                  d«      }‰ |k7  r	 t	        ||«      S t        d|› d|› d�«      ‚c c}}w # t        $ r t        d|› d‰ › d|› d�«      ‚w xY w)Nc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­wrJ   )Úgetattribute_from_module)rM   ÚaÚmodules     €r)   rO   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    ÚdictÚitemsrÙ   rT   r"   Ú	importlibÚimport_modulerb   )rÛ   ÚattrÚkÚvÚtransformers_modules   `    r)   rÙ   rÙ   	  sù   ø€ Ø€|ØÜ�$œÔÜÓGÀ$ÔGÓGÐGÜ�$œÔØCGÇ:Á:Ã<×P¹4¸1¸a�Ô+¨F°AÓ6Ñ6ÓPÐPÜˆv�tÔÜ�v˜tÓ$Ð$ô $×1Ñ1°.ÓAÐàÐ$Ò$ð	iÜ+Ð,?ÀÓFÐFô ˜?¨4¨&°Ð5HÐ4IÈÐKÓLÐLùó Qøô ò 	iÜ˜¨t¨f°LÀÀÈÐQdÐPeÐefÐgÓhÐhð	iús   ÁB8ÂB> Â>Cc                 ó\  — dt        | j                  «      vr| S dt        | j                  «      v r| S t        | d«      xr dt        t	        | d«      «      v}t        | d«      xr 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__rT   r"   r   r!   r   Ú__dict__)rj   Úhas_custom_generate_in_classÚhas_custom_prepare_inputsÚ!model_class_with_generation_mixins       r)   r]   r]     sÙ   € ð (¬s°;×3FÑ3FÓ/GÑGØÐð œC × 5Ñ 5Ó6Ñ6ØÐô $+¨;¸
Ó#Cò $ÐHYÔadÜ�˜ZÓ(óbð IÐ ô !(¨Ð5TÓ Uò !ÐZkÔsvÜ�Ð<Ó=ótð [Ðñ $Ñ'@Ü,0Ø× Ñ  ;´Ð"@ÐBZÀ[×EYÑEYÐBZó-
Ð)ð 1Ð0ØÐr5   c                   ó  — 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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
    r-   Nc                 ó¼   — || _         |j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        || _        | | j                  _        i | _        i | _        y c c}}w rJ   )Ú_config_mappingrß   Ú_reverse_config_mappingrU   Ú_extra_contentÚ_modules)r1   Úconfig_mappingr$   rã   rä   s        r)   r4   z_LazyAutoMapping.__init__H  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 rJ   )Úsetrò   ÚkeysÚintersectionrU   r¼   rô   )r1   Úcommon_keyss     r)   Ú__len__z_LazyAutoMapping.__len__P  sP   € Ü˜$×.Ñ.×3Ñ3Ó5Ó6×CÑCÀD×DWÑDW×D\ÑD\ÓD^Ó_ˆÜ�;Ó¤# d×&9Ñ&9Ó":Ñ:Ð:r5   Úkeyc                 óÖ  — || 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 rJ   )rô   ró   r!   rU   Ú_load_attr_from_modulerò   rß   ÚKeyError)r1   rý   Ú
model_typeÚ
model_namerã   rä   Úmodel_typesÚmtypes           r)   Ú__getitem__z_LazyAutoMapping.__getitem__T  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 )NrR   ztransformers.models)r   rõ   rà   rá   rÙ   )r1   r  râ   Úmodule_names       r)   rÿ   z'_LazyAutoMapping._load_attr_from_moduled  sQ   € Ü/°
Ó;ˆØ˜dŸm™mÑ+Ü)2×)@Ñ)@À1À[ÀMÐARÐTiÓ)jˆD�M‰M˜+Ñ&Ü'¨¯©°kÑ(BÀDÓIÐIr5   c                 óî   — | j                   j                  «       D ��cg c]%  \  }}|| j                  v r| j                  ||«      ‘Œ' }}}|t	        | j
                  j                  «       «      z   S c c}}w rJ   )rò   rß   rU   rÿ   r   rô   rù   )r1   rý   r–   Úmapping_keyss       r)   rù   z_LazyAutoMapping.keysj  su   € ð "×1Ñ1×7Ñ7Ó9÷
á��TØ�d×)Ñ)Ñ)ð ×'Ñ'¨¨TÕ2ð
ˆñ 
ð
 œd 4×#6Ñ#6×#;Ñ#;Ó#=Ó>Ñ>Ð>ùó
ó   ž*A1Údefaultc                 óH   — 	 | j                  |«      S # t        $ r |cY S w xY wrJ   )r  r   )r1   rý   r  s      r)   r`   z_LazyAutoMapping.getr  s,   € ð	Ø×#Ñ# CÓ(Ð(øÜò 	ØŠNð	ús   ‚ “! !c                 ó4   — t        | j                  «       «      S rJ   )Úboolrù   ©r1   s    r)   Ú__bool__z_LazyAutoMapping.__bool__x  ó   € Ü�D—I‘I“KÓ Ð r5   c                 óî   — | j                   j                  «       D ��cg c]%  \  }}|| j                  v r| j                  ||«      ‘Œ' }}}|t	        | j
                  j                  «       «      z   S c c}}w rJ   )rU   rß   rò   rÿ   r   rô   rÓ   )r1   rý   r–   Úmapping_valuess       r)   rÓ   z_LazyAutoMapping.values{  su   € ð "×0Ñ0×6Ñ6Ó8÷
á��TØ�d×*Ñ*Ñ*ð ×'Ñ'¨¨TÕ2ð
ˆñ 
ð
 ¤ T×%8Ñ%8×%?Ñ%?Ó%AÓ BÑBÐBùó
r
  c           	      ó  — | j                   D �cg c]N  }|| j                  v r>| j                  || j                  |   «      | j                  || j                   |   «      f‘ŒP }}|t        | j                  j                  «       «      z   S c c}w rJ   )rU   rò   rÿ   r   rô   rß   )r1   rý   Úmapping_itemss      r)   rß   z_LazyAutoMapping.itemsƒ  s•   € ð ×*Ñ*ö
ð
 Ø�d×*Ñ*Ñ*ð	 ×+Ñ+¨C°×1EÑ1EÀcÑ1JÓKØ×+Ñ+¨C°×1DÑ1DÀSÑ1IÓJòð
ˆð 
ð œt D×$7Ñ$7×$=Ñ$=Ó$?Ó@Ñ@Ð@ùò
s   �AB
c                 ó4   — t        | j                  «       «      S rJ   )Úiterrù   r  s    r)   Ú__iter__z_LazyAutoMapping.__iter__Ž  r  r5   Úitemc                 ó¸   — || j                   v ryt        |d«      r|j                  | j                  vry| j                  |j                     }|| j                  v S )NTr!   F)rô   rT   r!   ró   rU   )r1   r  r  s      r)   Ú__contains__z_LazyAutoMapping.__contains__‘  sV   € Ø�4×&Ñ&Ñ&ØÜ�t˜ZÔ(¨D¯M©MÀ×A]ÑA]Ñ,]ØØ×1Ñ1°$·-±-Ñ@ˆ
Ø˜T×0Ñ0Ð0Ð0r5   Úvaluec                 ó  — t        |d«      rP|j                  | j                  v r8| j                  |j                     }|| j                  v r|st	        d|› d�«      ‚t        |dd«      j                  d«      ry|| j                  |<   y)z7
        Register a new model in this mapping.
        r!   ú'z*' is already used by a Transformers model.rV   Ú r9   N)rT   r!   ró   rU   rb   r"   rW   rô   )r1   rý   r  r>   r  s        r)   r[   z_LazyAutoMapping.register™  s†   € ô �3˜
Ô#¨¯©¸×8TÑ8TÑ(TØ×5Ñ5°c·l±lÑCˆJØ˜T×0Ñ0Ñ0¹Ü  1 S EÐ)SÐ!TÓUÐUô �3˜ bÓ)×4Ñ4°_ÔEØð $)ˆ×Ñ˜CÒ r5   rŸ   r    )r!   rV   r¡   rÊ   r4   Úintrü   r   r   Ú_LazyAutoMappingValuer  rÿ   r   rù   r   r`   r  r  rÓ   r    rß   r   r  r  r£   r[   rq   r5   r)   rð   rð   ?  s  „ ñóð;˜ó ;ð˜tÐ$4Ñ5ð Ð:Oó ò Jð?�d˜4Ð 0Ñ1Ñ2ó ?ð�tÐ,Ñ-ð ¸ð Ð?TÐWYÑ?Yó ð!˜$ó !ðC˜Ð2Ñ3ó Cð	A�t˜E $Ð'7Ñ"8Ð:OÐ"OÑPÑQó 	Að!˜( 4Ð(8Ñ#9Ñ:ó !ð1 ð 1¨$ó 1ñ)˜DÐ!1Ñ2°SÑ8ð )ÐAVð )Ðkoô )r5   rð   rÖ   )r  )zgoogle-bert/bert-base-casedr  )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   r!  rÉ   rË   rÌ   r*   r,   r¦   r£   r¿   rÑ   rÖ   rÙ   r]   rð   Ú__all__rq   r5   r)   ú<module>r-     s  ðñ 4ã Û Û Û 	Ý #Ý $ß å 3ß \÷÷ ÷ ÷ iÑ hñ ÔÝ-ð 
ˆ×	Ñ	˜HÓ	%€áˆTƒ]€à˜d 3™i¨$Ñ.°°S±	¸DÑ0@Ð@ÑAÐ ð€ðÐ ð4Z#Ð òz÷ iRñ iRôX$]Ð0ô $]ñN¨ó ñ°3ð Ðbeó ò<òMò,ô@m)�{ 4Ð(8Ñ#9Ð;PÐ#PÑQô m)ð` ˆ.�r5   