MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / save_pretrained

Method save_pretrained

diffusers/src/diffusers/models/adapter.py:103–143  ·  view source on GitHub ↗

Save a model and its configuration file to a directory, so that it can be re-loaded using the `[`~models.adapter.MultiAdapter.from_pretrained`]` class method. Arguments: save_directory (`str` or `os.PathLike`): Directory to which to save. Will be

(
        self,
        save_directory: Union[str, os.PathLike],
        is_main_process: bool = True,
        save_function: Callable = None,
        safe_serialization: bool = True,
        variant: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

101 return accume_state
102
103 def save_pretrained(
104 self,
105 save_directory: Union[str, os.PathLike],
106 is_main_process: bool = True,
107 save_function: Callable = None,
108 safe_serialization: bool = True,
109 variant: Optional[str] = None,
110 ):
111 """
112 Save a model and its configuration file to a directory, so that it can be re-loaded using the
113 `[`~models.adapter.MultiAdapter.from_pretrained`]` class method.
114
115 Arguments:
116 save_directory (`str` or `os.PathLike`):
117 Directory to which to save. Will be created if it doesn't exist.
118 is_main_process (`bool`, *optional*, defaults to `True`):
119 Whether the process calling this is the main process or not. Useful when in distributed training like
120 TPUs and need to call this function on all processes. In this case, set `is_main_process=True` only on
121 the main process to avoid race conditions.
122 save_function (`Callable`):
123 The function to use to save the state dictionary. Useful on distributed training like TPUs when one
124 need to replace `torch.save` by another method. Can be configured with the environment variable
125 `DIFFUSERS_SAVE_MODE`.
126 safe_serialization (`bool`, *optional*, defaults to `True`):
127 Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
128 variant (`str`, *optional*):
129 If specified, weights are saved in the format pytorch_model.<variant>.bin.
130 """
131 idx = 0
132 model_path_to_save = save_directory
133 for adapter in self.adapters:
134 adapter.save_pretrained(
135 model_path_to_save,
136 is_main_process=is_main_process,
137 save_function=save_function,
138 safe_serialization=safe_serialization,
139 variant=variant,
140 )
141
142 idx += 1
143 model_path_to_save = model_path_to_save + f"_{idx}"
144
145 @classmethod
146 def from_pretrained(cls, pretrained_model_path: Optional[Union[str, os.PathLike]], **kwargs):

Callers 3

push_to_hubMethod · 0.45
runMethod · 0.45
save_motion_modulesMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected