README.md 9.37 KB
Newer Older
mashun1's avatar
hyi2v  
mashun1 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# HunyuanVideo-I2V

## 论文

`HunyuanVideo: A Systematic Framework For Large Video Generative Models`

* https://arxiv.org/abs/2412.03603

## 模型结构

模型采用主流`Latent Diffusion`架构,包含用于数据压缩/恢复的`3D VAE`,去噪模块`DiT`,文本使用`CLIP`以及多模态语言模型(MLLM)编码器处理。

![alt text](readme_imgs/arch.png)

## 算法原理

采用Flow matching算法训练模型。

![alt text](readme_imgs/alg.png)

## 环境配置

### Docker(方法一)
    
    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.3.0-ubuntu22.04-dtk24.04.3-py3.10

    docker run --shm-size 100g --network=host --name=hunyuanvideo_i2v --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

    pip install -r requirements.txt

mashun1's avatar
mashun1 committed
31
    pip install distvae yunchang==0.6.0
mashun1's avatar
hyi2v  
mashun1 committed
32

mashun1's avatar
mashun1 committed
33
    pip install "xfuser==0.4.2" --no-deps torch
mashun1's avatar
hyi2v  
mashun1 committed
34
35
36
37
38
39
40
41
42
43
44

    bash modified/fix.sh

### Dockerfile(方法二)

    docker build -t <IMAGE_NAME>:<TAG> .

    docker run --shm-size 100g --network=host --name=hunyuanvideo_i2v --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash
    
    pip install -r requirements.txt

mashun1's avatar
mashun1 committed
45
    pip install distvae yunchang==0.6.0
mashun1's avatar
hyi2v  
mashun1 committed
46

mashun1's avatar
mashun1 committed
47
    pip install "xfuser==0.4.2" --no-deps torch
mashun1's avatar
hyi2v  
mashun1 committed
48
49
50
51
52

    bash modified/fix.sh

### Anaconda(方法三)

chenzk's avatar
chenzk committed
53
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.sourcefind.cn/tool/
mashun1's avatar
hyi2v  
mashun1 committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

```
DTK驱动:dtk24.04.3
python:python3.10
torch:2.3.0
torchvision:0.18.1
torchaudio:2.1.2
triton:2.1.0
flash-attn:2.6.1
deepspeed:0.14.2
apex:1.3.0
xformers:0.0.25
transformers:4.48.0
```

2、其他非特殊库直接按照requirements.txt安装

```
pip install -r requirements.txt

mashun1's avatar
mashun1 committed
74
pip install distvae yunchang==0.6.0
mashun1's avatar
hyi2v  
mashun1 committed
75

mashun1's avatar
mashun1 committed
76
77
78
pip install "xfuser==0.4.2" --no-deps torch

bash modified/fix.sh
mashun1's avatar
hyi2v  
mashun1 committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

# 需要参考 modified/fix.sh中的命令修改相应位置的代码
```

## 数据集



## 训练



## 推理

### 多卡

```bash
torchrun --nproc_per_node=5 sample_image2video.py \
--model HYVideo-T/2 \
--prompt "An Asian man with short hair in black tactical uniform and white clothes waves a firework stick." \
--i2v-mode \
--i2v-image-path ./assets/demo/i2v/imgs/0.jpg \
--i2v-resolution 720p \
--i2v-stability \
--infer-steps 50 \
--video-length 129 \
--flow-reverse \
--flow-shift 7.0 \
--seed 0 \
--embedded-cfg-scale 6.0 \
--save-path ./results \
--ulysses-degree 1 \
--ring-degree 5 \
--video-size 720 720 \
--xdit-adaptive-size
```

参数说明

|     --video-size     | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |
|----------------------|----------------|----------------------------------|------------------|
| 1280 720 or 720 1280 | 129            | 8x1,4x2,2x4,1x8                  | 8                |
| 1280 720 or 720 1280 | 129            | 1x5                              | 5                |
| 1280 720 or 720 1280 | 129            | 4x1,2x2,1x4                      | 4                |
| 1280 720 or 720 1280 | 129            | 3x1,1x3                          | 3                |
| 1280 720 or 720 1280 | 129            | 2x1,1x2                          | 2                |
| 1104 832 or 832 1104 | 129            | 4x1,2x2,1x4                      | 4                |
| 1104 832 or 832 1104 | 129            | 3x1,1x3                          | 3                |
| 1104 832 or 832 1104 | 129            | 2x1,1x2                          | 2                |
| 960 960              | 129            | 6x1,3x2,2x3,1x6                  | 6                |
| 960 960              | 129            | 4x1,2x2,1x4                      | 4                |
| 960 960              | 129            | 3x1,1x3                          | 3                |
| 960 960              | 129            | 1x2,2x1                          | 2                |
| 960 544 or 544 960   | 129            | 6x1,3x2,2x3,1x6                  | 6                |
| 960 544 or 544 960   | 129            | 4x1,2x2,1x4                      | 4                |
| 960 544 or 544 960   | 129            | 3x1,1x3                          | 3                |
| 960 544 or 544 960   | 129            | 1x2,2x1                          | 2                |
| 832 624 or 624 832   | 129            | 4x1,2x2,1x4                      | 4                |
| 624 832 or 624 832   | 129            | 3x1,1x3                          | 3                |
| 832 624 or 624 832   | 129            | 2x1,1x2                          | 2                |
| 720 720              | 129            | 1x5                              | 5                |
| 720 720              | 129            | 3x1,1x3                          | 3                |

### 单卡(不推荐)
```bash
python3 sample_image2video.py \
    --model HYVideo-T/2 \
    --prompt "An Asian man with short hair in black tactical uniform and white clothes waves a firework stick." \
    --i2v-mode \
    --i2v-image-path ./assets/demo/i2v/imgs/0.jpg \
    --i2v-resolution 720p \
    --i2v-stability \
    --infer-steps 50 \
    --video-length 129 \
    --flow-reverse \
    --flow-shift 7.0 \
    --seed 0 \
    --embedded-cfg-scale 6.0 \
    --use-cpu-offload \
    --save-path ./results
```

参数说明:


|        参数        |            默认            |                                                                 描述                                                                 |
|:----------------------:|:-----------------------------:|:----------------------------------------------------------------------------------------------------------------------------------:|
|       `--prompt`       |             None              |                                                            用于视频生成的文本提示。                                                            |
|       `--model`        |      HYVideo-T/2-cfgdistill   |                                    这里我们使用 HYVideo-T/2 用于 I2V,HYVideo-T/2-cfgdistill 用于 T2V 模式。                                     |
|     `--i2v-mode`       |            False              |                                                            是否开启 I2V 模式。                                                            |
|  `--i2v-image-path`    | ./assets/demo/i2v/imgs/0.png  |                                                            用于视频生成的参考图像。                                                            |
|  `--i2v-resolution`    |            720p               |                                                             生成视频的分辨率。                                                              |
|  `--i2v-stability`    |            False             |                                                         是否使用稳定模式进行 i2v 推理。                                                         |
|    `--video-length`    |             129               |                                                              生成视频的长度。                                                              |
|    `--infer-steps`     |              50               |                                                              采样步骤的数量。                                                              |
|     `--flow-shift`     |             7.0               |                        流匹配调度器的偏移因子。我们建议将`--i2v-stability`设置为 7,以获得更稳定的视频;将`--i2v-stability`设置为 17,以获得更动态的视频                         |
|   `--flow-reverse`     |            False              |                                                       如果反转,从 t=1 学习/采样到 t=0。                                                       |
|        `--seed`        |             None              |                                                   生成视频的随机种子,如果为 None,则初始化一个随机种子。                                                   |
|  `--use-cpu-offload`   |            False              |                                                使用 CPU 卸载模型加载以节省更多内存,对于高分辨率视频生成是必要的。                                                |
|     `--save-path`      |         ./results             |                                                             保存生成视频的路径。                                                             |

## result

![](readme_imgs/hy_i2v.gif)

### 精度



## 应用场景

### 算法类别

`视频生成`

### 热点应用行业

`电商,教育,广媒`

## 预训练权重

|model|save_path|链接|
|:---:|:---:|:---:|
chenzk's avatar
chenzk committed
202
203
204
|HunyuanVideo-I2V|ckpts/hunyuan-video-i2v-720p/|[hf](https://hf-mirror.com/tencent/HunyuanVideo-I2V) \| [SCNet]|
|llava-llama-3-8b-v1_1-transformers|ckpts/text_encoder_i2v/|[hf](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers) \| [SCNet] |
|clip-vit-large-patch14 |ckpts/text_encoder_2| [hf](https://huggingface.co/openai/clip-vit-large-patch14) \| [SCNet] |
mashun1's avatar
hyi2v  
mashun1 committed
205
206
207
208
209
210
211
212
213


## 源码仓库及问题反馈

* https://developer.sourcefind.cn/codes/modelzoo/hunyuanvideo-i2v_pytorch

## 参考资料

* https://github.com/Tencent/HunyuanVideo-I2V