From 5fe57f42fad382c49bb58795f72ea77761898698 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 21 Sep 2026 20:20:18 -0700 Subject: [PATCH] comfyui: add VAE 4D-to-5D latent expansion to patch script --- dankclaw/apply_qwen21_patch.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dankclaw/apply_qwen21_patch.py b/dankclaw/apply_qwen21_patch.py index 22b996f..125f8f8 100644 --- a/dankclaw/apply_qwen21_patch.py +++ b/dankclaw/apply_qwen21_patch.py @@ -32,3 +32,21 @@ if os.path.exists(loader): with open(loader, "w") as fh: fh.write(lcode) print("Applied qwen_image21 arch list patch") + +# Patch VAE decode to expand 4D latents to 5D for video VAEs (latent_dim=3) +sd = "/opt/ComfyUI/comfy/sd.py" +with open(sd) as fh: + sdc = fh.read() +if "self.latent_dim == 3 and samples_in.ndim == 4" not in sdc: + anchor = " if self.latent_dim == 2 and samples_in.ndim == 5:\n samples_in = samples_in[:, :, 0]" + replacement = ( + " if self.latent_dim == 2 and samples_in.ndim == 5:\n" + " samples_in = samples_in[:, :, 0]\n" + " elif self.latent_dim == 3 and samples_in.ndim == 4:\n" + " samples_in = samples_in.unsqueeze(2)" + ) + if anchor in sdc: + sdc = sdc.replace(anchor, replacement) + with open(sd, "w") as fh: + fh.write(sdc) + print("Applied VAE 4D-to-5D latent expansion patch")