GYP666 commited on
Commit
a681892
·
verified ·
1 Parent(s): 1deef16

Create README_zh.md

Browse files
Files changed (1) hide show
  1. README_zh.md +271 -0
README_zh.md ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Video-BLADE: Block-Sparse Attention Meets Step Distillation for Efficient Video Generation
2
+
3
+ <div align="center">
4
+
5
+ [📖 Paper]() | [🚀 Quick Start](#-quick-start) | [💾 Models](https://huggingface.co/GYP666/VIDEO-BLADE)
6
+
7
+ </div>
8
+
9
+ Video-BLADE是一个无需视频数据训练的高效视频生成框架,通过联合训练自适应稀疏注意力和步数蒸馏技术,实现了视频生成模型的显著加速。该项目实现了块稀疏注意力机制与步数蒸馏技术的结合,在保持生成质量的同时将推理步数从50步降低到8步。
10
+
11
+ ## 📢 News
12
+
13
+ - **[2024-08]** 🎉 Video-BLADE代码和预训练模型发布!
14
+ - **[2024-08]** 📝 支持CogVideoX-5B和WanX-1.3B两种主流视频生成模型
15
+ - **[2024-08]** ⚡ 实现8步高质量视频生成,相比50步baseline显著提速
16
+
17
+ ## ✨ 主要特性
18
+
19
+ - 🚀 **高效推理**: 将推理步数从50步减少到8步,保持生成质量
20
+ - 🎯 **自适应稀疏注意力**: 块稀疏注意力机制,显著降低计算复杂度
21
+ - 📈 **步数蒸馏**: TDM(Trajectory Distillation Method)技术,无需视频数据即可训练
22
+ - 🎮 **即插即用**: 支持CogVideoX-5B和WanX-1.3B模型,无需修改原始架构
23
+
24
+ ## 🛠️ 环境配置
25
+
26
+ ### 系统要求
27
+ - Python >= 3.11 (建议)
28
+ - CUDA >= 11.6 (建议)
29
+ - GPU内存 >= 24GB (推理)
30
+ - GPU内存 >= 80GB (训练)
31
+
32
+
33
+ ### 安装步骤
34
+
35
+ 1. **克隆仓库**
36
+ ```bash
37
+ git clone https://github.com/Tacossp/VIDEO-BLADE
38
+ cd VIDEO-BLADE
39
+ ```
40
+
41
+ 2. **安装依赖包**
42
+ ```bash
43
+ # 使用uv安装依赖 (推荐)
44
+ uv pip install -r requirements.txt
45
+
46
+ # 或使用pip
47
+ pip install -r requirements.txt
48
+ ```
49
+
50
+ 3. **编译Block-Sparse-Attention库**
51
+ ```bash
52
+ git clone https://github.com/mit-han-lab/Block-Sparse-Attention.git
53
+ cd Block-Sparse-Attention
54
+ pip install packaging
55
+ pip install ninja
56
+ python setup.py install
57
+ cd ..
58
+ ```
59
+
60
+ ## 📥 模型权重下载
61
+
62
+ ### 基础模型权重
63
+
64
+ 请下载以下基础模型权重并放置在指定目录:
65
+
66
+ 1. **CogVideoX-5B模型**
67
+ ```bash
68
+ # 从Hugging Face下载
69
+ git lfs install
70
+ git clone https://huggingface.co/zai-org/CogVideoX-5b cogvideox/CogVideoX-5b
71
+ ```
72
+
73
+ 2. **WanX-1.3B模型**
74
+ ```bash
75
+ # 从Hugging Face下载
76
+ git clone https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B-Diffusers wanx/wan1.3b
77
+ ```
78
+
79
+ ### 预训练的Video-BLADE权重
80
+
81
+ 我们提供了已经训练好的Video-BLADE权重:
82
+
83
+ ```bash
84
+ # 下载预训练权重
85
+ git clone https://huggingface.co/GYP666/VIDEO-BLADE pretrained_weights
86
+ ```
87
+
88
+ ### 权重目录结构
89
+
90
+ 确保您的权重目录结构如下:
91
+ ```
92
+ VIDEO-BLADE/
93
+ ├── cogvideox/
94
+ │ └── CogVideoX-5b/ # CogVideoX基础模型权重
95
+ ├── wanx/
96
+ │ └── wan1.3b/ # WanX基础模型权重
97
+ └── pretrained_weights/ # Video-BLADE预训练权重
98
+ ├── BLADE_cogvideox_weight/
99
+ └── BLADe_wanx_weight/
100
+ ```
101
+
102
+ ## 🚀 快速开始 - 推理使用
103
+
104
+ ### CogVideoX推理
105
+
106
+ ```bash
107
+ cd cogvideox
108
+ python train/inference.py \
109
+ --lora_path ../pretrained_weights/
110
+ cogvideox_checkpoints/your_checkpoint \
111
+ --gpu 0
112
+ ```
113
+
114
+ **参数说明**:
115
+ - `--lora_path`: LoRA权重文件路径
116
+ - `--gpu`: 使用的GPU设备ID (默认: 0)
117
+
118
+ **输出**: 生成的视频将保存在 `cogvideox/outputs/inference/` 目录
119
+
120
+ ### WanX推理
121
+
122
+ ```bash
123
+ cd wanx
124
+ python train/inference.py \
125
+ --lora_path ../pretrained_weights/wanx_checkpoints/your_checkpoint \
126
+ --gpu 0
127
+ ```
128
+
129
+ **输出**: 生成的视频将保存在 `wanx/outputs/` 目录
130
+
131
+ ## 🔧 训练流程
132
+
133
+ ### 第一步: Prompts预处理
134
+
135
+ 在训练前,需要预处理提示词生成embeddings:
136
+
137
+ #### CogVideoX预处理
138
+ ```bash
139
+ cd utils
140
+ python process_prompts_cogvideox.py \
141
+ --input_file your_prompts.txt \
142
+ --output_dir ../cogvideox/prompts \
143
+ --model_path ../cogvideox/CogVideoX-5b \
144
+ --batch_size 32 \
145
+ --save_separate
146
+ ```
147
+
148
+ **参数说明**:
149
+ - `--input_file`: 包含prompts的txt文件,每行一个prompt
150
+ - `--output_dir`: 输出embeddings的目录
151
+ - `--model_path`: CogVideoX模型路径
152
+ - `--batch_size`: 处理批次大小
153
+ - `--save_separate`: 是否将每个embedding单独保存
154
+
155
+ #### WanX预处理
156
+ ```bash
157
+ cd utils
158
+ python process_prompts_wanx.py
159
+ ```
160
+
161
+ 此脚本会自动处理 `utils/all_dimension_aug_wanx.txt` 中的prompts并生成相应的embeddings。
162
+
163
+ ### 第二步: 启动训练
164
+
165
+ #### CogVideoX训练
166
+
167
+ ```bash
168
+ cd cogvideox
169
+ bash train_tdm_1.sh
170
+ ```
171
+
172
+ **核心训练参数**:
173
+ ```bash
174
+ #如果不是8卡训练需要修改CUDA_VISIBLE_DEVICES和config.yaml的num_processes
175
+ CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7,8 accelerate launch \
176
+ --config_file train/config.yaml \
177
+ train/train_cogvideo_tdm.py \
178
+ --pretrained_model_name_or_path CogVideoX-5b \ # 基础模型路径
179
+ --mixed_precision bf16 \ # 混合精度训练,减少显存使用
180
+ --train_batch_size 5 \ # 训练批次大小
181
+ --gradient_accumulation_steps 4 \ # 梯度累积���数
182
+ --learning_rate 1e-4 \ # student学习率
183
+ --learning_rate_g 1e-4 \
184
+ --learning_rate_fake 5e-4 \ # fake model学习率
185
+ --lambda_reg 0.5 \ # 正则化权重
186
+ --k_step 8 \ # 蒸馏目标步数
187
+ --cfg 3.5 \ # CFG引导强度
188
+ --eta 0.9 \ # ETA参数
189
+ --use_sparsity true \ # 启用稀疏注意力
190
+ --rank 64 \
191
+ --lora_alpha 64 \ # LoRA配置
192
+ --max_train_steps 300 \ # 最大训练步数
193
+ --checkpointing_steps 15 \ # 检查点保存间隔
194
+ --gradient_checkpointing \ # 梯度检查点,节省显存
195
+ --enable_slicing \
196
+ --enable_tiling \ # VAE内存优化
197
+ ```
198
+
199
+ #### WanX训练
200
+
201
+ ```bash
202
+ cd wanx
203
+ bash train_wanx_tdm.sh
204
+ ```
205
+
206
+ ## 📊 项目结构
207
+
208
+ ```
209
+ VIDEO-BLADE/
210
+ ├── README.md # 项目说明文档
211
+ ├── requirements.txt # Python依赖列表
212
+
213
+ ├── cogvideox/ # CogVideoX相关代码
214
+ │ ├── CogVideoX-5b/ # 基础模型权重目录
215
+ │ ├── train/ # 训练脚本
216
+ │ │ ├── inference.py # 推理脚本
217
+ │ │ ├── train_cogvideo_tdm.py # 训练脚本
218
+ │ │ ├── train_tdm_1.sh # 训练启动脚本
219
+ │ │ ├── modify_cogvideo.py # 模型修改脚本
220
+ │ │ └── config.yaml # 训练配置文件
221
+ │ ├── prompts/ # 预处理的prompts和embeddings
222
+ │ └── outputs/ # 训练和推理输出
223
+
224
+ ├── wanx/ # WanX相关代码
225
+ │ ├── wan1.3b/ # 基础模型权重目录
226
+ │ ├── train/ # 训练脚本
227
+ │ │ ├── inference.py # 推理脚本
228
+ │ │ ├── train_wanx_tdm.py # 训练脚本
229
+ │ │ ├── train_wanx_tdm.sh # 训练启动脚本
230
+ │ │ └── modify_wan.py # 模型修改脚本
231
+ │ ├── prompts/ # 预处理的prompts和embeddings
232
+ │ └── outputs/ # 训练和推理输出
233
+
234
+ ├── utils/ # 工具脚本
235
+ │ ├── process_prompts_cogvideox.py # CogVideoX数据预处理
236
+ │ ├── process_prompts_wanx.py # WanX数据预处理
237
+ │ └── all_dimension_aug_wanx.txt # WanX训练prompts
238
+
239
+ ├── Block-Sparse-Attention/ # 稀疏注意力库
240
+ │ ├── setup.py # 编译安装脚本
241
+ │ ├── block_sparse_attn/ # 核心库代码
242
+ │ └── README.md # 库使用说明
243
+
244
+ └── ds_config.json # DeepSpeed配置文件
245
+ ```
246
+
247
+
248
+ ## 🤝 致谢
249
+
250
+ - [FlashAttention](https://github.com/Dao-AILab/flash-attention),[Block-Sparse-Attention](https://github.com/mit-han-lab/Block-Sparse-Attention): 稀疏注意力实现基础
251
+ - [CogVideoX](https://github.com/THUDM/CogVideo),[Wan2.1](https://github.com/Wan-Video/Wan2.1): 模型支持
252
+ - [TDM](https://github.com/Luo-Yihong/TDM):蒸馏实现基础
253
+ - [Diffusers](https://github.com/huggingface/diffusers): 扩散模型工具库
254
+
255
+ ## 📄 引用
256
+
257
+ 如果您在研究中使用了Video-BLADE,请引用我们的工作:
258
+
259
+ ```bibtex
260
+ @article{video-blade-2024,
261
+ title={Video-BLADE: Block-Sparse Attention Meets Step Distillation for Efficient Video Generation},
262
+ author={},
263
+ year={2024}
264
+ }
265
+ ```
266
+
267
+ ## 📧 联系方式
268
+
269
+ 如有问题或建议,欢迎:
270
+ - Please contact Youping Gu ([email protected]) if you have any questions about this work.
271
+ - 提交issue: [Github issue](https://github.com/Tacossp/VIDEO-BLADE/issues)