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

Function main

diffusers/scripts/convert_k_upscaler_to_diffusers.py:269–288  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

267
268
269def main(args):
270 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
271
272 orig_config_path = huggingface_hub.hf_hub_download(UPSCALER_REPO, "config_laion_text_cond_latent_upscaler_2.json")
273 orig_weights_path = huggingface_hub.hf_hub_download(
274 UPSCALER_REPO, "laion_text_cond_latent_upscaler_2_1_00470000_slim.pth"
275 )
276 print(f"loading original model configuration from {orig_config_path}")
277 print(f"loading original model checkpoint from {orig_weights_path}")
278
279 print("converting to diffusers unet")
280 orig_config = K.config.load_config(open(orig_config_path))["model"]
281 model = unet_model_from_original_config(orig_config)
282
283 orig_checkpoint = torch.load(orig_weights_path, map_location=device)["model_ema"]
284 converted_checkpoint = unet_to_diffusers_checkpoint(model, orig_checkpoint)
285
286 model.load_state_dict(converted_checkpoint, strict=True)
287 model.save_pretrained(args.dump_path)
288 print(f"saving converted unet model in {args.dump_path}")
289
290
291if __name__ == "__main__":

Calls 7

load_configMethod · 0.80
load_state_dictMethod · 0.80
deviceMethod · 0.45
loadMethod · 0.45
save_pretrainedMethod · 0.45

Tested by

no test coverage detected