From d37280e58c1557b1951c6b98dd672cde5c6cf704 Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Wed, 11 Feb 2026 18:00:18 +0530 Subject: [PATCH 1/2] Fix height/width swap and other bugs in dataset utils - 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" --- opensora/datasets/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opensora/datasets/utils.py b/opensora/datasets/utils.py index e580735e0..142ea73b6 100644 --- a/opensora/datasets/utils.py +++ b/opensora/datasets/utils.py @@ -76,7 +76,7 @@ def download_url(input_path): base_name = os.path.basename(input_path) output_path = os.path.join(output_dir, base_name) img_data = requests.get(input_path).content - with open(output_path, "wb", encoding="utf-8") as handler: + with open(output_path, "wb") as handler: handler.write(img_data) print(f"URL {input_path} downloaded to {output_path}") return output_path @@ -266,7 +266,7 @@ def rand_size_crop_arr(pil_image, image_size): # get random start pos h_start = random.randint(0, max(len(arr) - height, 0)) - w_start = random.randint(0, max(len(arr[0]) - height, 0)) + w_start = random.randint(0, max(len(arr[0]) - width, 0)) # crop return Image.fromarray(arr[h_start : h_start + height, w_start : w_start + width]) @@ -356,7 +356,7 @@ def rescale_image_by_path(path: str, height: int, width: int): raise ValueError("The image is invalid or empty.") # resize image - resize_transform = transforms.Resize((width, height)) + resize_transform = transforms.Resize((height, width)) resized_image = resize_transform(image) # save resized image back to the original path @@ -384,7 +384,7 @@ def rescale_video_by_path(path: str, height: int, width: int): raise ValueError("The video is invalid or empty.") # Resize video frames using a performant method - resize_transform = transforms.Compose([transforms.Resize((width, height))]) + resize_transform = transforms.Compose([transforms.Resize((height, width))]) resized_video = torch.stack([resize_transform(frame) for frame in video]) # Save resized video back to the original path From 076cb15fad894d1ae93723aea049946fca30cf5f Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:01:12 +0530 Subject: [PATCH 2/2] Fix swapped height/width dimensions in I2VDenoiser 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. --- opensora/utils/sampling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensora/utils/sampling.py b/opensora/utils/sampling.py index 205940910..df5474822 100644 --- a/opensora/utils/sampling.py +++ b/opensora/utils/sampling.py @@ -183,7 +183,7 @@ def denoise(self, model: MMDiTModel, **kwargs) -> Tensor: t_vec = torch.full( (img.shape[0],), t_curr, dtype=img.dtype, device=img.device ) - b, c, t, w, h = masked_ref.size() + b, c, t, h, w = masked_ref.size() cond = torch.cat((masks, masked_ref), dim=1) cond = pack(cond, patch_size=patch_size) kwargs["cond"] = torch.cat([cond, cond, torch.zeros_like(cond)], dim=0)