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

Function save_model_hook

diffusers/examples/dreambooth/train_dreambooth.py:953–960  ·  view source on GitHub ↗
(models, weights, output_dir)

Source from the content-addressed store, hash-verified

951
952 # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
953 def save_model_hook(models, weights, output_dir):
954 if accelerator.is_main_process:
955 for model in models:
956 sub_dir = "unet" if isinstance(model, type(unwrap_model(unet))) else "text_encoder"
957 model.save_pretrained(os.path.join(output_dir, sub_dir))
958
959 # make sure to pop weight so that corresponding model is not saved again
960 weights.pop()
961
962 def load_model_hook(models, input_dir):
963 while len(models) > 0:

Callers

nothing calls this directly

Calls 3

unwrap_modelFunction · 0.70
save_pretrainedMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected