Spaces:
Runtime error
Runtime error
myschoolstory
commited on
Commit
·
57d5bb1
1
Parent(s):
0b3ee4f
Update and optimize for CPU.
Browse files- Dockerfile +31 -0
- HARDWARE.md +32 -0
- README.md +29 -0
- app.py +39 -8
- requirements-gpu.txt +3 -0
- requirements.txt +3 -1
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile for MovieGen Demo (CPU-only by default)
|
| 2 |
+
# To enable GPU, use a CUDA base image and install requirements-gpu.txt
|
| 3 |
+
|
| 4 |
+
FROM python:3.12
|
| 5 |
+
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# System dependencies
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
ffmpeg \
|
| 11 |
+
git \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Copy code
|
| 15 |
+
COPY . /app
|
| 16 |
+
|
| 17 |
+
# Install Python dependencies (CPU by default)
|
| 18 |
+
RUN pip install --upgrade pip && \
|
| 19 |
+
pip install -r requirements.txt
|
| 20 |
+
|
| 21 |
+
# Detect if running in a CUDA environment and install GPU dependencies if so
|
| 22 |
+
RUN if python -c "import torch; print(torch.cuda.is_available())" | grep -q True; then \
|
| 23 |
+
pip install -r requirements-gpu.txt; \
|
| 24 |
+
echo 'Installed GPU dependencies.'; \
|
| 25 |
+
else \
|
| 26 |
+
echo 'Running in CPU-only mode.'; \
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
+
EXPOSE 7860
|
| 30 |
+
|
| 31 |
+
CMD ["python", "app.py"]
|
HARDWARE.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hardware Requirements for MovieGen Demo
|
| 2 |
+
|
| 3 |
+
## Minimum Requirements
|
| 4 |
+
- **CPU:** Modern x86_64 CPU (8+ cores recommended)
|
| 5 |
+
- **RAM:** 16 GB (32 GB recommended for larger resolutions)
|
| 6 |
+
- **Disk:** At least 10 GB free space for model checkpoints and cache
|
| 7 |
+
|
| 8 |
+
## Recommended (GPU) Requirements
|
| 9 |
+
- **GPU:** NVIDIA GPU with CUDA support (Ampere or newer recommended)
|
| 10 |
+
- **GPU Memory:** 16 GB VRAM minimum (24 GB+ for high resolutions)
|
| 11 |
+
- **CUDA:** CUDA 11.7+ (if using GPU)
|
| 12 |
+
- **Driver:** Latest NVIDIA driver compatible with your CUDA version
|
| 13 |
+
|
| 14 |
+
## Notes
|
| 15 |
+
- The app can run on CPU, but generation will be much slower compared to GPU.
|
| 16 |
+
- For best performance and high-resolution video generation, a high-end GPU is strongly recommended.
|
| 17 |
+
- Ensure sufficient disk space for temporary video and model files.
|
| 18 |
+
- If running on CPU, expect longer processing times and possible memory limitations for large models or high resolutions.
|
| 19 |
+
|
| 20 |
+
## How to Select Device
|
| 21 |
+
- Use the `--device` argument to select `cpu` or `cuda` (GPU) at launch:
|
| 22 |
+
```bash
|
| 23 |
+
python app.py --device cuda # for GPU
|
| 24 |
+
python app.py --device cpu # for CPU
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
## Troubleshooting
|
| 28 |
+
- If you encounter out-of-memory errors, try reducing the resolution or batch size.
|
| 29 |
+
- If no compatible GPU is found, the app will default to CPU mode.
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
For more details, see the main README or contact the maintainers.
|
README.md
CHANGED
|
@@ -12,3 +12,32 @@ short_description: A demo space for MovieGen1.1.
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
+
|
| 16 |
+
## Hardware Requirements
|
| 17 |
+
See [HARDWARE.md](./HARDWARE.md) for detailed hardware requirements and recommendations for running this app efficiently on CPU or GPU.
|
| 18 |
+
|
| 19 |
+
## Running with Docker
|
| 20 |
+
|
| 21 |
+
You can run this app in a containerized environment using Docker. The provided `Dockerfile` will automatically detect if a GPU is available and install GPU-specific dependencies (like `flash-attn`) if needed.
|
| 22 |
+
|
| 23 |
+
### 1. Build the Docker image
|
| 24 |
+
```bash
|
| 25 |
+
docker build -t moviegen-demo .
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### 2. Run the container
|
| 29 |
+
```bash
|
| 30 |
+
docker run --rm -p 7860:7860 moviegen-demo
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
- The app will be available at http://localhost:7860
|
| 34 |
+
- By default, the container runs in CPU mode. If a compatible GPU is available and Docker is configured for GPU access (e.g., with `--gpus all`), GPU dependencies will be installed and used automatically.
|
| 35 |
+
|
| 36 |
+
#### To run with GPU (if available):
|
| 37 |
+
```bash
|
| 38 |
+
docker run --rm --gpus all -p 7860:7860 moviegen-demo
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
> **Note:**
|
| 42 |
+
> - For GPU support, you must have the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) installed and a CUDA-compatible GPU.
|
| 43 |
+
> - See [HARDWARE.md](./HARDWARE.md) for more details on requirements.
|
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import sys
|
|
| 6 |
import warnings
|
| 7 |
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
|
| 10 |
warnings.filterwarnings('ignore')
|
| 11 |
|
|
@@ -69,10 +70,17 @@ def gradio_interface():
|
|
| 69 |
<div style="text-align: center; font-size: 16px; font-weight: normal; margin-bottom: 20px;">
|
| 70 |
Wan: Open and Advanced Large-Scale Video Generative Models.
|
| 71 |
</div>
|
|
|
|
| 72 |
""")
|
| 73 |
|
| 74 |
with gr.Row():
|
| 75 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
txt2vid_prompt = gr.Textbox(
|
| 77 |
label="Prompt",
|
| 78 |
placeholder="Describe the video you want to generate",
|
|
@@ -135,12 +143,29 @@ def gradio_interface():
|
|
| 135 |
inputs=[txt2vid_prompt, tar_lang],
|
| 136 |
outputs=[txt2vid_prompt])
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
run_t2v_button.click(
|
| 139 |
-
fn=
|
| 140 |
-
inputs=[
|
| 141 |
-
txt2vid_prompt, resolution, sd_steps, guide_scale, shift_scale,
|
| 142 |
-
seed, n_prompt
|
| 143 |
-
],
|
| 144 |
outputs=[result_gallery],
|
| 145 |
)
|
| 146 |
|
|
@@ -167,7 +192,12 @@ def _parse_args():
|
|
| 167 |
type=str,
|
| 168 |
default=None,
|
| 169 |
help="The prompt extend model to use.")
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
args = parser.parse_args()
|
| 172 |
|
| 173 |
return args
|
|
@@ -182,7 +212,7 @@ if __name__ == '__main__':
|
|
| 182 |
model_name=args.prompt_extend_model, is_vl=False)
|
| 183 |
elif args.prompt_extend_method == "local_qwen":
|
| 184 |
prompt_expander = QwenPromptExpander(
|
| 185 |
-
model_name=args.prompt_extend_model, is_vl=False, device=
|
| 186 |
else:
|
| 187 |
raise NotImplementedError(
|
| 188 |
f"Unsupport prompt_extend_method: {args.prompt_extend_method}")
|
|
@@ -193,11 +223,12 @@ if __name__ == '__main__':
|
|
| 193 |
wan_t2v = wan.WanT2V(
|
| 194 |
config=cfg,
|
| 195 |
checkpoint_dir=args.ckpt_dir,
|
| 196 |
-
device_id=0,
|
| 197 |
rank=0,
|
| 198 |
t5_fsdp=False,
|
| 199 |
dit_fsdp=False,
|
| 200 |
use_usp=False,
|
|
|
|
| 201 |
)
|
| 202 |
print("done", flush=True)
|
| 203 |
|
|
|
|
| 6 |
import warnings
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
+
import torch
|
| 10 |
|
| 11 |
warnings.filterwarnings('ignore')
|
| 12 |
|
|
|
|
| 70 |
<div style="text-align: center; font-size: 16px; font-weight: normal; margin-bottom: 20px;">
|
| 71 |
Wan: Open and Advanced Large-Scale Video Generative Models.
|
| 72 |
</div>
|
| 73 |
+
<div style='text-align: center; color: #1976d2; font-size: 18px; margin-bottom: 16px;'><b>Upvote this space if you want faster generations!<br>We are submitting for a GPU grant after 100 upvotes 🚀</b></div>
|
| 74 |
""")
|
| 75 |
|
| 76 |
with gr.Row():
|
| 77 |
with gr.Column():
|
| 78 |
+
device_choice = gr.Radio(
|
| 79 |
+
choices=["cuda", "cpu"],
|
| 80 |
+
value="cuda" if torch.cuda.is_available() else "cpu",
|
| 81 |
+
label="Select Device (GPU or CPU)",
|
| 82 |
+
info="Choose 'cuda' for GPU (faster, if available) or 'cpu' for CPU mode."
|
| 83 |
+
)
|
| 84 |
txt2vid_prompt = gr.Textbox(
|
| 85 |
label="Prompt",
|
| 86 |
placeholder="Describe the video you want to generate",
|
|
|
|
| 143 |
inputs=[txt2vid_prompt, tar_lang],
|
| 144 |
outputs=[txt2vid_prompt])
|
| 145 |
|
| 146 |
+
def run_generation_with_device(device, *args):
|
| 147 |
+
global wan_t2v, prompt_expander
|
| 148 |
+
# Re-initialize models if device changes
|
| 149 |
+
import wan
|
| 150 |
+
from wan.configs import WAN_CONFIGS
|
| 151 |
+
from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander
|
| 152 |
+
cfg = WAN_CONFIGS['t2v-14B']
|
| 153 |
+
prompt_expander = QwenPromptExpander(model_name=None, is_vl=False, device=device)
|
| 154 |
+
wan_t2v = wan.WanT2V(
|
| 155 |
+
config=cfg,
|
| 156 |
+
checkpoint_dir="cache",
|
| 157 |
+
device_id=0 if device == "cuda" else -1,
|
| 158 |
+
rank=0,
|
| 159 |
+
t5_fsdp=False,
|
| 160 |
+
dit_fsdp=False,
|
| 161 |
+
use_usp=False,
|
| 162 |
+
device=device
|
| 163 |
+
)
|
| 164 |
+
return t2v_generation(*args)
|
| 165 |
+
|
| 166 |
run_t2v_button.click(
|
| 167 |
+
fn=run_generation_with_device,
|
| 168 |
+
inputs=[device_choice, txt2vid_prompt, resolution, sd_steps, guide_scale, shift_scale, seed, n_prompt],
|
|
|
|
|
|
|
|
|
|
| 169 |
outputs=[result_gallery],
|
| 170 |
)
|
| 171 |
|
|
|
|
| 192 |
type=str,
|
| 193 |
default=None,
|
| 194 |
help="The prompt extend model to use.")
|
| 195 |
+
parser.add_argument(
|
| 196 |
+
"--device",
|
| 197 |
+
type=str,
|
| 198 |
+
default="cuda" if torch.cuda.is_available() else "cpu",
|
| 199 |
+
choices=["cpu", "cuda"],
|
| 200 |
+
help="Device to run the model on (cpu or cuda). Default: cuda if available, else cpu.")
|
| 201 |
args = parser.parse_args()
|
| 202 |
|
| 203 |
return args
|
|
|
|
| 212 |
model_name=args.prompt_extend_model, is_vl=False)
|
| 213 |
elif args.prompt_extend_method == "local_qwen":
|
| 214 |
prompt_expander = QwenPromptExpander(
|
| 215 |
+
model_name=args.prompt_extend_model, is_vl=False, device=args.device)
|
| 216 |
else:
|
| 217 |
raise NotImplementedError(
|
| 218 |
f"Unsupport prompt_extend_method: {args.prompt_extend_method}")
|
|
|
|
| 223 |
wan_t2v = wan.WanT2V(
|
| 224 |
config=cfg,
|
| 225 |
checkpoint_dir=args.ckpt_dir,
|
| 226 |
+
device_id=0 if args.device == "cuda" else -1,
|
| 227 |
rank=0,
|
| 228 |
t5_fsdp=False,
|
| 229 |
dit_fsdp=False,
|
| 230 |
use_usp=False,
|
| 231 |
+
device=args.device
|
| 232 |
)
|
| 233 |
print("done", flush=True)
|
| 234 |
|
requirements-gpu.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Additional requirements for GPU environments
|
| 2 |
+
# Use this file if you have a CUDA-enabled GPU and want to use flash-attn
|
| 3 |
+
flash_attn
|
requirements.txt
CHANGED
|
@@ -10,7 +10,9 @@ imageio
|
|
| 10 |
easydict
|
| 11 |
ftfy
|
| 12 |
imageio-ffmpeg
|
| 13 |
-
flash_attn
|
|
|
|
|
|
|
| 14 |
gradio>=5.0.0
|
| 15 |
numpy>=1.23.5,<2
|
| 16 |
xfuser
|
|
|
|
| 10 |
easydict
|
| 11 |
ftfy
|
| 12 |
imageio-ffmpeg
|
| 13 |
+
# flash_attn is only needed for GPU environments
|
| 14 |
+
# Use requirements-gpu.txt for GPU installs
|
| 15 |
+
# flash_attn
|
| 16 |
gradio>=5.0.0
|
| 17 |
numpy>=1.23.5,<2
|
| 18 |
xfuser
|