support LongCat-Video#1018
Conversation
Summary of ChangesHello @Artiprocher, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the video generation framework by adding full support for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for the LongCat-Video model, including its architecture, pipeline integration, and example scripts for inference and training. The changes are extensive and well-structured. I've identified a few critical issues in the pipeline integration that could lead to incorrect behavior, particularly with batching and the model's output interpretation. There's also a medium-severity issue regarding unsafe tensor initialization in the model's implementation. After addressing these points, the PR should be in good shape.
| num_cond_latents = longcat_latents.shape[2] | ||
| else: | ||
| num_cond_latents = 0 | ||
| context = context.unsqueeze(0) |
There was a problem hiding this comment.
The use of context.unsqueeze(0) appears to be incorrect and will likely cause issues with batch sizes greater than 1 (e.g., when using classifier-free guidance with cfg_merge=True). It reshapes the context tensor to [1, B, N, C], which will cause a dimension mismatch later in the model's forward pass. It should be context.unsqueeze(1) to correctly shape it to [B, 1, N, C] for batch processing.
| context = context.unsqueeze(0) | |
| context = context.unsqueeze(1) |
| use_gradient_checkpointing=use_gradient_checkpointing, | ||
| use_gradient_checkpointing_offload=use_gradient_checkpointing_offload, | ||
| ) | ||
| output = -output |
There was a problem hiding this comment.
Negating the model's output with output = -output is highly unusual and potentially a critical bug. Standard diffusion models are trained to predict noise or velocity, and negating the output would reverse the diffusion process, leading to incorrect results. If this model was specifically trained to predict the negative of the target, this should be clearly documented with a comment. Otherwise, this line should be removed.
| output = -output | |
| # output = -output |
| if num_cond_latents is not None and num_cond_latents > 0: | ||
| k_full = torch.cat([k_cache, k], dim=2).contiguous() | ||
| v_full = torch.cat([v_cache, v], dim=2).contiguous() | ||
| q_padding = torch.cat([torch.empty_like(k_cache), q], dim=2).contiguous() |
There was a problem hiding this comment.
Using torch.empty_like is unsafe as it creates a tensor with uninitialized memory, which can lead to non-deterministic behavior or NaNs. Please use torch.zeros_like instead for safe and deterministic initialization.
| q_padding = torch.cat([torch.empty_like(k_cache), q], dim=2).contiguous() | |
| q_padding = torch.cat([torch.zeros_like(k_cache), q], dim=2).contiguous() |
support LongCat-Video
No description provided.