Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from torchao.quantization import quantize_
|
|
| 14 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig
|
| 15 |
from torchao.quantization import Int8WeightOnlyConfig
|
| 16 |
|
| 17 |
-
import aoti
|
| 18 |
|
| 19 |
|
| 20 |
MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
|
|
@@ -32,7 +32,7 @@ MIN_FRAMES_MODEL = 8
|
|
| 32 |
MIN_DURATION = round(MIN_FRAMES_MODEL / FIXED_FPS, 1)
|
| 33 |
DEFAULT_DURATION = 5.0
|
| 34 |
|
| 35 |
-
# Модель загружается с device_map='auto' для распределения больших трансформеров
|
| 36 |
pipe = WanImageToVideoPipeline.from_pretrained(
|
| 37 |
MODEL_ID,
|
| 38 |
transformer=WanTransformer3DModel.from_pretrained(
|
|
@@ -50,6 +50,7 @@ pipe = WanImageToVideoPipeline.from_pretrained(
|
|
| 50 |
torch_dtype=torch.bfloat16,
|
| 51 |
)
|
| 52 |
|
|
|
|
| 53 |
pipe.load_lora_weights(
|
| 54 |
"Kijai/WanVideo_comfy",
|
| 55 |
weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors",
|
|
@@ -67,15 +68,12 @@ pipe.fuse_lora(adapter_names=["lightx2v"], lora_scale=3., components=["transform
|
|
| 67 |
pipe.fuse_lora(adapter_names=["lightx2v_2"], lora_scale=1., components=["transformer_2"])
|
| 68 |
pipe.unload_lora_weights()
|
| 69 |
|
| 70 |
-
# Квантизация
|
| 71 |
quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
|
| 72 |
quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
|
| 73 |
quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
# Эта строка вызывала ошибку 'Cannot copy out of meta tensor'.
|
| 77 |
-
|
| 78 |
-
# AOTI
|
| 79 |
aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 80 |
aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 81 |
|
|
@@ -88,7 +86,7 @@ default_negative_prompt = (
|
|
| 88 |
"静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"
|
| 89 |
)
|
| 90 |
|
| 91 |
-
|
| 92 |
def resize_image(image: Image.Image) -> Image.Image:
|
| 93 |
width, height = image.size
|
| 94 |
|
|
@@ -175,7 +173,9 @@ def generate_video(
|
|
| 175 |
resized_image = resize_image(input_image)
|
| 176 |
|
| 177 |
# При первом вызове pipe() здесь произойдет перемещение всех оставшихся (CPU/quantized)
|
| 178 |
-
# частей модели на GPU.
|
|
|
|
|
|
|
| 179 |
output_frames_list = pipe(
|
| 180 |
image=resized_image,
|
| 181 |
prompt=prompt,
|
|
@@ -187,6 +187,7 @@ def generate_video(
|
|
| 187 |
guidance_scale_2=float(guidance_scale_2),
|
| 188 |
num_inference_steps=int(steps),
|
| 189 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
|
|
|
| 190 |
).frames[0]
|
| 191 |
|
| 192 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
|
@@ -196,7 +197,7 @@ def generate_video(
|
|
| 196 |
return video_path, current_seed
|
| 197 |
|
| 198 |
|
| 199 |
-
# --- Gradio Interface ---
|
| 200 |
with gr.Blocks() as demo:
|
| 201 |
gr.Markdown("# 🚀 Wan 2.2 I2V (14B) — Unlimited Duration Edition 🕒")
|
| 202 |
gr.Markdown("Generate cinematic I2V animations without duration limits. Optimized for 4x NVIDIA L40S.")
|
|
|
|
| 14 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig
|
| 15 |
from torchao.quantization import Int8WeightOnlyConfig
|
| 16 |
|
| 17 |
+
import aoti # Импорт aoti.py
|
| 18 |
|
| 19 |
|
| 20 |
MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
|
|
|
|
| 32 |
MIN_DURATION = round(MIN_FRAMES_MODEL / FIXED_FPS, 1)
|
| 33 |
DEFAULT_DURATION = 5.0
|
| 34 |
|
| 35 |
+
# Модель загружается с device_map='auto' для распределения больших трансформеров
|
| 36 |
pipe = WanImageToVideoPipeline.from_pretrained(
|
| 37 |
MODEL_ID,
|
| 38 |
transformer=WanTransformer3DModel.from_pretrained(
|
|
|
|
| 50 |
torch_dtype=torch.bfloat16,
|
| 51 |
)
|
| 52 |
|
| 53 |
+
# Загрузка и фьюзинг LoRA
|
| 54 |
pipe.load_lora_weights(
|
| 55 |
"Kijai/WanVideo_comfy",
|
| 56 |
weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors",
|
|
|
|
| 68 |
pipe.fuse_lora(adapter_names=["lightx2v_2"], lora_scale=1., components=["transformer_2"])
|
| 69 |
pipe.unload_lora_weights()
|
| 70 |
|
| 71 |
+
# Квантизация
|
| 72 |
quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
|
| 73 |
quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
|
| 74 |
quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
|
| 75 |
|
| 76 |
+
# AOTI
|
|
|
|
|
|
|
|
|
|
| 77 |
aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 78 |
aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 79 |
|
|
|
|
| 86 |
"静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"
|
| 87 |
)
|
| 88 |
|
| 89 |
+
# Функция изменения размера изображения
|
| 90 |
def resize_image(image: Image.Image) -> Image.Image:
|
| 91 |
width, height = image.size
|
| 92 |
|
|
|
|
| 173 |
resized_image = resize_image(input_image)
|
| 174 |
|
| 175 |
# При первом вызове pipe() здесь произойдет перемещение всех оставшихся (CPU/quantized)
|
| 176 |
+
# частей модели на GPU.
|
| 177 |
+
# 🟢 ИСПРАВЛЕНО: Добавлен 'device="cuda"' для создания латентов на GPU,
|
| 178 |
+
# что соответствует генератору 'torch.Generator(device="cuda")'.
|
| 179 |
output_frames_list = pipe(
|
| 180 |
image=resized_image,
|
| 181 |
prompt=prompt,
|
|
|
|
| 187 |
guidance_scale_2=float(guidance_scale_2),
|
| 188 |
num_inference_steps=int(steps),
|
| 189 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 190 |
+
device="cuda", # <--- ИСПРАВЛЕНИЕ: Гарантирует, что латенты создаются на CUDA
|
| 191 |
).frames[0]
|
| 192 |
|
| 193 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
|
|
|
| 197 |
return video_path, current_seed
|
| 198 |
|
| 199 |
|
| 200 |
+
# --- Gradio Interface ---
|
| 201 |
with gr.Blocks() as demo:
|
| 202 |
gr.Markdown("# 🚀 Wan 2.2 I2V (14B) — Unlimited Duration Edition 🕒")
|
| 203 |
gr.Markdown("Generate cinematic I2V animations without duration limits. Optimized for 4x NVIDIA L40S.")
|