Repeat conditioning images along batch dimension in prepare_latents - #469
Open
prishajain1 wants to merge 1 commit into
Open
Repeat conditioning images along batch dimension in prepare_latents#469prishajain1 wants to merge 1 commit into
prishajain1 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the latent preparation logic in both wan_pipeline_i2v_2p1.py and wan_pipeline_i2v_2p2.py to dynamically repeat the input image and last_image arrays to match the target batch_size. The reviewer correctly identified a potential issue where a non-divisible batch size or an image batch size larger than the target could cause integer division to yield incorrect repeat factors or zero, leading to downstream shape mismatches. Implementing the suggested defensive checks to validate divisibility and raise clear errors will significantly improve the robustness of both pipelines.
csgoogle
approved these changes
Aug 31, 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.
Overview
Fixes an issue in WAN Image-to-Video pipelines (
WanPipelineI2V_2_1andWanPipelineI2V_2_2) where running with a batch size > 1 (such as passing multiple prompts) crashes with:TypeError: Cannot concatenate arrays with shapes that differ in dimensions other than the one being concatenated: concatenating along dimension 4 for shapes (2, 21, 90, 160, 4), (1, 21, 90, 160, 16).Root Cause
mask_lat_sizeis constructed usingbatch_size(e.g., shape(2, 21, 90, 160, 4)).latent_conditionis encoded fromimage, which hadshape[0] == 1because image repetition only occurred whennum_videos_per_prompt > 1, ignoring cases wherebatch_size > 1due to multiple prompts.axis=-1, JAX raised aTypeErrordue to mismatched batch dimensions (2vs1).Changes
prepare_latentsinwan_pipeline_i2v_2p1.pyandwan_pipeline_i2v_2p2.pyto repeatimage(andlast_image) along axis 0 wheneverimage.shape[0] < batch_size.