feat: add Wan2.2 Animate 2 video models - #5309
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for the Wan2.2-Animate-2-14B and Wan2.2-Animate-2-14B-Distilled character animation models (family WanAnimate2) by introducing a video parameter to the image_to_video endpoint across the RESTful API, async/sync clients, and diffusers model backend. Feedback highlights critical issues: both RESTful clients need to read the video file from disk when a local path string is provided rather than uploading the path string itself; in diffusers.py, fps must be popped from generate_kwargs to prevent a downstream TypeError crash, the temporary file path should be assigned before writing to ensure cleanup on failure, and local file paths should be validated for existence.
| fps = generate_kwargs.get("fps", 24) | ||
| temp_video_path = None | ||
| try: | ||
| if isinstance(video, bytes): | ||
| with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f: | ||
| f.write(video) | ||
| temp_video_path = f.name | ||
| video = temp_video_path | ||
| elif not isinstance(video, str): | ||
| raise TypeError("`video` must be video bytes or a local path") |
There was a problem hiding this comment.
There are three issues in this block:
fpsis retrieved usinggetbut not popped fromgenerate_kwargs. Sincefpsis not a valid parameter for the underlyingWanAnimate2Pipeline.__call__method, leaving it ingenerate_kwargswill cause aTypeErrorcrash.- If
f.write(video)fails,temp_video_pathremainsNone, leaving an orphaned temporary file on disk. Settingtemp_video_pathbefore writing ensures it is cleaned up in thefinallyblock. - If
videois a string path, we should check if the file exists to fail fast with a clear error.
fps = generate_kwargs.pop("fps", 24)
temp_video_path = None
try:
if isinstance(video, bytes):
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
temp_video_path = f.name
f.write(video)
video = temp_video_path
elif isinstance(video, str):
if not os.path.exists(video):
raise FileNotFoundError(f"Driving video path does not exist: {video}")
else:
raise TypeError("`video` must be video bytes or a local path")References
- Avoid adding unused parameters to launch or configuration arguments if they are not directly consumed, as they can leak through
**kwargsinto downstream model construction. Instead, clean up stale or internal fields and overwrite only the required parameters.
7fededb to
e4d594e
Compare
d002764 to
1cdac88
Compare
No description provided.