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

Function load_model_hook

diffusers/examples/dreambooth/train_dreambooth.py:962–977  ·  view source on GitHub ↗
(models, input_dir)

Source from the content-addressed store, hash-verified

960 weights.pop()
961
962 def load_model_hook(models, input_dir):
963 while len(models) > 0:
964 # pop models so that they are not loaded again
965 model = models.pop()
966
967 if isinstance(model, type(unwrap_model(text_encoder))):
968 # load transformers style into model
969 load_model = text_encoder_cls.from_pretrained(input_dir, subfolder="text_encoder")
970 model.config = load_model.config
971 else:
972 # load diffusers style into model
973 load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet")
974 model.register_to_config(**load_model.config)
975
976 model.load_state_dict(load_model.state_dict())
977 del load_model
978
979 accelerator.register_save_state_pre_hook(save_model_hook)
980 accelerator.register_load_state_pre_hook(load_model_hook)

Callers

nothing calls this directly

Calls 6

register_to_configMethod · 0.80
load_state_dictMethod · 0.80
unwrap_modelFunction · 0.70
popMethod · 0.45
from_pretrainedMethod · 0.45
state_dictMethod · 0.45

Tested by

no test coverage detected