Creates a config for the diffusers based on the config of the LDM model.
(original_config, image_size: int)
| 490 | |
| 491 | |
| 492 | def create_vae_diffusers_config(original_config, image_size: int): |
| 493 | """ |
| 494 | Creates a config for the diffusers based on the config of the LDM model. |
| 495 | """ |
| 496 | vae_params = original_config["model"]["params"]["first_stage_config"]["params"]["ddconfig"] |
| 497 | _ = original_config["model"]["params"]["first_stage_config"]["params"]["embed_dim"] |
| 498 | |
| 499 | block_out_channels = [vae_params["ch"] * mult for mult in vae_params["ch_mult"]] |
| 500 | down_block_types = ["DownEncoderBlock2D"] * len(block_out_channels) |
| 501 | up_block_types = ["UpDecoderBlock2D"] * len(block_out_channels) |
| 502 | |
| 503 | config = { |
| 504 | "sample_size": image_size, |
| 505 | "in_channels": vae_params["in_channels"], |
| 506 | "out_channels": vae_params["out_ch"], |
| 507 | "down_block_types": tuple(down_block_types), |
| 508 | "up_block_types": tuple(up_block_types), |
| 509 | "block_out_channels": tuple(block_out_channels), |
| 510 | "latent_channels": vae_params["z_channels"], |
| 511 | "layers_per_block": vae_params["num_res_blocks"], |
| 512 | } |
| 513 | return config |
| 514 | |
| 515 | |
| 516 | def convert_ldm_vae_checkpoint(checkpoint, config): |
no outgoing calls
no test coverage detected