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

Function save_model_hook

diffusers/examples/controlnet/train_controlnet_sd3.py:1018–1029  ·  view source on GitHub ↗
(models, weights, output_dir)

Source from the content-addressed store, hash-verified

1016 if version.parse(accelerate.__version__) >= version.parse("0.16.0"):
1017 # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
1018 def save_model_hook(models, weights, output_dir):
1019 if accelerator.is_main_process:
1020 i = len(weights) - 1
1021
1022 while len(weights) > 0:
1023 weights.pop()
1024 model = models[i]
1025
1026 sub_dir = "controlnet"
1027 model.save_pretrained(os.path.join(output_dir, sub_dir))
1028
1029 i -= 1
1030
1031 def load_model_hook(models, input_dir):
1032 while len(models) > 0:

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
save_pretrainedMethod · 0.45

Tested by

no test coverage detected