Conversation
Summary of ChangesHello, 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 addresses a critical time-dimension mismatch in the wan-animate pipeline, which previously led to misaligned conditioning and target frames. By shifting the frame alignment logic upstream and removing a compensatory downstream frame-dropping mechanism, the changes ensure consistency across all inputs. This fix is expected to improve the quality of generated videos, potentially resolving issues like color shifts and discrepancies between initial and subsequent frames. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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 refactors the WanVideoPipeline in diffsynth/pipelines/wan_video.py to improve support for "wan-animate" functionality. Key changes include the removal of the WanVideoUnit_AnimateVideoSplit unit and modifications to WanVideoUnit_NoiseInitializer and WanVideoUnit_InputVideoEmbedder. These units now accept input_image and animate_pose_video parameters, with NoiseInitializer adjusting video length and InputVideoEmbedder preprocessing and prepending the latent representation of a single reference input_image when both are present. Additionally, several example scripts (model_inference, model_inference_low_vram, model_training/validate_full, and model_training/validate_lora) were updated to consistently process 77 frames instead of 81 for various animate_video inputs. Review comments point out the unintended addition of a UTF-8 Byte Order Mark (BOM) character to the import torch line in the example scripts, which should be removed, and suggest defining the number 77 as a variable for improved readability and maintainability.
examples/wanvideo/model_inference_low_vram/Wan2.2-Animate-14B.py
Outdated
Show resolved
Hide resolved
examples/wanvideo/model_training/validate_full/Wan2.2-Animate-14B.py
Outdated
Show resolved
Hide resolved
examples/wanvideo/model_training/validate_lora/Wan2.2-Animate-14B.py
Outdated
Show resolved
Hide resolved
| animate_pose_video = VideoData("data/examples/wan/animate/animate_pose_video.mp4").raw_data()[:77] | ||
| animate_face_video = VideoData("data/examples/wan/animate/animate_face_video.mp4").raw_data()[:77] | ||
| video = pipe( | ||
| prompt="视频中的人在做动作", | ||
| seed=0, tiled=True, | ||
| input_image=input_image, | ||
| animate_pose_video=animate_pose_video, | ||
| animate_face_video=animate_face_video, | ||
| num_frames=81, height=720, width=1280, | ||
| num_frames=77, height=720, width=1280, |
There was a problem hiding this comment.
The number 77 is used in multiple places within this block. To improve readability and maintainability, it's good practice to define it as a variable before this block and reuse it. This avoids 'magic numbers' and makes it easier to change this value in the future. For example:
num_frames_to_process = 77
animate_pose_video = VideoData(...).raw_data()[:num_frames_to_process]
animate_face_video = VideoData(...).raw_data()[:num_frames_to_process]
video = pipe(
...
num_frames=num_frames_to_process,
...
)| animate_pose_video = VideoData("data/examples/wan/animate/animate_pose_video.mp4").raw_data()[:77] | ||
| animate_face_video = VideoData("data/examples/wan/animate/animate_face_video.mp4").raw_data()[:77] | ||
| video = pipe( | ||
| prompt="视频中的人在做动作", | ||
| seed=0, tiled=True, | ||
| input_image=input_image, | ||
| animate_pose_video=animate_pose_video, | ||
| animate_face_video=animate_face_video, | ||
| num_frames=81, height=720, width=1280, | ||
| num_frames=77, height=720, width=1280, |
There was a problem hiding this comment.
The number 77 is used in multiple places within this block. To improve readability and maintainability, it's good practice to define it as a variable before this block and reuse it. This avoids 'magic numbers' and makes it easier to change this value in the future. For example:
num_frames_to_process = 77
animate_pose_video = VideoData(...).raw_data()[:num_frames_to_process]
animate_face_video = VideoData(...).raw_data()[:num_frames_to_process]
video = pipe(
...
num_frames=num_frames_to_process,
...
)| animate_pose_video = VideoData("data/examples/wan/animate/animate_pose_video.mp4", height=480, width=832).raw_data()[:77] | ||
| animate_face_video = VideoData("data/examples/wan/animate/animate_face_video.mp4", height=512, width=512).raw_data()[:77] | ||
| video = pipe( | ||
| prompt="视频中的人在做动作", | ||
| seed=0, tiled=True, | ||
| input_image=input_image, | ||
| animate_pose_video=animate_pose_video, | ||
| animate_face_video=animate_face_video, | ||
| num_frames=81, height=480, width=832, | ||
| num_frames=77, height=480, width=832, |
There was a problem hiding this comment.
The number 77 is used in multiple places within this block. To improve readability and maintainability, it's good practice to define it as a variable before this block and reuse it. This avoids 'magic numbers' and makes it easier to change this value in the future. For example:
num_frames_to_process = 77
animate_pose_video = VideoData(...).raw_data()[:num_frames_to_process]
animate_face_video = VideoData(...).raw_data()[:num_frames_to_process]
video = pipe(
...
num_frames=num_frames_to_process,
...
)| animate_pose_video = VideoData("data/examples/wan/animate/animate_pose_video.mp4", height=480, width=832).raw_data()[:77] | ||
| animate_face_video = VideoData("data/examples/wan/animate/animate_face_video.mp4", height=512, width=512).raw_data()[:77] | ||
| video = pipe( | ||
| prompt="视频中的人在做动作", | ||
| seed=0, tiled=True, | ||
| input_image=input_image, | ||
| animate_pose_video=animate_pose_video, | ||
| animate_face_video=animate_face_video, | ||
| num_frames=81, height=480, width=832, | ||
| num_frames=77, height=480, width=832, |
There was a problem hiding this comment.
The number 77 is used in multiple places within this block. To improve readability and maintainability, it's good practice to define it as a variable before this block and reuse it. This avoids 'magic numbers' and makes it easier to change this value in the future. For example:
num_frames_to_process = 77
animate_pose_video = VideoData(...).raw_data()[:num_frames_to_process]
animate_face_video = VideoData(...).raw_data()[:num_frames_to_process]
video = pipe(
...
num_frames=num_frames_to_process,
...
)Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…14B.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…14B.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
What changed
diffsynth/pipelines/wan_video.pyWanVideoUnit_NoiseInitializer: add +1 time step when input_image & animate_pose_video are presentWanVideoUnit_InputVideoEmbedder: prepend input_image latent for wan-animateWanVideoUnit_AnimateVideoSplitfrom the pipelineexamples/wanvideo/model_training/validate_lora/Wan2.2-Animate-14B.pyexamples/wanvideo/model_training/validate_full/Wan2.2-Animate-14B.pyexamples/wanvideo/model_inference/Wan2.2-Animate-14B.pyexamples/wanvideo/model_inference_low_vram/Wan2.2-Animate-14B.pynum_framesto 77 and slice inputs as[:77]Rationale / Issue
Fixes the time-dimension mismatch discussed in #1027. The prior
drop last 4 framesbehavior is a downstream patch; it avoids shape errors but leaves conditioning and target frames misaligned. This change aligns the reference frame and latents upstream so all inputs and targets are consistent.Related Issues