r""" Instantiate a :class:`~transformers.PretrainedConfig` (or a derived class) from a pre-trained model configuration. Args: pretrained_model_name_or_path (:obj:`string`): either: - a string with the `shortcut name` of a pre-trained mo
(cls, pretrained_model_name_or_path, **kwargs)
| 143 | |
| 144 | @classmethod |
| 145 | def from_pretrained(cls, pretrained_model_name_or_path, **kwargs) -> "PretrainedConfig": |
| 146 | r""" |
| 147 | |
| 148 | Instantiate a :class:`~transformers.PretrainedConfig` (or a derived class) from a pre-trained model configuration. |
| 149 | |
| 150 | Args: |
| 151 | pretrained_model_name_or_path (:obj:`string`): |
| 152 | either: |
| 153 | - a string with the `shortcut name` of a pre-trained model configuration to load from cache or |
| 154 | download, e.g.: ``bert-base-uncased``. |
| 155 | - a string with the `identifier name` of a pre-trained model configuration that was user-uploaded to |
| 156 | our S3, e.g.: ``dbmdz/bert-base-german-cased``. |
| 157 | - a path to a `directory` containing a configuration file saved using the |
| 158 | :func:`~transformers.PretrainedConfig.save_pretrained` method, e.g.: ``./my_model_directory/``. |
| 159 | - a path or url to a saved configuration JSON `file`, e.g.: |
| 160 | ``./my_model_directory/configuration.json``. |
| 161 | cache_dir (:obj:`string`, `optional`): |
| 162 | Path to a directory in which a downloaded pre-trained model |
| 163 | configuration should be cached if the standard cache should not be used. |
| 164 | kwargs (:obj:`Dict[str, any]`, `optional`): |
| 165 | The values in kwargs of any keys which are configuration attributes will be used to override the loaded |
| 166 | values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is |
| 167 | controlled by the `return_unused_kwargs` keyword parameter. |
| 168 | force_download (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 169 | Force to (re-)download the model weights and configuration files and override the cached versions if they exist. |
| 170 | resume_download (:obj:`bool`, `optional`, defaults to :obj:`False`): |
| 171 | Do not delete incompletely recieved file. Attempt to resume the download if such a file exists. |
| 172 | proxies (:obj:`Dict`, `optional`): |
| 173 | A dictionary of proxy servers to use by protocol or endpoint, e.g.: |
| 174 | :obj:`{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.` |
| 175 | The proxies are used on each request. |
| 176 | return_unused_kwargs: (`optional`) bool: |
| 177 | If False, then this function returns just the final configuration object. |
| 178 | If True, then this functions returns a :obj:`Tuple(config, unused_kwargs)` where `unused_kwargs` is a |
| 179 | dictionary consisting of the key/value pairs whose keys are not configuration attributes: ie the part |
| 180 | of kwargs which has not been used to update `config` and is otherwise ignored. |
| 181 | |
| 182 | Returns: |
| 183 | :class:`PretrainedConfig`: An instance of a configuration object |
| 184 | |
| 185 | Examples:: |
| 186 | |
| 187 | # We can't instantiate directly the base class `PretrainedConfig` so let's show the examples on a |
| 188 | # derived class: BertConfig |
| 189 | config = BertConfig.from_pretrained('bert-base-uncased') # Download configuration from S3 and cache. |
| 190 | config = BertConfig.from_pretrained('./test/saved_model/') # E.g. config (or model) was saved using `save_pretrained('./test/saved_model/')` |
| 191 | config = BertConfig.from_pretrained('./test/saved_model/my_configuration.json') |
| 192 | config = BertConfig.from_pretrained('bert-base-uncased', output_attention=True, foo=False) |
| 193 | assert config.output_attention == True |
| 194 | config, unused_kwargs = BertConfig.from_pretrained('bert-base-uncased', output_attention=True, |
| 195 | foo=False, return_unused_kwargs=True) |
| 196 | assert config.output_attention == True |
| 197 | assert unused_kwargs == {'foo': False} |
| 198 | |
| 199 | """ |
| 200 | config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs) |
| 201 | return cls.from_dict(config_dict, **kwargs) |
| 202 |
nothing calls this directly
no test coverage detected