Views
No views yet
Wan-AI/Wan2.2-I2V-A14BWan-AI/Wan2.2-I2V-A14B model. It reduces model size by 32% compared to the original BFloat16 model, while maintaining bit-identical outputs and supporting efficient GPU inference.Wan-AI/Wan2.2-I2V-A14B can now generate a 5-second 720P video on a single 24GB GPU, while maintaining full model quality. 🔥🔥🔥| Model | Model Size | Peak GPU Memory (5-second 720P generation) | Generation Time (A100 GPU) |
|---|---|---|---|
| Wan-AI/Wan2.2-I2V-A14B (BFloat16) | ~56 GB | O.O.M. | - |
| Wan-AI/Wan2.2-I2V-A14B (DFloat11) | 19.47 + 19.44 GB | 29.12 GB | 42 minutes |
| Wan-AI/Wan2.2-I2V-A14B (DFloat11 + CPU Offloading) | 19.47 + 19.44 GB | 20.01 GB | 44 minutes |
pip install -U dfloat11[cuda12]diffusers package from source:pip install git+https://github.com/huggingface/diffusersi2v.py:1import time
2import torch
3import numpy as np
4import argparse
5from diffusers import WanImageToVideoPipeline
6from diffusers.utils import export_to_video, load_image
7from dfloat11 import DFloat11Model
8
9parser = argparse.ArgumentParser(description='Image to Video generation using Wan2.2-I2V model')
10parser.add_argument('--cpu_offload', action='store_true', help='Enable CPU offloading')
11parser.add_argument('--image_path', type=str, default="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/wan_i2v_input.JPG", help='Path or URL to the input image')
12parser.add_argument('--width', type=int, default=1280, help='Output video width')
13parser.add_argument('--height', type=int, default=720, help='Output video height')
14parser.add_argument('--prompt', type=str, default="Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside.", help='Prompt for video generation')
15parser.add_argument('--negative_prompt', type=str, default="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走", help='Negative prompt for video generation')
16parser.add_argument('--num_frames', type=int, default=81, help='Number of frames to generate')
17parser.add_argument('--guidance_scale', type=float, default=3.5, help='Guidance scale for generation')
18parser.add_argument('--num_inference_steps', type=int, default=40, help='Number of inference steps')
19parser.add_argument('--seed', type=int, default=42, help='Random seed for generation')
20parser.add_argument('--output', type=str, default='i2v_output.mp4', help='Output video path')
21parser.add_argument('--fps', type=int, default=16, help='FPS of output video')
22
23args = parser.parse_args()
24
25image = load_image(args.image_path)
26
27pipe = WanImageToVideoPipeline.from_pretrained("Wan-AI/Wan2.2-I2V-A14B-Diffusers", torch_dtype=torch.bfloat16)
28
29DFloat11Model.from_pretrained(
30 "DFloat11/Wan2.2-I2V-A14B-DF11",
31 device="cpu",
32 cpu_offload=args.cpu_offload,
33 bfloat16_model=pipe.transformer,
34)
35DFloat11Model.from_pretrained(
36 "DFloat11/Wan2.2-I2V-A14B-2-DF11",
37 device="cpu",
38 cpu_offload=args.cpu_offload,
39 bfloat16_model=pipe.transformer_2,
40)
41
42pipe.enable_model_cpu_offload()
43
44max_area = args.width * args.height
45aspect_ratio = image.height / image.width
46mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
47height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
48width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
49image = image.resize((width, height))
50
51generator = torch.Generator(device="cuda").manual_seed(args.seed)
52
53start_time = time.time()
54output = pipe(
55 image=image,
56 prompt=args.prompt,
57 negative_prompt=args.negative_prompt,
58 height=height,
59 width=width,
60 num_frames=args.num_frames,
61 guidance_scale=args.guidance_scale,
62 num_inference_steps=args.num_inference_steps,
63 generator=generator,
64).frames[0]
65print(f"Time taken: {time.time() - start_time:.2f} seconds")
66
67export_to_video(output, args.output, fps=args.fps)
68
69max_memory = torch.cuda.max_memory_allocated()
70print(f"Max memory: {max_memory / (1000 ** 3):.2f} GB")PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True python i2v.pyPYTORCH_CUDA_ALLOC_CONF=expandable_segments:True python i2v.py --cpu_offloadSettingPYTORCH_CUDA_ALLOC_CONF=expandable_segments:Trueis strongly recommended to prevent out-of-memory errors caused by GPU memory fragmentation.