Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the [`~ConfigMixin.from_config`] class method. Args: save_directory (`str` or `os.PathLike`): Directory where the configuration JSON file
(self, save_directory: Union[str, os.PathLike], push_to_hub: bool = False, **kwargs)
| 143 | raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'") |
| 144 | |
| 145 | def save_config(self, save_directory: Union[str, os.PathLike], push_to_hub: bool = False, **kwargs): |
| 146 | """ |
| 147 | Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the |
| 148 | [`~ConfigMixin.from_config`] class method. |
| 149 | |
| 150 | Args: |
| 151 | save_directory (`str` or `os.PathLike`): |
| 152 | Directory where the configuration JSON file is saved (will be created if it does not exist). |
| 153 | push_to_hub (`bool`, *optional*, defaults to `False`): |
| 154 | Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the |
| 155 | repository you want to push to with `repo_id` (will default to the name of `save_directory` in your |
| 156 | namespace). |
| 157 | kwargs (`Dict[str, Any]`, *optional*): |
| 158 | Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method. |
| 159 | """ |
| 160 | if os.path.isfile(save_directory): |
| 161 | raise AssertionError(f"Provided path ({save_directory}) should be a directory, not a file") |
| 162 | |
| 163 | os.makedirs(save_directory, exist_ok=True) |
| 164 | |
| 165 | # If we save using the predefined names, we can load using `from_config` |
| 166 | output_config_file = os.path.join(save_directory, self.config_name) |
| 167 | |
| 168 | self.to_json_file(output_config_file) |
| 169 | logger.info(f"Configuration saved in {output_config_file}") |
| 170 | |
| 171 | if push_to_hub: |
| 172 | commit_message = kwargs.pop("commit_message", None) |
| 173 | private = kwargs.pop("private", False) |
| 174 | create_pr = kwargs.pop("create_pr", False) |
| 175 | token = kwargs.pop("token", None) |
| 176 | repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1]) |
| 177 | repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id |
| 178 | |
| 179 | self._upload_folder( |
| 180 | save_directory, |
| 181 | repo_id, |
| 182 | token=token, |
| 183 | commit_message=commit_message, |
| 184 | create_pr=create_pr, |
| 185 | ) |
| 186 | |
| 187 | @classmethod |
| 188 | def from_config(cls, config: Union[FrozenDict, Dict[str, Any]] = None, return_unused_kwargs=False, **kwargs): |