MCPcopy Index your code
hub / github.com/YesianRohn/TextSSR / load_model_hook

Function load_model_hook

train_diff.py:192–208  ·  view source on GitHub ↗
(models, input_dir)

Source from the content-addressed store, hash-verified

190 weights.pop()
191
192 def load_model_hook(models, input_dir):
193 if cfgs.use_ema:
194 load_model = EMAModel.from_pretrained(os.path.join(input_dir, "unet_ema"), UNet2DConditionModel)
195 ema_unet.load_state_dict(load_model.state_dict())
196 ema_unet.to(accelerator.device)
197 del load_model
198
199 for i in range(len(models)):
200 # pop models so that they are not loaded again
201 model = models.pop()
202
203 # load diffusers style into model
204 load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet")
205 model.register_to_config(**load_model.config)
206
207 model.load_state_dict(load_model.state_dict())
208 del load_model
209
210 accelerator.register_save_state_pre_hook(save_model_hook)
211 accelerator.register_load_state_pre_hook(load_model_hook)

Callers

nothing calls this directly

Calls 6

load_state_dictMethod · 0.80
register_to_configMethod · 0.80
from_pretrainedMethod · 0.45
state_dictMethod · 0.45
toMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected