README.md 3.77 KB
Newer Older
jerrrrry's avatar
jerrrrry committed
1

jerrrrry's avatar
jerrrrry committed
2
# hunyuan-t2v
jerrrrry's avatar
jerrrrry committed
3

jerrrrry's avatar
jerrrrry committed
4
5
## 项目简介
`hunyuan-t2v` 是一个基于 PyTorch 的视频生成与优化项目,整合了腾讯混元大模型和多种深度学习工具,支持高效视频生成与推理。通过容器化部署和丰富的模型支持,满足复杂环境下的快速开发及测试需求。
jerrrrry's avatar
jerrrrry committed
6

jerrrrry's avatar
jerrrrry committed
7
## 环境部署
jerrrrry's avatar
jerrrrry committed
8

jerrrrry's avatar
jerrrrry committed
9
10
11
### 1. 拉取容器镜像
```bash
docker pull harbor.sourcefind.cn:5443/dcu/admin/base/pytorch:2.5.1-ubuntu22.04-dtk25.04.4-1230-py3.10-20260115
jerrrrry's avatar
jerrrrry committed
12
13
```

jerrrrry's avatar
jerrrrry committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
### 2. 创建并启动 Docker 容器
```bash
docker run -it \
--network=host \
--hostname=localhost \
--name=hunyuan-t2v \
-v /opt/hyhal:/opt/hyhal:ro \
-v $PWD:/workspace \
--ipc=host \
--device=/dev/kfd \
--device=/dev/mkfd \
--device=/dev/dri \
--shm-size=512G \
--privileged \
--group-add video \
--cap-add=SYS_PTRACE \
-u root \
--security-opt seccomp=unconfined \
harbor.sourcefind.cn:5443/dcu/admin/base/pytorch:2.5.1-ubuntu22.04-dtk25.04.4-1230-py3.10-20260115 \
/bin/bash
```
jerrrrry's avatar
jerrrrry committed
35

jerrrrry's avatar
jerrrrry committed
36
---
jerrrrry's avatar
jerrrrry committed
37

jerrrrry's avatar
jerrrrry committed
38
## 测试步骤
jerrrrry's avatar
jerrrrry committed
39

jerrrrry's avatar
jerrrrry committed
40
41
42
43
### 1. 拉取优化后代码仓库
```bash
git clone http://developer.sourcefind.cn/codes/bw-bestperf/hunyuanvideo-t2v.git
cd hunyuanvideo-t2v
jerrrrry's avatar
jerrrrry committed
44
45
```

jerrrrry's avatar
jerrrrry committed
46
47
48
49
50
### 2. 安装依赖
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install yunchang==0.6.0 xfuser==0.4.2
bash fix.sh  # 适配 xfuser
jerrrrry's avatar
jerrrrry committed
51
52
```

jerrrrry's avatar
jerrrrry committed
53
### 3. 下载并准备模型
jerrrrry's avatar
jerrrrry committed
54

jerrrrry's avatar
jerrrrry committed
55
56
57
安装 ModelScope:
```bash
pip install modelscope
jerrrrry's avatar
jerrrrry committed
58
59
```

jerrrrry's avatar
jerrrrry committed
60
61
62
63
下载所需模型:
```bash
# 下载混元视频模型
modelscope download --model Tencent-Hunyuan/HunyuanVideo --local_dir ./ckpts
jerrrrry's avatar
jerrrrry committed
64

jerrrrry's avatar
jerrrrry committed
65
66
# 下载 Llava LLaMA 3 8b 模型
modelscope download --model AI-ModelScope/llava-llama-3-8b-v1_1-transformers --local_dir ./ckpts/llava-llama-3-8b-v1_1-transformers
jerrrrry's avatar
jerrrrry committed
67

jerrrrry's avatar
jerrrrry committed
68
69
70
# 下载 CLIP ViT-Large Patch14
modelscope download --model AI-ModelScope/clip-vit-large-patch14 README.md --local_dir ./ckpts/text_encoder2
```
jerrrrry's avatar
jerrrrry committed
71

jerrrrry's avatar
jerrrrry committed
72
73
74
75
76
`text_encoder` 模型进行转换:
```bash
cd HunyuanVideo
python hyvideo/utils/preprocess_text_encoder_tokenizer_utils.py --input_dir ../ckpts/llava-llama-3-8b-v1_1-transformers --output_dir ../ckpts/text_encoder
```
jerrrrry's avatar
jerrrrry committed
77

jerrrrry's avatar
jerrrrry committed
78
---
jerrrrry's avatar
jerrrrry committed
79

jerrrrry's avatar
jerrrrry committed
80
## 测试示例
jerrrrry's avatar
jerrrrry committed
81

jerrrrry's avatar
jerrrrry committed
82
配置视频参数并运行多卡推理测试:
jerrrrry's avatar
jerrrrry committed
83
84

```bash
jerrrrry's avatar
jerrrrry committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
len=33
step=20

for num in 1 2 4; do
    torchrun --nproc_per_node=${num} sample_video.py \
        --video-size 1280 720 \
        --video-length ${len} \
        --infer-steps ${step} \
        --prompt "A cat walks on the grass, realistic style." \
        --flow-reverse \
        --seed 42 \
        --ulysses-degree ${num} \
        --ring-degree 1 \
        --save-path ./results 2>&1 | tee 1016-video/bw-video-len_${len}-step_${step}-num-${num}.log
done
jerrrrry's avatar
jerrrrry committed
100
101
```

jerrrrry's avatar
jerrrrry committed
102
或者直接使用脚本:
jerrrrry's avatar
jerrrrry committed
103
```bash
jerrrrry's avatar
jerrrrry committed
104
bash run_len33.sh
jerrrrry's avatar
jerrrrry committed
105
106
```

jerrrrry's avatar
jerrrrry committed
107
长视频推理(帧数129):
jerrrrry's avatar
jerrrrry committed
108
```bash
jerrrrry's avatar
jerrrrry committed
109
110
export PYTORCH_NO_HIP_MEMORY_CACHING=1  # 禁用 HIP 缓存 allocator,防止OOM
bash run_len129.sh
jerrrrry's avatar
jerrrrry committed
111
112
```

jerrrrry's avatar
jerrrrry committed
113
---
jerrrrry's avatar
jerrrrry committed
114

jerrrrry's avatar
jerrrrry committed
115
## 配置选项
jerrrrry's avatar
jerrrrry committed
116

jerrrrry's avatar
jerrrrry committed
117
118
119
120
121
122
123
- `--video-size`: 输出视频分辨率,格式为宽 高,如 `1280 720`
- `--video-length`: 生成视频的帧数长度
- `--infer-steps`: 推理步数
- `--prompt`: 文本提示,指导视频生成内容
- `--flow-reverse`: 是否启用流动反转模式
- `--seed`: 随机种子,保证结果复现
- `--save-path`: 输出结果保存路径
jerrrrry's avatar
jerrrrry committed
124

jerrrrry's avatar
jerrrrry committed
125
---
jerrrrry's avatar
jerrrrry committed
126

jerrrrry's avatar
jerrrrry committed
127
## 贡献指南
jerrrrry's avatar
jerrrrry committed
128

jerrrrry's avatar
jerrrrry committed
129
130
欢迎大家参与 `hunyuan-t2v` 的优化与功能扩展!  
请遵循以下步骤:
jerrrrry's avatar
jerrrrry committed
131

jerrrrry's avatar
jerrrrry committed
132
133
134
135
136
1. Fork 本仓库
2. 新建 feature 分支:`git checkout -b feature/your-feature-name`
3. 进行代码修改,并确保通过测试
4. 提交并推送分支:`git push origin feature/your-feature-name`
5. 创建 Pull Request,描述变更内容和目的
jerrrrry's avatar
jerrrrry committed
137

jerrrrry's avatar
jerrrrry committed
138
请确保代码风格统一,功能完整,包含必要测试。
jerrrrry's avatar
jerrrrry committed
139

jerrrrry's avatar
jerrrrry committed
140
---
jerrrrry's avatar
jerrrrry committed
141

jerrrrry's avatar
jerrrrry committed
142
## 许可证
jerrrrry's avatar
jerrrrry committed
143

jerrrrry's avatar
jerrrrry committed
144
本项目遵循 **Apache License 2.0** 许可证。详细请查看 [LICENSE](LICENSE) 文件。
jerrrrry's avatar
jerrrrry committed
145

jerrrrry's avatar
jerrrrry committed
146
---
jerrrrry's avatar
jerrrrry committed
147

jerrrrry's avatar
jerrrrry committed
148
感谢使用与支持 `hunyuan-t2v`
jerrrrry's avatar
jerrrrry committed
149

jerrrrry's avatar
jerrrrry committed
150
151
如有任何问题,请联系维护团队或提交 Issue。
```