MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / create_vae_diffusers_config

Function create_vae_diffusers_config

scripts/convert_zero123_to_diffusers.py:492–513  ·  view source on GitHub ↗

Creates a config for the diffusers based on the config of the LDM model.

(original_config, image_size: int)

Source from the content-addressed store, hash-verified

490
491
492def 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
516def convert_ldm_vae_checkpoint(checkpoint, config):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected