Skip to content

Commit d15b3ec

Browse files
committed
support loading VAE
1 parent bad7cb2 commit d15b3ec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/sd_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ def load_model_weights(model, checkpoint_file, sd_model_hash):
134134

135135
devices.dtype = torch.float32 if shared.cmd_opts.no_half else torch.float16
136136

137+
vae_file = os.path.splitext(checkpoint_file)[0] + ".vae.pt"
138+
if os.path.exists(vae_file):
139+
print(f"Loading VAE weights from: {vae_file}")
140+
vae_ckpt = torch.load(vae_file, map_location="cpu")
141+
vae_dict = {k: v for k, v in vae_ckpt["state_dict"].items() if k[0:4] != "loss"}
142+
143+
model.first_stage_model.load_state_dict(vae_dict)
144+
137145
model.sd_model_hash = sd_model_hash
138146
model.sd_model_checkpint = checkpoint_file
139147

0 commit comments

Comments
 (0)