-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix in LTXImageToVideoPipeline.prepare_latents() when latents is already set #10918
base: main
Are you sure you want to change the base?
Conversation
I don't think there's a mistake with handling latents here. When user calls prepare_latents with their own latents, it is assumed to already be "prepared" (in this case, packed into ndim=3 tensor) and the only operation we wish to perform on the latent is device and dtype casting. Regarding the mask shape, I believe that might be an actual mistake. Could you try running inference with only the mask_shape related change and passing ndim=3 latent? |
This case also fails. Since the packed latents is of shape
becomes equal to num_channel, which shouldn't be expected. The following is the result, where
"""Code snippet to see the error
"""
import torch
from diffusers import LTXImageToVideoPipeline
device = "cuda:0"
# instantiate a pipeline
pipe = LTXImageToVideoPipeline.from_pretrained(
"a-r-r-o-w/LTX-Video-0.9.1-diffusers",
torch_dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload(device=device)
# create a dummy latents tensor
num_frames = 49
height = 352
width = 640
latent_num_frames = (num_frames - 1) // pipe.vae_temporal_compression_ratio + 1
latent_height = height // pipe.vae_spatial_compression_ratio
latent_width = width // pipe.vae_spatial_compression_ratio
latents = torch.randn((1, 128, latent_num_frames, latent_height, latent_width), device=device)
latents = pipe._pack_latents(latents, pipe.transformer_spatial_patch_size, pipe.transformer_temporal_patch_size)
# run
pipe(
height=height,
width=width,
num_frames=num_frames,
prompt="test_test",
latents=latents,
)
|
Ohh okay, I see! nice catch 🔥 cc @yiyixuxu What do we want to do here? Accept fully prepared latents from the user (ndim=3) and do a fix for that, or accept ndim=5 tensor and prepare it |
I think it should be fully prepared latents (output of prepare_latents) and do a fix for that |
Fixed. We can check the validity using the same code snippet above. |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
||
shape = (batch_size, num_channels_latents, num_frames, height, width) | ||
mask_shape = (batch_size, 1, num_frames, height, width) | ||
|
||
if latents is not None: | ||
conditioning_mask = latents.new_zeros(shape) | ||
conditioning_mask = latents.new_zeros(mask_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normal route of prepare_latents()
outputs conditioning_mask
with that shape, so it is natural to align with it (here).
What does this PR do?
A small bug is in LTXImageToVideoPipeline.prepare_latents() when
latents
is already set.latents
assumes five-dimensional input(batch, channel, num_frames, height, width)
as we can see from the lineHowever, when
latents
is set in the argument, the code skips applyingself._pack_latents()
.Also, the shape of
conditioning_mask
is wrong.This PR addresses these two issues.
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.