MCPcopy Index your code
hub / github.com/huggingface/diffusers / save_pretrained

Method save_pretrained

src/diffusers/models/adapter.py:105–145  ·  view source on GitHub ↗

Save a model and its configuration file to a specified directory, allowing it to be re-loaded with the `[`~models.adapter.MultiAdapter.from_pretrained`]` class method. Args: save_directory (`str` or `os.PathLike`): The directory where the model w

(
        self,
        save_directory: str | os.PathLike,
        is_main_process: bool = True,
        save_function: Callable = None,
        safe_serialization: bool = True,
        variant: str | None = None,
    )

Source from the content-addressed store, hash-verified

103 return accume_state
104
105 def save_pretrained(
106 self,
107 save_directory: str | os.PathLike,
108 is_main_process: bool = True,
109 save_function: Callable = None,
110 safe_serialization: bool = True,
111 variant: str | None = None,
112 ):
113 """
114 Save a model and its configuration file to a specified directory, allowing it to be re-loaded with the
115 `[`~models.adapter.MultiAdapter.from_pretrained`]` class method.
116
117 Args:
118 save_directory (`str` or `os.PathLike`):
119 The directory where the model will be saved. If the directory does not exist, it will be created.
120 is_main_process (`bool`, optional, defaults=True):
121 Indicates whether current process is the main process or not. Useful for distributed training (e.g.,
122 TPUs) and need to call this function on all processes. In this case, set `is_main_process=True` only
123 for the main process to avoid race conditions.
124 save_function (`Callable`):
125 Function used to save the state dictionary. Useful for distributed training (e.g., TPUs) to replace
126 `torch.save` with another method. Can also be configured using`DIFFUSERS_SAVE_MODE` environment
127 variable.
128 safe_serialization (`bool`, optional, defaults=True):
129 If `True`, save the model using `safetensors`. If `False`, save the model with `pickle`.
130 variant (`str`, *optional*):
131 If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
132 """
133 idx = 0
134 model_path_to_save = save_directory
135 for adapter in self.adapters:
136 adapter.save_pretrained(
137 model_path_to_save,
138 is_main_process=is_main_process,
139 save_function=save_function,
140 safe_serialization=safe_serialization,
141 variant=variant,
142 )
143
144 idx += 1
145 model_path_to_save = model_path_to_save + f"_{idx}"
146
147 @classmethod
148 def from_pretrained(cls, pretrained_model_path: str | os.PathLike | None, **kwargs):

Callers 3

push_to_hubMethod · 0.45
runMethod · 0.45
runMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected