Fix swapped height/width dimensions in I2VDenoiser#911
Open
Mr-Neutr0n wants to merge 2 commits intohpcaitech:mainfrom
Open
Fix swapped height/width dimensions in I2VDenoiser#911Mr-Neutr0n wants to merge 2 commits intohpcaitech:mainfrom
Mr-Neutr0n wants to merge 2 commits intohpcaitech:mainfrom
Conversation
- Fix rescale_image_by_path and rescale_video_by_path passing (width, height) to transforms.Resize(), which expects (height, width) - Fix rand_size_crop_arr using height instead of width for w_start boundary - Fix download_url passing encoding="utf-8" to binary write mode "wb"
In `I2VDenoiser.denoise()`, the `masked_ref` tensor dimensions were unpacked as `(b, c, t, w, h)` instead of the correct `(b, c, t, h, w)`. The standard PyTorch video tensor layout is (B, C, T, H, W), and this is confirmed by `prepare_inference_condition()` in inference.py which constructs masked_ref using `B, C, T, H, W = z.shape`. The swapped variables cause the `image_gs` guidance scale tensor to be constructed with incorrect spatial dimensions when `scale_temporal_osci` is enabled, since `.repeat(b, c, 1, h, w)` would receive the wrong values for h and w. This leads to a shape mismatch (and runtime error) or silently incorrect guidance scaling for non-square video resolutions.
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.
Summary
I2VDenoiser.denoise()wheremasked_ref.size()was incorrectly unpacked as(b, c, t, w, h)instead of(b, c, t, h, w)(B, C, T, H, W), matching howmasked_refis constructed inprepare_inference_condition()(B, C, T, H, W = z.shape)image_gsguidance scale tensor (built via.repeat(b, c, 1, h, w)) to have incorrect spatial dimensions whenscale_temporal_osciis enabled, leading to wrong guidance scaling or shape errors for non-square video resolutionsDetails
In
opensora/utils/sampling.py, line 186:The
handwvariables are used downstream in the temporal oscillation scaling branch:With the old code, for a non-square video (e.g., 720x480 latent),
hwould hold the width value andwthe height value, producing animage_gstensor with swapped spatial dimensions that cannot correctly broadcast againstcond,uncond, anduncond_2in the guidance computation.Test plan
prepare_inference_condition()ininference.pycreates tensors with(B, C, T, H, W)layouthandwscale_temporal_osci=Trueto verify correct guidance scaling