Commit 5d8a8bf
committed
fix(wan): WanModel.patchify flatten + return grid size tuple
Fixes #1063.
WanModel.forward (and the parallel usp_dit_forward in
diffsynth/utils/xfuser/xdit_context_parallel.py) both unpack
patchify's return value as `x, (f, h, w) = self.patchify(x)`, but
patchify only returns `x` -- and that `x` is a 5D (B, dim, f, h, w)
tensor straight out of Conv3d, not the (B, f*h*w, dim) sequence the
transformer blocks expect.
Net result: every Wan training run crashes at the first forward call
with `ValueError: not enough values to unpack (expected 2, got 1)`.
The block loop never executes.
The fix: extract (f, h, w) from the Conv3d output shape, flatten the
3D spatial-temporal grid into a token sequence (B, f*h*w, dim) ready
for the transformer blocks, return (x, (f, h, w)) to match what
forward and unpatchify expect.
Verified end-to-end with a synthetic 8-layer WanModel on the same
forward path (input shape (1, 16, 4, 8, 8) -> output shape
(1, 16, 4, 8, 8) round-trip), forward + backward both complete,
loss gradient propagates through all blocks.1 parent bf5faf6 commit 5d8a8bf
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
502 | 508 | | |
503 | 509 | | |
504 | 510 | | |
| |||
0 commit comments