Wan example doesn't produce expected results
Hi, thanks for the fantastic work! I'm trying to replicate the results in the paper and the quantized video I'm getting is of poor quality.
When I run the inference script without the --quant option I get a video with quality represented by this picture
When I add back the --quant flag, I get a video looking like this
Just in case, I tried to disable the --fix flag, which seems to improve results slightly
I downloaded the pre-quantized Wan model you provided and the script I use is pretty much unchanged from the original, although it's worth noting I need to offload the text encoder to fit the process into my VRAM, which I do with these 2 patches:
- pipe = WanPipeline.from_pretrained(model_path, torch_dtype=dtype, vae=vae)
+
+
+ from transformers import UMT5EncoderModel
+
+ text_encoder = UMT5EncoderModel.from_pretrained(
+ model_path,
+ subfolder="text_encoder",
+ device_map="cuda",
+ torch_dtype=dtype
+ )
+ pipe = WanPipeline.from_pretrained(
+ model_path,
+ torch_dtype=dtype,
+ text_encoder=text_encoder,
+ transformer=None,
+ vae=None,
+ device_map="balanced"
+ )
+
+ with torch.no_grad():
+ prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
+ 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"
+ prompt_embeds, negative_embeds = pipe.encode_prompt(prompt=prompt, negative_prompt=negative_prompt)
+
+ import gc
+
+ def flush():
+ gc.collect()
+ torch.cuda.empty_cache()
+
+ del text_encoder
+ del pipe
+ flush()
+
+ pipe = WanPipeline.from_pretrained(
+ model_path,
+ torch_dtype=dtype,
+ text_encoder=None,
+ vae=vae
+ )
+
and
video_generate = pipe(
height=height,
width=width,
- prompt=prompt,
+
+ # prompt=prompt,
+ prompt_embeds=prompt_embeds,
+ negative_prompt_embeds=negative_embeds,
+
num_videos_per_prompt=1,
num_inference_steps=num_inference_steps,
num_frames=num_frames,
# use_dynamic_cfg=True,
guidance_scale=guidance_scale,
).frames[0]
This is on Linux with a fresh conda virtual environment, I'm happy to provide any further environment info if it helps to identify the issue.
Any help identifying the issue would be immensely helpful, many thanks in advance!
Hi, I have tried the prompts you prepared. I modified inference/wan.py as follows (compared with the latest main branch):
@@ -209,6 +209,19 @@ def generate_video(
# turn off if you have multiple GPUs or enough GPU memory(such as H100) and it will cost less time in inference
# and enable to("cuda")
pipe.to("cuda")
+ from transformers import UMT5EncoderModel
+
+ text_encoder = UMT5EncoderModel.from_pretrained(
+ model_path,
+ subfolder="text_encoder",
+ device_map="cuda",
+ torch_dtype=dtype
+ )
+
+ with torch.no_grad():
+ prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
+ 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"
+ prompt_embeds, negative_embeds = pipe.encode_prompt(prompt=prompt, negative_prompt=negative_prompt)
# pipe.enable_model_cpu_offload()
# pipe.enable_sequential_cpu_offload()
@@ -241,7 +254,9 @@ def generate_video(
video_generate = pipe(
height=height,
width=width,
- prompt=prompt,
+ # prompt=prompt,
+ prompt_embeds=prompt_embeds,
+ negative_prompt_embeds=negative_embeds,
num_videos_per_prompt=1,
num_inference_steps=num_inference_steps,
num_frames=num_frames,
Next, I used the provided script: script/inference/wan_1-3b.sh (only change the output_path and quant_model_path), and the quantized model and original model downloaded from Huggingface. Finally, I got the following results:
with --quant
https://github.com/user-attachments/assets/e4fe1010-f351-45f9-bbc7-5250e0de63a9
without --quant
https://github.com/user-attachments/assets/20215a51-249d-4e7b-806d-d64f47b209e1
I used a single H100 GPU with the environment provided in requirements.txt. Moreover, the cuda version is 12.4 and the python version is 3.10.12.
I hope this information could help you to reproduce our results.
PS: By the way, I believe the prompt you used is too complicated for a 1.3B model, and we will release the 14B quantized model later.
Thanks for the quick response! Confirming I was able to replicate the high quality result on an H100. I'll investigate why I'm getting a different outcome on my RTX 4080 and will follow up with a comment on this thread.
P.S. Thanks for the note on the prompt, it's the default one off of hugging face, but duly noted!
I've identified the issue - it's varying the num_frames parameter. Keeping to the original state of the repository, running on an H100, and just changing that value in the provided script produces these results:
17 frame inference https://github.com/user-attachments/assets/96f9164a-2645-44cd-90f6-5de6051e89e6
29 frame inference https://github.com/user-attachments/assets/55dd0358-fede-4933-ab1e-042c8ffbbc23
41 frame inference https://github.com/user-attachments/assets/a1b4f443-795c-4cbb-82d1-c97e5560b48f
77 frame inference https://github.com/user-attachments/assets/0da14923-6a50-4eff-8d27-a63d1312c059
Is this expected? If so, is the idea to quantize for the specific number of frames in the target application?
It is better to keep training and inference aligned. However, I am not sure whether such a huge gap is incurred by quantization or not, and I think you can try to cancel --quant to test the original model.
In the training, I set frame_num to 49 and 81 (the default value for Wan) for the inference. I find it works well, which shows the generalization ability.
Fantastic, thanks for the quick reply! Doing 17-frame inference without quant produces results of comparable quality to the default model without quantization. I'll investigate training on shorter snippets of video to alleviate the issue.