From 6c4843567d56b76774527c9ad9deb2b37405d28b Mon Sep 17 00:00:00 2001 From: Rattus Date: Mon, 16 Mar 2026 21:57:26 +1000 Subject: [PATCH] wan: encode frames 2x2. Reduce VRAM usage greatly by encoding frames 2 at a time rather than 4. --- comfy/ldm/wan/vae.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comfy/ldm/wan/vae.py b/comfy/ldm/wan/vae.py index 65296afa8..a4a567130 100644 --- a/comfy/ldm/wan/vae.py +++ b/comfy/ldm/wan/vae.py @@ -458,11 +458,12 @@ class WanVAE(nn.Module): conv_idx = [0] ## cache t = x.shape[2] - iter_ = 1 + (t - 1) // 4 + t = 1 + ((t - 1) // 4) * 4 + iter_ = 1 + (t - 1) // 2 feat_map = None if iter_ > 1: feat_map = [None] * count_cache_layers(self.encoder) - ## 对encode输入的x,按时间拆分为1、4、4、4.... + ## 对encode输入的x,按时间拆分为1、2、2、2....(总帧数先按4N+1向下取整) for i in range(iter_): conv_idx = [0] if i == 0: @@ -472,7 +473,7 @@ class WanVAE(nn.Module): feat_idx=conv_idx) else: out_ = self.encoder( - x[:, :, 1 + 4 * (i - 1):1 + 4 * i, :, :], + x[:, :, 1 + 2 * (i - 1):1 + 2 * i, :, :], feat_cache=feat_map, feat_idx=conv_idx, final=(i == (iter_ - 1)))