From fb6dbad54cdfb5d0b166845dfd76fee44fc775c8 Mon Sep 17 00:00:00 2001 From: Adrian Corduneanu Date: Wed, 26 Feb 2025 02:56:57 -0800 Subject: [PATCH 1/4] Update text2video.py to reduce GPU memory by emptying cache (#44) * Update text2video.py to reduce GPU memory by emptying cache If offload_model is set, empty_cache() must be called after the model is moved to CPU to actually free the GPU. I verified on a RTX 4090 that without calling empty_cache the model remains in memory and the subsequent vae decoding never finishes. * Update text2video.py only one empty_cache needed before vae decode --- wan/text2video.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wan/text2video.py b/wan/text2video.py index 96cfa78..2400545 100644 --- a/wan/text2video.py +++ b/wan/text2video.py @@ -252,6 +252,7 @@ class WanT2V: x0 = latents if offload_model: self.model.cpu() + torch.cuda.empty_cache() if self.rank == 0: videos = self.vae.decode(x0) From 4c503a8bc27b83135c16bb7f8fa7cc8354f64846 Mon Sep 17 00:00:00 2001 From: cocktailpeanut <121128867+cocktailpeanut@users.noreply.github.com> Date: Wed, 26 Feb 2025 05:57:30 -0500 Subject: [PATCH 2/4] os.path.sep instead of / (#12) --- gradio/i2v_14B_singleGPU.py | 3 ++- gradio/t2i_14B_singleGPU.py | 3 ++- gradio/t2v_1.3B_singleGPU.py | 3 ++- gradio/t2v_14B_singleGPU.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gradio/i2v_14B_singleGPU.py b/gradio/i2v_14B_singleGPU.py index 9a22297..100002b 100644 --- a/gradio/i2v_14B_singleGPU.py +++ b/gradio/i2v_14B_singleGPU.py @@ -2,6 +2,7 @@ import argparse import gc import os.path as osp +import os import sys import warnings @@ -10,7 +11,7 @@ import gradio as gr warnings.filterwarnings('ignore') # Model -sys.path.insert(0, '/'.join(osp.realpath(__file__).split('/')[:-2])) +sys.path.insert(0, os.path.sep.join(osp.realpath(__file__).split(os.path.sep)[:-2])) import wan from wan.configs import MAX_AREA_CONFIGS, WAN_CONFIGS from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander diff --git a/gradio/t2i_14B_singleGPU.py b/gradio/t2i_14B_singleGPU.py index f81129a..cb42e38 100644 --- a/gradio/t2i_14B_singleGPU.py +++ b/gradio/t2i_14B_singleGPU.py @@ -1,6 +1,7 @@ # Copyright 2024-2025 The Alibaba Wan Team Authors. All rights reserved. import argparse import os.path as osp +import os import sys import warnings @@ -9,7 +10,7 @@ import gradio as gr warnings.filterwarnings('ignore') # Model -sys.path.insert(0, '/'.join(osp.realpath(__file__).split('/')[:-2])) +sys.path.insert(0, os.path.sep.join(osp.realpath(__file__).split(os.path.sep)[:-2])) import wan from wan.configs import WAN_CONFIGS from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander diff --git a/gradio/t2v_1.3B_singleGPU.py b/gradio/t2v_1.3B_singleGPU.py index 54706b2..87c414e 100644 --- a/gradio/t2v_1.3B_singleGPU.py +++ b/gradio/t2v_1.3B_singleGPU.py @@ -1,6 +1,7 @@ # Copyright 2024-2025 The Alibaba Wan Team Authors. All rights reserved. import argparse import os.path as osp +import os import sys import warnings @@ -9,7 +10,7 @@ import gradio as gr warnings.filterwarnings('ignore') # Model -sys.path.insert(0, '/'.join(osp.realpath(__file__).split('/')[:-2])) +sys.path.insert(0, os.path.sep.join(osp.realpath(__file__).split(os.path.sep)[:-2])) import wan from wan.configs import WAN_CONFIGS from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander diff --git a/gradio/t2v_14B_singleGPU.py b/gradio/t2v_14B_singleGPU.py index b7448ef..a9b7485 100644 --- a/gradio/t2v_14B_singleGPU.py +++ b/gradio/t2v_14B_singleGPU.py @@ -1,6 +1,7 @@ # Copyright 2024-2025 The Alibaba Wan Team Authors. All rights reserved. import argparse import os.path as osp +import os import sys import warnings @@ -9,7 +10,7 @@ import gradio as gr warnings.filterwarnings('ignore') # Model -sys.path.insert(0, '/'.join(osp.realpath(__file__).split('/')[:-2])) +sys.path.insert(0, os.path.sep.join(osp.realpath(__file__).split(os.path.sep)[:-2])) import wan from wan.configs import WAN_CONFIGS from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander From 4169800a95be7e1ea47c882e6d78ee3025faafac Mon Sep 17 00:00:00 2001 From: WanX-Video Date: Wed, 26 Feb 2025 20:33:18 +0800 Subject: [PATCH 3/4] update gradio (#58) --- gradio/t2v_1.3B_singleGPU.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradio/t2v_1.3B_singleGPU.py b/gradio/t2v_1.3B_singleGPU.py index 87c414e..0a752d2 100644 --- a/gradio/t2v_1.3B_singleGPU.py +++ b/gradio/t2v_1.3B_singleGPU.py @@ -46,7 +46,7 @@ def t2v_generation(txt2vid_prompt, resolution, sd_steps, guide_scale, guide_scale=guide_scale, n_prompt=n_prompt, seed=seed, - offload_model=False) + offload_model=True) cache_video( tensor=video[None], From 8d75c013ac1d3b8c3b7fe4eb9c00712e6975b397 Mon Sep 17 00:00:00 2001 From: Yingda Chen Date: Wed, 26 Feb 2025 22:31:12 +0800 Subject: [PATCH 4/4] add modelscope download cli --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5d26fde..8c95c58 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,11 @@ pip install "huggingface_hub[cli]" huggingface-cli download Wan-AI/Wan2.1-T2V-14B --local-dir ./Wan2.1-T2V-14B ``` +Download models using modelscope-cli: +``` +pip install modelscope +modelscope download Wan-AI/Wan2.1-T2V-14B --local_dir ./Wan2.1-T2V-14B +``` #### Run Text-to-Video Generation This repository supports two Text-to-Video models (1.3B and 14B) and two resolutions (480P and 720P). The parameters and configurations for these models are as follows: