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

Function save_model_hook

diffusers/examples/controlnet/train_controlnet.py:829–840  ·  view source on GitHub ↗
(models, weights, output_dir)

Source from the content-addressed store, hash-verified

827 if version.parse(accelerate.__version__) >= version.parse("0.16.0"):
828 # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
829 def save_model_hook(models, weights, output_dir):
830 if accelerator.is_main_process:
831 i = len(weights) - 1
832
833 while len(weights) > 0:
834 weights.pop()
835 model = models[i]
836
837 sub_dir = "controlnet"
838 model.save_pretrained(os.path.join(output_dir, sub_dir))
839
840 i -= 1
841
842 def load_model_hook(models, input_dir):
843 while len(models) > 0:

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
save_pretrainedMethod · 0.45

Tested by

no test coverage detected