-
Notifications
You must be signed in to change notification settings - Fork 6k
[WIP] test prepare_latents for ltx0.95 #10976
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
Conversation
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. |
Co-authored-by: hlky <[email protected]>
condition_latents, rope_interpolation_scale = self._pack_latents( | ||
condition_latents, self.transformer_spatial_patch_size, self.transformer_temporal_patch_size, device | ||
) | ||
|
||
rope_interpolation_scale = ( | ||
rope_interpolation_scale * | ||
torch.tensor([self.vae_temporal_compression_ratio, self.vae_spatial_compression_ratio, self.vae_spatial_compression_ratio], device=rope_interpolation_scale.device)[None, :, None] | ||
) | ||
rope_interpolation_scale[:, 0] = (rope_interpolation_scale[:, 0] + 1 - self.vae_temporal_compression_ratio).clamp(min=0) | ||
rope_interpolation_scale[:, 0] += condition.frame_index | ||
|
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.
I don't think this is compatible with what we do in LTXRotaryPosEmbed layer... We prepare the meshgrid there and only pass the interpolation scales from the pipeline. It seems like here we are preparing the meshgrid beforehand, which will be incorrect. I think we would have to do one of the following:
- Make sure to only pass multiplicative interpolation scale without first multiplying with the latent_coords (the screenshot below shows how I handled it in the other PR)
- If we're passing latent_coords, we will have to handle it differently in the transformer for LTX v0.9.0/v0.9.1 vs v0.9.5
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.
I think we have different ways to handle rope in our current code base, in general, I think it's more convenient/natural to prepare position ids (e.g. the image_ids, text_ids in flux or the grid here for ltx) at same time when we patchify the latents (e.g. pack_latent for ltx or flux). flux and ltx do this in pipeline and other models like lumina handle both together inside transformer with a patch embed
I think it is ok to have this flexibility for rope since it's something that slows us down for each integration. maybe a general rule is to try to follow closer to the original code base and fit it into one of the patterns that's easier for us to maintain.
@@ -864,7 +891,7 @@ def __call__( | |||
frame_rate, | |||
generator, | |||
device, | |||
torch.float32, | |||
prompt_embeds.dtype, |
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.
We could use float32 here and then typecast before sending into transformer, no? That way there won't be a downcast/upcast for CFG
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.
Thanks @yiyixuxu
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.
Thanks so much for taking this up @yiyixuxu! LGTM but I had one doubt
rope_interpolation_scale = [ | ||
# TODO!!! This is incorrect: the frame index needs to added AFTER multiplying the interpolation | ||
# scale with the grid. | ||
(self.vae_temporal_compression_ratio + condition.frame_index) / frame_rate, | ||
self.vae_spatial_compression_ratio, | ||
self.vae_spatial_compression_ratio, | ||
] |
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.
@yiyixuxu Pardon my stupidity, but I can't seem to find if we're handling this + condition.frame_index
part. Is this missing by any chance, or was I mistaken in trying to handle this here?
In the original code, this is what I was meaning to handle: https://github.com/Lightricks/LTX-Video/blob/496dc5058f4408dcb777282f3fb6377fb2da08e6/ltx_video/pipelines/pipeline_ltx_video.py#L1285
* torch.tensor([scale_factor_t, scale_factor, scale_factor], device=video_ids.device)[None, :, None] | ||
) | ||
scaled_latent_coords[:, 0] = (scaled_latent_coords[:, 0] + 1 - scale_factor_t).clamp(min=0) | ||
scaled_latent_coords[:, 0] += frame_index |
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.
@a-r-r-o-w it's here!
Co-authored-by: Aryan <[email protected]>
for #10968