[bugfix] Wan I2V: CLIP image conditioning silently dropped when passed as a tensor during training - #1673
Merged
Conversation
WanTransformer3DModel.forward (and the causal/dreamx/lingbotworld variants) unwrapped encoder_hidden_states_image only when it was a list, and set it to None otherwise -- discarding a bare tensor even though the signature accepts torch.Tensor | list[torch.Tensor] | None. The inference pipelines store image_embeds as a list (image_encoding.py), so they were unaffected. Every I2V *training* pipeline passes the CLIP features directly as a tensor (wan_i2v_training_pipeline.py:129, wan_i2v_distillation_pipeline.py:170, self_forcing_distillation_pipeline.py), so those trained with no image cross-attention at all, silently and without error. Unwrap a list, leave a tensor alone. Matches the handling of encoder_hidden_states two lines above, and the form already used in matrixgame2/causal_model.py and matrixgame2/model.py. Models with image_dim=None (Wan2.2 I2V/TI2V, LingBotWorld) build no image embedder and are unaffected either way.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
Collaborator
Author
|
/merge |
SolitaryThinker
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
WanTransformer3DModel.forward(and the causal/dreamx/lingbotworld variants) unwrappedencoder_hidden_states_imageonly when it was a list, and set it toNoneotherwise — discarding a bare tensor even though the signature acceptstorch.Tensor | list[torch.Tensor] | None.The inference pipelines store
image_embedsas a list (image_encoding.py), so they were unaffected. Every I2V training pipeline passes the CLIP features directly as a tensor (wan_i2v_training_pipeline.py:129,wan_i2v_distillation_pipeline.py:170,self_forcing_distillation_pipeline.py), so those trained with no image cross-attention at all, silently and without error.Models with
image_dim=None(Wan2.2 I2V/TI2V, LingBotWorld) build no image embedder and are unaffected either way.Changes
Unwrap a list, leave a tensor alone. Matches the handling of
encoder_hidden_statestwo lines above, and the form already used inmatrixgame2/causal_model.pyandmatrixgame2/model.py.Touches
wanvideo.py,causal_wanvideo.py(2 sites),dreamx_world.py,lingbotworld/model.py.Test Plan
Wan2.1-I2V-14B-720P, one image, 480x832, 121 frames, 30 steps, guidance 3.0, seed 1000.
The inference stack passes a list, so it never hits the bug. To exercise the training convention end-to-end,
denoising.pywas temporarily patched to hand the DiT a bare tensor — this patch is not part of the PR:Then generate twice on the same node/seed: once with
wanvideo.pyfrommain, once with this branch.Test Results
std= per-video pixel standard deviation (contrast/detail proxy).After the fix, passing a tensor reproduces the untouched list path exactly. Before it, the output is brighter and washed out, degrading over the clip.
Same fix measured through a training-side validation callback (Wan2.1-I2V-14B, stock weights), against ground truth:
Checklist
pre-commit run— all four files live underfastvideo/models/, which the config's globalexcludeskips, so no hooks apply to this diffforward(..., encoder_hidden_states_image=tensor) != forward(..., encoder_hidden_states_image=None)would prevent this from recurring; happy to add if wanted.For model/pipeline changes, also check: