MCPcopy
hub / github.com/zai-org/CogVideo / load_model_from_config

Function load_model_from_config

sat/sgm/util.py:286–314  ·  view source on GitHub ↗
(config, ckpt, verbose=True, freeze=True)

Source from the content-addressed store, hash-verified

284
285
286def load_model_from_config(config, ckpt, verbose=True, freeze=True):
287 print(f"Loading model from {ckpt}")
288 if ckpt.endswith("ckpt"):
289 pl_sd = torch.load(ckpt, map_location="cpu")
290 if "global_step" in pl_sd:
291 print(f"Global Step: {pl_sd['global_step']}")
292 sd = pl_sd["state_dict"]
293 elif ckpt.endswith("safetensors"):
294 sd = load_safetensors(ckpt)
295 else:
296 raise NotImplementedError
297
298 model = instantiate_from_config(config.model)
299
300 m, u = model.load_state_dict(sd, strict=False)
301
302 if len(m) > 0 and verbose:
303 print("missing keys:")
304 print(m)
305 if len(u) > 0 and verbose:
306 print("unexpected keys:")
307 print(u)
308
309 if freeze:
310 for param in model.parameters():
311 param.requires_grad = False
312
313 model.eval()
314 return model
315
316
317def get_configs_path() -> str:

Callers

nothing calls this directly

Calls 5

loadMethod · 0.80
load_state_dictMethod · 0.80
parametersMethod · 0.80
instantiate_from_configFunction · 0.70
evalMethod · 0.45

Tested by

no test coverage detected