MCPcopy Create free account
hub / github.com/IceClear/StableSR / load_model_from_config

Function load_model_from_config

app.py:131–148  ·  view source on GitHub ↗
(config, ckpt, verbose=False)

Source from the content-addressed store, hash-verified

129 return iter(lambda: tuple(islice(it, size)), ())
130
131def load_model_from_config(config, ckpt, verbose=False):
132 print(f"Loading model from {ckpt}")
133 pl_sd = torch.load(ckpt, map_location="cpu")
134 if "global_step" in pl_sd:
135 print(f"Global Step: {pl_sd['global_step']}")
136 sd = pl_sd["state_dict"]
137 model = instantiate_from_config(config.model)
138 m, u = model.load_state_dict(sd, strict=False)
139 if len(m) > 0 and verbose:
140 print("missing keys:")
141 print(m)
142 if len(u) > 0 and verbose:
143 print("unexpected keys:")
144 print(u)
145
146 model.cuda()
147 model.eval()
148 return model
149
150# device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
151device = torch.device("cuda")

Callers 2

app.pyFile · 0.70
inferenceFunction · 0.70

Calls 2

instantiate_from_configFunction · 0.90
loadMethod · 0.80

Tested by

no test coverage detected