-
Notifications
You must be signed in to change notification settings - Fork 6k
fix wan i2v pipeline bugs #10975
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
Merged
Merged
fix wan i2v pipeline bugs #10975
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
465e12e
fix wan i2v pipeline bugs
yupeng1111 4670287
update t2v example
yupeng1111 efbdd34
Apply style fixes
github-actions[bot] a40b127
Merge branch 'main' into fix_wan_i2v
yiyixuxu 86f94d6
Merge branch 'main' into fix_wan_i2v
yupeng1111 9bfacc4
Apply suggestions from code review
yiyixuxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
import PIL | ||
import regex as re | ||
import torch | ||
from transformers import AutoTokenizer, CLIPImageProcessor, CLIPVisionModelWithProjection, UMT5EncoderModel | ||
from transformers import AutoTokenizer, CLIPImageProcessor, CLIPVisionModel, UMT5EncoderModel | ||
|
||
from ...callbacks import MultiPipelineCallbacks, PipelineCallback | ||
from ...image_processor import PipelineImageInput | ||
|
@@ -46,29 +46,47 @@ | |
Examples: | ||
```python | ||
>>> import torch | ||
>>> import numpy as np | ||
>>> from diffusers import AutoencoderKLWan, WanImageToVideoPipeline | ||
>>> from diffusers.utils import export_to_video, load_image | ||
>>> from transformers import CLIPVisionModel | ||
|
||
>>> # Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-1.3B-720P-Diffusers | ||
>>> # Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers | ||
>>> model_id = "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers" | ||
>>> image_encoder = CLIPVisionModel.from_pretrained( | ||
... model_id, subfolder="image_encoder", torch_dtype=torch.float32 | ||
... ) | ||
>>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32) | ||
>>> pipe = WanImageToVideoPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16) | ||
>>> pipe = WanImageToVideoPipeline.from_pretrained( | ||
... model_id, vae=vae, image_encoder=image_encoder, torch_dtype=torch.bfloat16 | ||
... ) | ||
>>> pipe.to("cuda") | ||
|
||
>>> height, width = 480, 832 | ||
>>> image = load_image( | ||
... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg" | ||
... ).resize((width, height)) | ||
... ) | ||
>>> max_area = 480 * 832 | ||
>>> aspect_ratio = image.height / image.width | ||
>>> mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] | ||
>>> height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value | ||
>>> width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value | ||
>>> image = image.resize((width, height)) | ||
>>> prompt = ( | ||
... "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in " | ||
... "the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot." | ||
... ) | ||
>>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards" | ||
|
||
>>> output = pipe( | ||
... image=image, prompt=prompt, negative_prompt=negative_prompt, num_frames=81, guidance_scale=5.0 | ||
... image=image, | ||
... prompt=prompt, | ||
... negative_prompt=negative_prompt, | ||
... height=height, | ||
... width=width, | ||
... num_frames=81, | ||
... guidance_scale=5.0, | ||
... ).frames[0] | ||
>>> export_to_video(output, "output.mp4", fps=15) | ||
>>> export_to_video(output, "output.mp4", fps=16) | ||
``` | ||
""" | ||
|
||
|
@@ -137,7 +155,7 @@ def __init__( | |
self, | ||
tokenizer: AutoTokenizer, | ||
text_encoder: UMT5EncoderModel, | ||
image_encoder: CLIPVisionModelWithProjection, | ||
image_encoder: CLIPVisionModel, | ||
image_processor: CLIPImageProcessor, | ||
transformer: WanTransformer3DModel, | ||
vae: AutoencoderKLWan, | ||
|
@@ -204,7 +222,7 @@ def _get_t5_prompt_embeds( | |
def encode_image(self, image: PipelineImageInput): | ||
image = self.image_processor(images=image, return_tensors="pt").to(self.device) | ||
image_embeds = self.image_encoder(**image, output_hidden_states=True) | ||
return image_embeds.hidden_states[-1] | ||
return image_embeds.hidden_states[-2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @a-r-r-o-w the change of output is probably from here |
||
|
||
# Copied from diffusers.pipelines.wan.pipeline_wan.WanPipeline.encode_prompt | ||
def encode_prompt( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
need to match with here https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-480P-Diffusers/blob/main/model_index.json#L6