Skip to content

Commit 6119e4a

Browse files
fix(wan): adapt patchify consumers to bare-tensor return (#1063)
WanModel.patchify returns a bare [b,c,f,h,w] tensor, but WanModel.forward and usp_dit_forward unpacked x, (f,h,w) = self.patchify(x). Flatten and derive the grid in the consumers to match. Drops the earlier model_fn_wans2v edit: that path runs WanS2VModel, whose patchify already returns (flattened_x, grid_size), so the original tuple-unpack was correct.
1 parent bf5faf6 commit 6119e4a

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

diffsynth/models/wan_video_dit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,10 @@ def forward(self,
527527
clip_embdding = self.img_emb(clip_feature)
528528
context = torch.cat([clip_embdding, context], dim=1)
529529

530-
x, (f, h, w) = self.patchify(x)
531-
530+
x = self.patchify(x)
531+
f, h, w = x.shape[-3], x.shape[-2], x.shape[-1]
532+
x = x.flatten(2).transpose(1, 2)
533+
532534
freqs = torch.cat([
533535
self.freqs[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
534536
self.freqs[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),

diffsynth/utils/xfuser/xdit_context_parallel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def usp_dit_forward(self,
8181
clip_embdding = self.img_emb(clip_feature)
8282
context = torch.cat([clip_embdding, context], dim=1)
8383

84-
x, (f, h, w) = self.patchify(x)
85-
84+
x = self.patchify(x)
85+
f, h, w = x.shape[-3], x.shape[-2], x.shape[-1]
86+
x = x.flatten(2).transpose(1, 2)
87+
8688
freqs = torch.cat([
8789
self.freqs[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
8890
self.freqs[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),

0 commit comments

Comments
 (0)