U
    &ºcå,  ã                   @   s  d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZmZ ddlmZmZ dd	lmZmZ dd
lmZ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  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- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; e <e=¡Z>e?dd„ eee$e/eee:e4e)eeee,e7eefD ƒƒZ@ede-fdefdefdefde8fd e"fd!e	fd"e'fd#e*fd$efd%efd&e%fd'e fd(e0fd)e;fd*e5fd+efd,efd-efgƒZAG d.d/„ d/ƒZBdS )0z Auto Config class. é    N)ÚOrderedDicté   )Ú$ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAPÚAlbertConfig)Ú"BART_PRETRAINED_CONFIG_ARCHIVE_MAPÚ
BartConfig)Ú"BERT_PRETRAINED_CONFIG_ARCHIVE_MAPÚ
BertConfig)Ú'CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAPÚCamembertConfig)Ú"CTRL_PRETRAINED_CONFIG_ARCHIVE_MAPÚ
CTRLConfig)Ú(DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAPÚDistilBertConfig)Ú%ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAPÚElectraConfig)ÚEncoderDecoderConfig)Ú&FLAUBERT_PRETRAINED_CONFIG_ARCHIVE_MAPÚFlaubertConfig)Ú"GPT2_PRETRAINED_CONFIG_ARCHIVE_MAPÚ
GPT2Config)ÚMarianConfig)Ú(OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAPÚOpenAIGPTConfig)ÚReformerConfig)Ú%ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAPÚRobertaConfig)Ú T5_PRETRAINED_CONFIG_ARCHIVE_MAPÚT5Config)Ú(TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAPÚTransfoXLConfig)ÚPretrainedConfig)Ú!XLM_PRETRAINED_CONFIG_ARCHIVE_MAPÚ	XLMConfig)Ú)XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAPÚXLMRobertaConfig)Ú#XLNET_PRETRAINED_CONFIG_ARCHIVE_MAPÚXLNetConfigc                 c   s(   | ] }|  ¡ D ]\}}||fV  qqd S )N)Úitems)Ú.0Zpretrained_mapÚkeyÚvalue© r,   úC/tmp/pip-unpacked-wheel-ymerj3tt/transformers/configuration_auto.pyÚ	<genexpr>.   s   
 ír.   Zt5Z
distilbertZalbertZ	camembertzxlm-robertaZmarianZbartZreformerZrobertaZflaubertZbertz
openai-gptZgpt2z
transfo-xlZxlnetZxlmZctrlZelectrazencoder-decoderc                   @   s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	Ú
AutoConfiga5  
        :class:`~transformers.AutoConfig` is a generic configuration class
        that will be instantiated as one of the configuration classes of the library
        when created with the :func:`~transformers.AutoConfig.from_pretrained` class method.

        The :func:`~transformers.AutoConfig.from_pretrained` method takes care of returning the correct model class instance
        based on the `model_type` property of the config object, or when it's missing,
        falling back to using pattern matching on the `pretrained_model_name_or_path` string.
    c                 C   s   t dƒ‚d S )NzwAutoConfig is designed to be instantiated using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method.)ÚEnvironmentError)Úselfr,   r,   r-   Ú__init__j   s    ÿzAutoConfig.__init__c                 O   sF   t  ¡ D ]\}}||kr|||Ž  S qtd |d t  ¡ ¡¡ƒ‚d S )Nz=Unrecognized model identifier in {}. Should contain one of {}ú, )ÚCONFIG_MAPPINGr(   Ú
ValueErrorÚformatÚjoinÚkeys)ÚclsÚ
model_typeÚargsÚkwargsÚpatternÚconfig_classr,   r,   r-   Ú	for_modelp   s     ÿÿzAutoConfig.for_modelc                 K   s†   t j|fdti|—Ž\}}d|kr<t|d  }|j|f|ŽS t ¡ D ]"\}}||krD|j|f|Ž  S qDtd |d t 	¡ ¡¡ƒ‚dS )a«   Instantiates one of the configuration classes of the library
        from a pre-trained model configuration.

        The configuration class to instantiate is selected
        based on the `model_type` property of the config object, or when it's missing,
        falling back to using pattern matching on the `pretrained_model_name_or_path` string.
            - contains `t5`: :class:`~transformers.T5Config` (T5 model)
            - contains `distilbert`: :class:`~transformers.DistilBertConfig` (DistilBERT model)
            - contains `albert`: :class:`~transformers.AlbertConfig` (ALBERT model)
            - contains `camembert`: :class:`~transformers.CamembertConfig` (CamemBERT model)
            - contains `xlm-roberta`: :class:`~transformers.XLMRobertaConfig` (XLM-RoBERTa model)
            - contains `roberta`: :class:`~transformers.RobertaConfig` (RoBERTa model)
            - contains `reformer`: :class:`~transformers.ReformerConfig` (Reformer model)
            - contains `bert`: :class:`~transformers.BertConfig` (Bert model)
            - contains `openai-gpt`: :class:`~transformers.OpenAIGPTConfig` (OpenAI GPT model)
            - contains `gpt2`: :class:`~transformers.GPT2Config` (OpenAI GPT-2 model)
            - contains `transfo-xl`: :class:`~transformers.TransfoXLConfig` (Transformer-XL model)
            - contains `xlnet`: :class:`~transformers.XLNetConfig` (XLNet model)
            - contains `xlm`: :class:`~transformers.XLMConfig` (XLM model)
            - contains `ctrl` : :class:`~transformers.CTRLConfig` (CTRL model)
            - contains `flaubert` : :class:`~transformers.FlaubertConfig` (Flaubert model)
            - contains `electra` : :class:`~transformers.ElectraConfig` (ELECTRA model)


        Args:
            pretrained_model_name_or_path (:obj:`string`):
                Is either: \
                    - a string with the `shortcut name` of a pre-trained model configuration to load from cache or download, e.g.: ``bert-base-uncased``.
                    - a string with the `identifier name` of a pre-trained model configuration that was user-uploaded to our S3, e.g.: ``dbmdz/bert-base-german-cased``.
                    - a path to a `directory` containing a configuration file saved using the :func:`~transformers.PretrainedConfig.save_pretrained` method, e.g.: ``./my_model_directory/``.
                    - a path or url to a saved configuration JSON `file`, e.g.: ``./my_model_directory/configuration.json``.

            cache_dir (:obj:`string`, optional, defaults to `None`):
                Path to a directory in which a downloaded pre-trained model
                configuration should be cached if the standard cache should not be used.

            force_download (:obj:`boolean`, optional, defaults to `False`):
                Force to (re-)download the model weights and configuration files and override the cached versions if they exist.

            resume_download (:obj:`boolean`, optional, defaults to `False`):
                Do not delete incompletely received file. Attempt to resume the download if such a file exists.

            proxies (:obj:`Dict[str, str]`, optional, defaults to `None`):
                A dictionary of proxy servers to use by protocol or endpoint, e.g.: :obj:`{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`.
                The proxies are used on each request. See `the requests documentation <https://requests.readthedocs.io/en/master/user/advanced/#proxies>`__ for usage.

            return_unused_kwargs (:obj:`boolean`, optional, defaults to `False`):
                - If False, then this function returns just the final configuration object.
                - If True, then this functions returns a tuple `(config, unused_kwargs)` where `unused_kwargs` is a dictionary consisting of the key/value pairs whose keys are not configuration attributes: ie the part of kwargs which has not been used to update `config` and is otherwise ignored.

            kwargs (:obj:`Dict[str, any]`, optional, defaults to `{}`): key/value pairs with which to update the configuration object after loading.
                - The values in kwargs of any keys which are configuration attributes will be used to override the loaded values.
                - Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled by the `return_unused_kwargs` keyword parameter.


        Examples::

            config = AutoConfig.from_pretrained('bert-base-uncased')  # Download configuration from S3 and cache.
            config = AutoConfig.from_pretrained('./test/bert_saved_model/')  # E.g. config (or model) was saved using `save_pretrained('./test/saved_model/')`
            config = AutoConfig.from_pretrained('./test/bert_saved_model/my_configuration.json')
            config = AutoConfig.from_pretrained('bert-base-uncased', output_attention=True, foo=False)
            assert config.output_attention == True
            config, unused_kwargs = AutoConfig.from_pretrained('bert-base-uncased', output_attention=True,
                                                               foo=False, return_unused_kwargs=True)
            assert config.output_attention == True
            assert unused_kwargs == {'foo': False}

        Zpretrained_config_archive_mapr:   z„Unrecognized model in {}. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: {}r3   N)
r!   Zget_config_dictÚ!ALL_PRETRAINED_CONFIG_ARCHIVE_MAPr4   Ú	from_dictr(   r5   r6   r7   r8   )r9   Zpretrained_model_name_or_pathr<   Zconfig_dictÚ_r>   r=   r,   r,   r-   Úfrom_pretrained{   s&    Fÿÿÿ
 þÿzAutoConfig.from_pretrainedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   Úclassmethodr?   rC   r,   r,   r,   r-   r/   _   s   


r/   )CrG   ÚloggingÚcollectionsr   Zconfiguration_albertr   r   Zconfiguration_bartr   r   Zconfiguration_bertr   r	   Zconfiguration_camembertr
   r   Zconfiguration_ctrlr   r   Zconfiguration_distilbertr   r   Zconfiguration_electrar   r   Zconfiguration_encoder_decoderr   Zconfiguration_flaubertr   r   Zconfiguration_gpt2r   r   Zconfiguration_marianr   Zconfiguration_openair   r   Zconfiguration_reformerr   Zconfiguration_robertar   r   Zconfiguration_t5r   r   Zconfiguration_transfo_xlr   r    Zconfiguration_utilsr!   Zconfiguration_xlmr"   r#   Zconfiguration_xlm_robertar$   r%   Zconfiguration_xlnetr&   r'   Ú	getLoggerrD   ÚloggerÚdictr@   r4   r/   r,   r,   r,   r-   Ú<module>   s‚   
ðþíÿ