
    bCil                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
JrJrJr  SSKJr  SSKJrJr  SS	KJrJrJrJrJrJrJrJrJr  S
SKJrJrJ r   \" 5       (       a  SSK!J"r"  \RF                  " \$5      r%\" S5      r&\'\\(\   S4   \\(\   S4   4   r)Sr*Sr+Sr,Sr-Sr.S r/ " S S5      r0 " S S\05      r1S!S\24S jjr3S"S\2S\24S jjr4S r5S r6S r7 " S S\\(\   \)4   5      r8S /r9g)#z-Factory function to build auto-model classes.    N)OrderedDict)Iterator)AnyTypeVarUnion   )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)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).
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                 2   U[        U 5         n[        U[        [        45      (       d  U$ U Vs0 s H  o3R                  U_M     nn[        U S/ 5      nU H4  nXd;   a  XF   s  $ SU 3U;   a
  USU 3   s  $ SU 3U;   d  M,  USU 3   s  $    US   $ s  snf )NarchitecturesTFFlaxr   )type
isinstancelisttuple__name__getattr)configmodel_mappingsupported_modelsmodelname_to_modelr   archs          _/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/auto/auto_factory.py_get_model_classr,     s    $T&\2&u668HI8Hu^^U*8HMIFOR8M  &&$[M) 2dV--D6]m+ 4v//  A Js   Bc                       \ rS rSrSrSS jr\S 5       r\S\S\4S j5       r	\S\
\\R                  \   4   4S	 j5       r\SSS
 jj5       rSrg)_BaseAutoModelClassi  Nreturnc                     [        U R                  R                   SU R                  R                   SU R                  R                   S35      e)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___BaseAutoModelClass.__init__  sR    ~~&&' (..112 3''((FH
 	
    c                    UR                  SS 5      n[        US5      =(       a    U R                  UR                  ;   n[	        U5      U R
                  ;   nU(       aK  UR                  U R                     nSU;   a  UR                  S5      S   nOS n[        X1R                  XTUS9nU(       a  U(       a  SW;   a  UR                  S5      u  pOUR                  n[        Xh40 UD6n	U(       d*  U R                  UR                  U	SS9  U	R                  U S9  UR                  S	S 5      n
[        U	5      n	U	R                  " U40 UD6$ [	        U5      U R
                  ;   a(  [!        XR
                  5      n	U	R                  " U40 UD6$ [#        S
UR                   SU R                   SSR%                  S U R
                   5       5       S35      e)Ntrust_remote_codeauto_map--r   upstream_repoTexist_ok
auto_classcode_revision!Unrecognized configuration class  for this kind of AutoModel: .
Model type should be one of , c              3   8   #    U  H  oR                   v   M     g 7fNr#   .0cs     r+   	<genexpr>2_BaseAutoModelClass.from_config.<locals>.<genexpr>       4\I[AZZI[   .)pophasattrr#   r;   r   _model_mappingsplitr   _name_or_pathname_or_pathr
   registerr2   register_for_auto_class$add_generation_mixin_to_remote_model_from_configr,   
ValueErrorjoin)clsr%   r5   r:   has_remote_codehas_local_code	class_refr>   repo_idmodel_class_s              r+   from_config_BaseAutoModelClass.from_config  s   "JJ':DA!&*5Y#,,&//:Yf););;5Iy  ) 5a 8 $ 9!#7#7hu! 0y %.__T%:" --7	UfUK "V--{TJ33s3C

?D1A>{KK++F=f==&\S///*63E3EFK++F=f==/0@0@/AA^_b_k_k^l m++/994\I[I[4\+\*]]^`
 	
r8   r%   c                     U$ )z`Additional autoclass-specific config post-loading manipulation. May be overridden in subclasses. )r_   r%   s     r+   _prepare_config_for_auto_class2_BaseAutoModelClass._prepare_config_for_auto_class  s	     r8   pretrained_model_name_or_pathc                 "	   UR                  SS 5      nUR                  S5      nSUS'   / SQnU Vs0 s H  owU;   d  M
  XsR                  U5      _M     nnUR                  SS 5      n	UR                  SS 5      n
UR                  SS 5      nUR                  S	S 5      nUR                  S
S 5      nUb+  [        R                  " S[        5        Ub  [        S5      eUnUb  XS	'   U
cC  [        U[        5      (       d!  [        U[        4SSSS.UD6n[        X5      n
O[        USS 5      n
[        5       (       aP  Uc	  0 nUb  XS	'   [        U4SU
0UD6nUb3  [        USSS9 n[        R                   " U5      nXS'   US   nS S S 5        [        U[        5      (       d  ["        R$                  " U5      nUR                  S5      S:X  a  UR                  S5      nUR                  S5      S:X  a  UR                  S5      nUR                  S5      b  UR                  S5      n[&        R(                  " U4SU	U
S.UDUD6u  pCUR                  SS 5      S:X  a  SUS'   UR                  SS 5      S:X  a  SUS'   UR                  SS 5      b  US   US'   [+        US5      =(       a    U R,                  UR.                  ;   n[1        U5      U R2                  ;   nS nU(       a3  UR.                  U R,                     nSU;   a  UR5                  S5      S   n[7        UUUUUS9nXSS'   XS'   U(       a  U(       ay  [9        WU4SU	0UDUD6nUR                  SS 5      nU(       d*  U R;                  UR<                  USS9  UR?                  U S9  [A        U5      nUR(                  " U/UQ7SU0UDUD6$ [1        U5      U R2                  ;   ai  [C        X@R2                  5      nURD                  URF                  R                  SS 5      :X  a  URI                  5       nUR(                  " U/UQ7SU0UDUD6$ [        S UR<                   S!U R,                   S"S#RK                  S$ U R2                   5       5       S%35      es  snf ! , (       d  f       GN= f)&Nr%   r:   T
_from_auto)		cache_dirforce_downloadlocal_files_onlyproxiesresume_downloadrevision	subfolderuse_auth_tokentokenrC   _commit_hashadapter_kwargsrw   rv   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dtypequantization_config)return_unused_kwargsrC   rx   r;   r<   r   r=   r?   rA   text_configrD   rE   rF   rG   c              3   8   #    U  H  oR                   v   M     g 7frI   rJ   rK   s     r+   rN   6_BaseAutoModelClass.from_pretrained.<locals>.<genexpr>a  rP   rQ   rR   )&rS   getwarningswarnFutureWarningr]   r    r	   r   r   r   r$   r   r   openjsonloadcopydeepcopyr   from_pretrainedrT   r#   r;   r   rU   rV   r   r
   rY   r2   rZ   r[   r,   config_classsub_configsget_text_configr^   )r_   rl   
model_argsr5   r%   r:   hub_kwargs_namesname
hub_kwargsrC   commit_hashry   rw   rv   resolved_config_filemaybe_adapter_pathfadapter_configkwargs_origre   r`   ra   r>   rb   rd   s                            r+   r   #_BaseAutoModelClass.from_pretrained  s   Hd+"JJ':;#|

 :J\9IU[^,dJJt,,9I
\

?D9jj6$4d;w-#(8$?%MM E   l  #E"'wf&677'21( 6;:?<A( !($ 22FT%fndC%!#$.37+!9-"<G"KY" "-,cGD%)YYq\N<Y#894BC\4]1	 E &"233--/K zz-(F2JJ}-zz'"f,JJw'zz/0<JJ45'77-%)+(	
  NF }d3v=(.}%w-7"(w4d;G0;<Q0R,-!&*5Y#,,&//:Yf););;5Iy  ) 5a 85)'
 '8"# $2 078HUYcgmK 5A "V--{TJ33s3C>{KK..-0:CIMW[a  &\S///*63E3EFK''6+=+=+A+A-QU+VV//1..-0:CIMW[a  /0@0@/AA^_b_k_k^l m++/994\I[I[4\+\*]]^`
 	
w ]^ EDs   	Q:Q:! Q??
Rc                     [        US5      (       a@  UR                  R                  UR                  :w  a  [        SUR                   SU S35      eU R                  R                  XUS9  g)z
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   zThe 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   r   r#   r]   rU   rY   )r_   r   rd   r@   s       r+   rY   _BaseAutoModelClass.registerd  sx     ;//K4L4L4U4UYeYnYn4n66A6N6N5OO_`l_m n.. 
 	##L#Qr8   ri   r/   NF)r#   
__module____qualname____firstlineno__rU   r6   classmethodrf   r	   rj   r   strosPathLiker   rY   __static_attributes__ri   r8   r+   r.   r.     s    N
 $
 $
L 4D IY   M
E#r{{SVGWBW<X M
 M
^ R Rr8   r.   c                   L   ^  \ rS rSrSr\U 4S j5       r\U 4S j5       rSrU =r	$ )_BaseAutoBackboneClassix  Nc                   > [        U SS/5        SSKJn  UR                  SU" 5       5      nUR	                  S5      b  [        S5      eUR	                  SS	5      (       a  [        S
5      eUR                  SUR                  5      nUR                  SUR                  5      nUR                  SUR                  5      nUR                  SUR                  5      n	U" UUUUU	S9n[        T
U ],  " U40 UD6$ )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   rS   r   r]   r   r   r   r   superrf   )r_   rl   r   r5   r   r%   r   r   r   r   r2   s             r+   #_load_timm_backbone_from_pretrained:_BaseAutoBackboneClass._load_timm_backbone_from_pretrained|  s    #&12>H&8&:;::n%1OPP::+U33_``zz.&2E2EF

?F4H4HI"(**-FHfHf"gjj0B0BC#2%'$;#
 w"64V44r8   c                    > UR                  SS5      nU(       a  U R                  " U/UQ70 UD6$ [        TU ]  " U/UQ70 UD6$ )Nuse_timm_backboneF)rS   r   r   r   )r_   rl   r   r5   r   r2   s        r+   r   &_BaseAutoBackboneClass.from_pretrained  sR    "JJ':EB::;Xp[epioppw&'D\z\U[\\r8   ri   )
r#   r   r   r   rU   r   r   r   r   __classcell__)r2   s   @r+   r   r   x  s0    N5 52 ] ]r8   r   head_docc                 p    [        U5      S:  a  U R                  SSU S35      $ U R                  SS5      $ )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>xjP
 	
 24c r8   checkpoint_for_examplec                 T   U R                   nU R                  n[        [        US9nUR	                  SU5      U l        [        [        R                  5      n[        [        US9nUR	                  SU5      nUR	                  SU5      nXvl        [        UR                   SS9" U5      n[        U5      U l        UR                  S5      (       a  [        nO#UR                  S5      (       a  [        nO[        n[        [        R                   5      n	[        XS9nUR	                  SU5      nUR	                  SU5      nUR#                  S5      S	   R#                  S
5      S   n
UR	                  SU
5      nXl        [        UR                   5      " U	5      n	[        U	5      U l        U $ )N)r   BaseAutoModelClasscheckpoint_placeholderF)use_model_typesr   r   /-r   shortcut_placeholder)rU   r#   r   CLASS_DOCSTRINGr   __doc__r   r.   rf   FROM_CONFIG_DOCSTRINGr   r   
startswithFROM_PRETRAINED_TF_DOCSTRINGFROM_PRETRAINED_FLAX_DOCSTRINGFROM_PRETRAINED_TORCH_DOCSTRINGr   rV   )r_   r   r   r&   r   class_docstringrf   from_config_docstringfrom_pretrained_docstringr   shortcuts              r+   auto_class_updater     s   &&M<<D%oIO!))*>ECK /;;<K+,AHU199:NPTU199:RTjk/3M4P4PbghituK!+.COt$@!		 	 $B!$C! 3 C CDO /0I ] 9 A ABVX\ ] 9 A ABZ\r s%++C04::3?BH 9 A ABXZb c778T8TUVefO%o6CJr8   c                     / nU R                  5        H?  n[        U[        [        45      (       a  U[        U5      -  nM.  UR	                  U5        MA     U$ rI   )valuesr    r!   r"   append)r&   resultr(   s      r+   
get_valuesr     sL    F%%'edE]++d5k!FMM% 	 ( Mr8   c           
      T  ^  Uc  g [        U[        5      (       a  [        U 4S jU 5       5      $ [        T U5      (       a  [        T U5      $ [        R
                  " S5      nT U:w  a   [        X!5      $ [        SU SU S35      e! [         a    [        SU ST  SU S35      ef = f)Nc              3   <   >#    U  H  n[        TU5      v   M     g 7frI   )getattribute_from_module)rL   amodules     r+   rN   +getattribute_from_module.<locals>.<genexpr>  s     G$Q-fa88$s   transformerszCould not find z neither in z nor in !z in )r    r"   rT   r$   	importlibimport_moduler   r]   )r   attrtransformers_modules   `  r+   r   r     s    |$G$GGGvtvt$$ $11.A$$	i+,?FF ?4&5H4IKLL  	itfLQdPeefghh	is   *
B  B'c                    S[        U R                  5      ;  a  U $ S[        U R                  5      ;   a  U $ [        U S5      =(       a    S[        [	        U S5      5      ;  n[        U S5      =(       a    S[        [	        U S5      5      ;  nU(       d  U(       a+  [        U R                  U [        40 U R                  E5      nU$ U $ )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__)rd   has_custom_generate_in_classhas_custom_prepare_inputs!model_class_with_generation_mixins       r+   r[   r[     s     (s;3F3F/GG C 5 566 $+;
#C $HYadZ(b I  !(5T U !Zksv<=t [ $'@,0  ;"@BZ[EYEYBZ-
) 10r8   c                       \ rS rSrSrSS jrS\4S jrS\\	   S\
4S jrS	 rS\\\	      4S
 jrS\\	   S\S\\
\4   4S jrS\4S jrS\\
   4S jrS\\\\	   \
4      4S jrS\\\	      4S jrS\S\4S jrSS\\	   S\
SS4S jjrSrg)_LazyAutoMappingi  z
" 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                     Xl         UR                  5        VVs0 s H  u  p4XC_M	     snnU l        X l        X R                  l        0 U l        0 U l        g s  snnf rI   )_config_mappingitems_reverse_config_mappingrU   _extra_content_modules)r3   config_mappingr&   kvs        r+   r6   _LazyAutoMapping.__init__  sU    -9G9M9M9O'P9O9O'P$+-1* 	 (Qs   Ac                     [        U R                  R                  5       5      R                  U R                  R                  5       5      n[        U5      [        U R                  5      -   $ rI   )setr   keysintersectionrU   r   r   )r3   common_keyss     r+   __len___LazyAutoMapping.__len__  sP    $..3356CCDDWDWD\D\D^_;#d&9&9":::r8   keyc                    XR                   ;   a  U R                   U   $ U R                  UR                     nX R                  ;   a   U R                  U   nU R	                  X#5      $ U R
                  R                  5        VVs/ s H  u  pEXQR                  :X  d  M  UPM     nnnU H4  nXpR                  ;   d  M  U R                  U   nU R	                  Xs5      s  $    [        U5      es  snnf rI   )r   r   r#   rU   _load_attr_from_moduler   r   KeyError)r3   r
  
model_type
model_namer   r  model_typesmtypes           r+   __getitem___LazyAutoMapping.__getitem__!  s    %%%&&s++11#,,?
,,,,,Z8J..zFF &*%9%9%?%?%AW%ATQQ,,EVq%AW E+++!007
225EE ! sm Xs   C+C+c                     [        U5      nX0R                  ;  a'  [        R                  " SU 3S5      U R                  U'   [	        U R                  U   U5      $ )NrR   ztransformers.models)r   r   r   r   r   )r3   r  r   module_names       r+   r  '_LazyAutoMapping._load_attr_from_module1  sO    /
;mm+)2)@)@1[MARTi)jDMM+&'k(BDIIr8   c                     U R                   R                  5        VVs/ s H'  u  pXR                  ;   d  M  U R                  X5      PM)     nnnU[	        U R
                  R                  5       5      -   $ s  snnf rI   )r   r   rU   r  r!   r   r  )r3   r
  r   mapping_keyss       r+   r  _LazyAutoMapping.keys7  st     "11779
9	))) 3D''29 	 

 d4#6#6#;#;#=>>>

   A5A5defaultc                 J     U R                  U5      $ ! [         a    Us $ f = frI   )r  r  )r3   r
  r  s      r+   r   _LazyAutoMapping.get?  s,    	##C(( 	N	s    ""c                 4    [        U R                  5       5      $ rI   )boolr  r3   s    r+   __bool___LazyAutoMapping.__bool__E      DIIK  r8   c                     U R                   R                  5        VVs/ s H'  u  pXR                  ;   d  M  U R                  X5      PM)     nnnU[	        U R
                  R                  5       5      -   $ s  snnf rI   )rU   r   r   r  r!   r   r   )r3   r
  r   mapping_valuess       r+   r   _LazyAutoMapping.valuesH  st     "00668
8	*** 3D''28 	 

 T%8%8%?%?%A BBB
r  c           	      &   U R                    Vs/ s HP  nXR                  ;   d  M  U R                  XR                  U   5      U R                  XR                   U   5      4PMR     nnU[        U R                  R                  5       5      -   $ s  snf rI   )rU   r   r  r!   r   r   )r3   r
  mapping_itemss      r+   r   _LazyAutoMapping.itemsP  s     **

 +***++C1E1Ec1JK++C1D1DS1IJ + 	 
 tD$7$7$=$=$?@@@
s   BA Bc                 4    [        U R                  5       5      $ rI   )iterr  r   s    r+   __iter___LazyAutoMapping.__iter__[  r#  r8   itemc                     XR                   ;   a  g[        US5      (       a  UR                  U R                  ;  a  gU R                  UR                     nX R                  ;   $ )NTr#   F)r   rT   r#   r   rU   )r3   r.  r  s      r+   __contains___LazyAutoMapping.__contains__^  sU    &&&tZ((DMMA]A],]11$--@
0000r8   valuec                     [        US5      (       aX  UR                  U R                  ;   a>  U R                  UR                     nX@R                  ;   a  U(       d  [	        SU S35      eX R
                  U'   g)z'
Register a new model in this mapping.
r#   'z*' is already used by a Transformers model.N)rT   r#   r   rU   r]   r   )r3   r
  r2  r@   r  s        r+   rY   _LazyAutoMapping.registerf  sg     3
##8T8T(T55cllCJ000 1SE)S!TUU#(C r8   )r   r   rU   r   r   r   r   )r#   r   r   r   r   r6   intr  r   r	   _LazyAutoMappingValuer  r  r!   r  r   r   r   r  r!  r   r"   r   r   r,  r0  rY   r   ri   r8   r+   r   r     s   ; ;t$45 :O  J?d4 012 ?t,-  uEZ\^E^?_ !$ !C23 C	AtE$'7"8:O"OPQ 	A!(4(8#9: !1 1$ 1	)D!12 	);P 	)ei 	) 	)r8   r   r   ) )zgoogle-bert/bert-base-casedr8  ):r   r   r   r   r   r   collectionsr   collections.abcr   typingr   r   r   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   r7  r   r   r   r   r   r,   r.   r   r   r   r   r   r   r[   r   __all__ri   r8   r+   <module>rD     sB   4    	  # $ & & 3 \
 
 
 i h - 
		H	%T]eDItO4eDItO6LLM  4j# Xa  Fa" H(XR XRv$]0 $]N  3  be  FM(@c){4(8#9;P#PQ c)L .r8   