HunyuanVideo: A Systematic Framework For Large Video Generation Model
add docker for xdit and update readme with xdit session (#4)
Jiarui Fang1b2072e1004c
diff --git a/README.md b/README.mdindex 8a5c6ad..48f118c 100644--- a/README.md+++ b/README.md@@ -233,8 +233,6 @@ We list the height/width/frame settings we support in the following table.### Using Command Line-**Single GPU:**-```bashcd HunyuanVideo@@ -248,7 +246,53 @@ python3 sample_video.py \--save-path ./results```-**Multiple GPUs:**+### More Configurations++We list some more useful configurations for easy usage:++| Argument | Default | Description |+|:----------------------:|:---------:|:-----------------------------------------:|+| `--prompt` | None | The text prompt for video generation |+| `--video-size` | 720 1280 | The size of the generated video |+| `--video-length` | 129 | The length of the generated video |+| `--infer-steps` | 50 | The number of steps for sampling |+| `--embedded-cfg-scale` | 6.0 | Embeded Classifier free guidance scale |+| `--flow-shift` | 7.0 | Shift factor for flow matching schedulers |+| `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |+| `--seed` | None | The random seed for generating video, if None, we init a random seed |+| `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |+| `--save-path` | ./results | Path to save the generated video |+++## Parallel Inference on Multiple GPUs by xDiT++[xDiT](https://github.com/xdit-project/xDiT) is a Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters.+It has successfully provide low latency parallel infernece solution for a varitey of DiTs models, including mochi-1, CogVideoX, Flux.1, SD3, etc. This repo adoped the [Unified Sequence Parallelism (USP)](https://arxiv.org/abs/2405.07719) APIs for parallel inference of the HunyuanVideo model.++### Install Dependencies Compatible with xDiT++```+conda env create -f environment.yml++# 2. Activate the environment+conda activate HunyuanVideoxDiT++# 3. Install PyTorch component with CUDA 11.8+conda install pytorch==2.5.0 torchvision==0.20.0 torchaudio==2.5.0 pytorch-cuda=11.8 -c pytorch -c nvidia++# 4. Install pip dependencies+python -m pip install -r requirements_xdit.txt+```++You can skip the above steps and pull the pre-built docker image directly, which is built from [docker/Dockerfile_xDiT](./docker/Dockerfile_xDiT)++```+docker pull thufeifeibear/hunyuanvideo:latest+```++### Usage++For example, to generate a video with 8 GPUs, you can use the following command:```bashcd HunyuanVideo@@ -265,7 +309,10 @@ torchrun --nproc_per_node=8 sample_video.py \--save-path ./results```-parallelization cofigurations+You can change the `--ulysses-degree` and `--ring-degree` to control the parallel configurations for the best performance. The valid parallel configurations are shown in the following table.++<details>+<summary>Supported Parallel Configurations (Click to expand)</summary>| --video-size | --video-length | supported --ulysses-degree x --ring-degree | --nproc-per-node ||--------------|----------------|--------------------------------------------|------------------|@@ -286,22 +333,8 @@ parallelization cofigurations| 832 624 | 129 | 4x1,2x2,1x4 | 4 || 832 624 | 129 | 2x1,1x2 | 2 |-### More Configurations--We list some more useful configurations for easy usage:+</details>-| Argument | Default | Description |-|:----------------------:|:---------:|:-----------------------------------------:|-| `--prompt` | None | The text prompt for video generation |-| `--video-size` | 720 1280 | The size of the generated video |-| `--video-length` | 129 | The length of the generated video |-| `--infer-steps` | 50 | The number of steps for sampling |-| `--embedded-cfg-scale` | 6.0 | Embeded Classifier free guidance scale |-| `--flow-shift` | 7.0 | Shift factor for flow matching schedulers |-| `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |-| `--seed` | None | The random seed for generating video, if None, we init a random seed |-| `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |-| `--save-path` | ./results | Path to save the generated video |## 🔗 BibTeXdiff --git a/docker/Dockerfile_xDiT b/docker/Dockerfile_xDiTnew file mode 100644index 0000000..61c0da3--- /dev/null+++ b/docker/Dockerfile_xDiT@@ -0,0 +1,41 @@+FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04++ENV DEBIAN_FRONTEND=noninteractive++# Install necessary packages+RUN apt-get update && apt-get install -y --no-install-recommends \+ python3 \+ python3-pip \+ python3-dev \+ git \+ wget \+ bzip2 \+ && rm -rf /var/lib/apt/lists/*++# Install Miniconda+RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh \+ && bash /tmp/miniconda.sh -b -p /opt/conda \+ && rm /tmp/miniconda.sh++# Set up environment variables for Conda+ENV PATH="/opt/conda/bin:$PATH"++# Create a new conda environment+RUN conda create -n myenv python=3.10 -y++# Activate the conda environment+SHELL ["/bin/bash", "--login", "-c"]+RUN echo "source activate myenv" > ~/.bashrc+ENV PATH /opt/conda/envs/myenv/bin:$PATH++# Install PyTorch and other dependencies using conda+RUN conda install pytorch==2.5.0 torchvision==0.20.0 torchaudio==2.5.0 pytorch-cuda=11.8 -c pytorch -c nvidia++COPY ./requirements_xdit.txt /tmp/requirements_xdit.txt+RUN pip install --no-cache-dir -r /tmp/requirements_xdit.txt++# Set working directory+WORKDIR /workspace++# Default command+CMD ["/bin/bash"]\ No newline at end of filediff --git a/requirements_xdit.txt b/requirements_xdit.txtnew file mode 100644index 0000000..43d5584--- /dev/null+++ b/requirements_xdit.txt@@ -0,0 +1,16 @@+opencv-python>=4.9.0.80+transformers==4.39.3+tokenizers==0.15.2+accelerate>=1.1.1+pandas==2.0.3+numpy==1.24.4+einops==0.7.0+tqdm==4.66.2+loguru==0.7.2+imageio==2.34.0+imageio-ffmpeg==0.5.1+safetensors==0.4.3+ninja+flash-attn>=2.6.3+xfuser==0.3.6+diffusers>=0.31.0\ No newline at end of filediff --git a/scripts/run_sample_video.sh b/scripts/run_sample_video.shindex 14bc62f..68175a9 100644--- a/scripts/run_sample_video.sh+++ b/scripts/run_sample_video.sh@@ -1,13 +1,42 @@#!/bin/bash# Description: This script demonstrates how to inference a video based on HunyuanVideo model-python3 sample_video.py \- --video-size 720 1280 \- --video-length 129 \- --infer-steps 50 \- --prompt "A cat walks on the grass, realistic style." \- --flow-reverse \- --flow-shift 7.0 \- --seed 0 \- --use-cpu-offload \- --save-path ./results+TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=8 \+ sample_video.py --video-size 1280 720 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=8 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node 4 \+ sample_video.py --video-size 1280 720 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=4 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=2 \+ sample_video.py --video-size 1280 720 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=2 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=1 \+ sample_video.py --video-size 1280 720 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=1 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=6 \+ sample_video.py --video-size 960 960 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=6 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=3 \+ sample_video.py --video-size 960 960 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=3 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=2 \+ sample_video.py --video-size 960 960 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=2 --ring-degree=1 --seed 42 --save-path ./results++TOKENIZERS_PARALLELISM=false torchrun --nproc_per_node=1 \+ sample_video.py --video-size 1280 720 --video-length 129 \+ --infer-steps 50 --prompt "A cat walks on the grass, realistic style." \+ --flow-reverse --ulysses-degree=1 --ring-degree=1 --seed 42 --save-path ./results