Read config from hub or local path Args: model_id_or_path (str): Model repo name or local directory path. revision: revision of the model when getting from the hub Return: config (:obj:`Config`): config object
(model_id_or_path: str,
revision: Optional[str] = DEFAULT_MODEL_REVISION)
| 38 | |
| 39 | |
| 40 | def read_config(model_id_or_path: str, |
| 41 | revision: Optional[str] = DEFAULT_MODEL_REVISION): |
| 42 | """ Read config from hub or local path |
| 43 | |
| 44 | Args: |
| 45 | model_id_or_path (str): Model repo name or local directory path. |
| 46 | revision: revision of the model when getting from the hub |
| 47 | Return: |
| 48 | config (:obj:`Config`): config object |
| 49 | """ |
| 50 | if not os.path.exists(model_id_or_path): |
| 51 | local_path = model_file_download( |
| 52 | model_id_or_path, ModelFile.CONFIGURATION, revision=revision) |
| 53 | elif os.path.isdir(model_id_or_path): |
| 54 | local_path = os.path.join(model_id_or_path, ModelFile.CONFIGURATION) |
| 55 | elif os.path.isfile(model_id_or_path): |
| 56 | local_path = model_id_or_path |
| 57 | else: |
| 58 | return None |
| 59 | |
| 60 | return Config.from_file(local_path) |
| 61 | |
| 62 | |
| 63 | def auto_load(model: Union[str, List[str]]): |
searching dependent graphs…