(args)
| 267 | |
| 268 | |
| 269 | def 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 | |
| 291 | if __name__ == "__main__": |
no test coverage detected