MCPcopy
hub / github.com/huggingface/diffusers / save_config

Method save_config

src/diffusers/configuration_utils.py:178–220  ·  view source on GitHub ↗

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: str | os.PathLike, push_to_hub: bool = False, **kwargs)

Source from the content-addressed store, hash-verified

176 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
177
178 def save_config(self, save_directory: str | os.PathLike, push_to_hub: bool = False, **kwargs):
179 """
180 Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the
181 [`~ConfigMixin.from_config`] class method.
182
183 Args:
184 save_directory (`str` or `os.PathLike`):
185 Directory where the configuration JSON file is saved (will be created if it does not exist).
186 push_to_hub (`bool`, *optional*, defaults to `False`):
187 Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the
188 repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
189 namespace).
190 kwargs (`dict[str, Any]`, *optional*):
191 Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
192 """
193 if os.path.isfile(save_directory):
194 raise AssertionError(f"Provided path ({save_directory}) should be a directory, not a file")
195
196 os.makedirs(save_directory, exist_ok=True)
197
198 # If we save using the predefined names, we can load using `from_config`
199 output_config_file = os.path.join(save_directory, self.config_name)
200
201 self.to_json_file(output_config_file)
202 logger.info(f"Configuration saved in {output_config_file}")
203
204 if push_to_hub:
205 commit_message = kwargs.pop("commit_message", None)
206 private = kwargs.pop("private", None)
207 create_pr = kwargs.pop("create_pr", False)
208 token = kwargs.pop("token", None)
209 repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])
210 repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id
211 subfolder = kwargs.pop("subfolder", None)
212
213 self._upload_folder(
214 save_directory,
215 repo_id,
216 token=token,
217 commit_message=commit_message,
218 create_pr=create_pr,
219 subfolder=subfolder,
220 )
221
222 @classmethod
223 def from_config(

Callers 15

save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
save_pretrainedMethod · 0.80
test_save_loadMethod · 0.80

Calls 5

to_json_fileMethod · 0.95
infoMethod · 0.80
splitMethod · 0.80
_upload_folderMethod · 0.80
popMethod · 0.45

Tested by 15

test_save_loadMethod · 0.64
test_save_load_configMethod · 0.64
check_over_configsMethod · 0.64
check_over_forwardMethod · 0.64
check_over_configsMethod · 0.64
check_over_forwardMethod · 0.64
check_over_configsMethod · 0.64
check_over_forwardMethod · 0.64
check_over_configsMethod · 0.64