From a `pretrained_model_name_or_path`, resolve to a dictionary of parameters, to be used for instantiating a Config using `from_dict`. Parameters: pretrained_model_name_or_path (:obj:`string`): The identifier of the pre-trained checkpoint from w
(cls, pretrained_model_name_or_path: str, **kwargs)
| 202 | |
| 203 | @classmethod |
| 204 | def get_config_dict(cls, pretrained_model_name_or_path: str, **kwargs) -> Tuple[Dict, Dict]: |
| 205 | """ |
| 206 | From a `pretrained_model_name_or_path`, resolve to a dictionary of parameters, to be used |
| 207 | for instantiating a Config using `from_dict`. |
| 208 | |
| 209 | Parameters: |
| 210 | pretrained_model_name_or_path (:obj:`string`): |
| 211 | The identifier of the pre-trained checkpoint from which we want the dictionary of parameters. |
| 212 | |
| 213 | Returns: |
| 214 | :obj:`Tuple[Dict, Dict]`: The dictionary that will be used to instantiate the configuration object. |
| 215 | |
| 216 | """ |
| 217 | cache_dir = kwargs.pop("cache_dir", None) |
| 218 | force_download = kwargs.pop("force_download", False) |
| 219 | resume_download = kwargs.pop("resume_download", False) |
| 220 | proxies = kwargs.pop("proxies", None) |
| 221 | local_files_only = kwargs.pop("local_files_only", False) |
| 222 | |
| 223 | if os.path.isdir(pretrained_model_name_or_path): |
| 224 | config_file = os.path.join(pretrained_model_name_or_path, CONFIG_NAME) |
| 225 | elif os.path.isfile(pretrained_model_name_or_path) or is_remote_url(pretrained_model_name_or_path): |
| 226 | config_file = pretrained_model_name_or_path |
| 227 | else: |
| 228 | config_file = hf_bucket_url(pretrained_model_name_or_path, filename=CONFIG_NAME, use_cdn=False) |
| 229 | |
| 230 | try: |
| 231 | # Load from URL or cache if already cached |
| 232 | resolved_config_file = cached_path( |
| 233 | config_file, |
| 234 | cache_dir=cache_dir, |
| 235 | force_download=force_download, |
| 236 | proxies=proxies, |
| 237 | resume_download=resume_download, |
| 238 | local_files_only=local_files_only, |
| 239 | ) |
| 240 | # Load config dict |
| 241 | if resolved_config_file is None: |
| 242 | raise EnvironmentError |
| 243 | config_dict = cls._dict_from_json_file(resolved_config_file) |
| 244 | |
| 245 | except EnvironmentError: |
| 246 | msg = ( |
| 247 | f"Can't load config for '{pretrained_model_name_or_path}'. Make sure that:\n\n" |
| 248 | f"- '{pretrained_model_name_or_path}' is a correct model identifier listed on 'https://huggingface.co/models'\n\n" |
| 249 | f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a {CONFIG_NAME} file\n\n" |
| 250 | ) |
| 251 | raise EnvironmentError(msg) |
| 252 | |
| 253 | except json.JSONDecodeError: |
| 254 | msg = ( |
| 255 | "Couldn't reach server at '{}' to download configuration file or " |
| 256 | "configuration file is not a valid JSON file. " |
| 257 | "Please check network or file content here: {}.".format(config_file, resolved_config_file) |
| 258 | ) |
| 259 | raise EnvironmentError(msg) |
| 260 | |
| 261 | if resolved_config_file == config_file: |
no test coverage detected