quickstart.md 6.48 KB
Newer Older
gushiqiao's avatar
gushiqiao committed
1
# LightX2V 快速入门指南
helloyongyang's avatar
helloyongyang committed
2

gushiqiao's avatar
gushiqiao committed
3
欢迎使用 LightX2V!本指南将帮助您快速搭建环境并开始使用 LightX2V 进行视频生成。
4

gushiqiao's avatar
gushiqiao committed
5
## 📋 目录
6

gushiqiao's avatar
gushiqiao committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
- [系统要求](#系统要求)
- [Linux 系统环境搭建](#linux-系统环境搭建)
  - [Docker 环境(推荐)](#docker-环境推荐)
  - [Conda 环境搭建](#conda-环境搭建)
- [Windows 系统环境搭建](#windows-系统环境搭建)
- [推理使用](#推理使用)

## 🚀 系统要求

- **操作系统**: Linux (Ubuntu 18.04+) 或 Windows 10/11
- **Python**: 3.10 或更高版本
- **GPU**: NVIDIA GPU,支持 CUDA,至少 8GB 显存
- **内存**: 建议 16GB 或更多
- **存储**: 至少 50GB 可用空间

## 🐧 Linux 系统环境搭建

### 🐳 Docker 环境(推荐)

我们强烈推荐使用 Docker 环境,这是最简单快捷的安装方式。

#### 1. 拉取镜像

访问 LightX2V 的 [Docker Hub](https://hub.docker.com/r/lightx2v/lightx2v/tags),选择一个最新日期的 tag,比如 `25061301`

```bash
# 拉取最新版本的 LightX2V 镜像
helloyongyang's avatar
helloyongyang committed
34
docker pull lightx2v/lightx2v:25061301
35
36
```

gushiqiao's avatar
gushiqiao committed
37
38
39
40
41
42
43
44
45
#### 2. 运行容器

```bash
docker run --gpus all -itd --ipc=host --name [容器名] -v [挂载设置] --entrypoint /bin/bash [镜像id]
```

#### 3. 国内镜像源(可选)

对于中国大陆地区,如果拉取镜像时网络不稳定,可以从[渡渡鸟](https://docker.aityp.com/r/docker.io/lightx2v/lightx2v)上拉取:
helloyongyang's avatar
helloyongyang committed
46

gushiqiao's avatar
gushiqiao committed
47
```bash
helloyongyang's avatar
helloyongyang committed
48
49
50
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/lightx2v/lightx2v:25061301
```

gushiqiao's avatar
gushiqiao committed
51
52
53
54
55
56
57
58
59
60
61
62
63
### 🐍 Conda 环境搭建

如果您希望使用 Conda 自行搭建环境,请按照以下步骤操作:

#### 步骤 1: 克隆项目

```bash
# 下载项目代码
git clone https://github.com/ModelTC/LightX2V.git
cd LightX2V
```

#### 步骤 2: 创建 conda 虚拟环境
helloyongyang's avatar
helloyongyang committed
64

gushiqiao's avatar
gushiqiao committed
65
66
67
68
69
```bash
# 创建并激活 conda 环境
conda create -n lightx2v python=3.12 -y
conda activate lightx2v
```
70

gushiqiao's avatar
gushiqiao committed
71
#### 步骤 3: 安装依赖
72

gushiqiao's avatar
gushiqiao committed
73
74
```bash
# 安装基础依赖
75
pip install -r requirements.txt
gushiqiao's avatar
gushiqiao committed
76
77
78
```

> 💡 **提示**: 混元模型需要在 4.45.2 版本的 transformers 下运行,如果您不需要运行混元模型,可以跳过 transformers 版本限制。
79

gushiqiao's avatar
gushiqiao committed
80
#### 步骤 4: 安装注意力机制算子
81

gushiqiao's avatar
gushiqiao committed
82
83
**选项 A: Flash Attention 2**
```bash
helloyongyang's avatar
helloyongyang committed
84
85
git clone https://github.com/Dao-AILab/flash-attention.git --recursive
cd flash-attention && python setup.py install
gushiqiao's avatar
gushiqiao committed
86
```
87

gushiqiao's avatar
gushiqiao committed
88
89
**选项 B: Flash Attention 3(用于 Hopper 架构显卡)**
```bash
helloyongyang's avatar
helloyongyang committed
90
cd flash-attention/hopper && python setup.py install
91
92
```

gushiqiao's avatar
gushiqiao committed
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
**选项 C: SageAttention 2(推荐)**
```bash
git clone https://github.com/thu-ml/SageAttention.git
cd SageAttention && python setup.py install
```

## 🪟 Windows 系统环境搭建

Windows 系统仅支持 Conda 环境搭建方式,请按照以下步骤操作:

### 🐍 Conda 环境搭建

#### 步骤 1: 检查 CUDA 版本

首先确认您的 GPU 驱动和 CUDA 版本:

```cmd
nvidia-smi
```

记录输出中的 **CUDA Version** 信息,后续安装时需要保持版本一致。

#### 步骤 2: 创建 Python 环境

```cmd
# 创建新环境(推荐 Python 3.12)
conda create -n lightx2v python=3.12 -y

# 激活环境
conda activate lightx2v
```

> 💡 **提示**: 建议使用 Python 3.10 或更高版本以获得最佳兼容性。

#### 步骤 3: 安装 PyTorch 框架

**方法一:下载官方 wheel 包(推荐)**

1. 访问 [PyTorch 官方下载页面](https://download.pytorch.org/whl/torch/)
2. 选择对应版本的 wheel 包,注意匹配:
   - **Python 版本**: 与您的环境一致
   - **CUDA 版本**: 与您的 GPU 驱动匹配
   - **平台**: 选择 Windows 版本

**示例(Python 3.12 + PyTorch 2.6 + CUDA 12.4):**

```cmd
# 下载并安装 PyTorch
pip install torch-2.6.0+cu124-cp312-cp312-win_amd64.whl
142

gushiqiao's avatar
gushiqiao committed
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# 安装配套包
pip install torchvision==0.21.0 torchaudio==2.6.0
```

**方法二:使用 pip 直接安装**

```cmd
# CUDA 12.4 版本示例
pip install torch==2.6.0+cu124 torchvision==0.21.0+cu124 torchaudio==2.6.0+cu124 --index-url https://download.pytorch.org/whl/cu124
```

#### 步骤 4: 安装 Windows 版 vLLM

[vllm-windows releases](https://github.com/SystemPanic/vllm-windows/releases) 下载对应的 wheel 包。

**版本匹配要求:**
- Python 版本匹配
- PyTorch 版本匹配
- CUDA 版本匹配

```cmd
# 安装 vLLM(请根据实际文件名调整)
pip install vllm-0.9.1+cu124-cp312-cp312-win_amd64.whl
```

#### 步骤 5: 安装注意力机制算子

**选项 A: Flash Attention 2**

```cmd
pip install flash-attn==2.7.2.post1
```

**选项 B: SageAttention 2(强烈推荐)**

**下载源:**
- [Windows 专用版本 1](https://github.com/woct0rdho/SageAttention/releases)
- [Windows 专用版本 2](https://github.com/sdbds/SageAttention-for-windows/releases)

```cmd
# 安装 SageAttention(请根据实际文件名调整)
pip install sageattention-2.1.1+cu126torch2.6.0-cp312-cp312-win_amd64.whl
```

> ⚠️ **注意**: SageAttention 的 CUDA 版本可以不严格对齐,但 Python 和 PyTorch 版本必须匹配。

#### 步骤 6: 克隆项目

```cmd
# 克隆项目代码
git clone https://github.com/ModelTC/LightX2V.git
cd LightX2V

# 安装 Windows 专用依赖
pip install -r requirements_win.txt
```

## 🎯 推理使用

### 📥 模型准备

在开始推理之前,您需要提前下载好模型文件。我们推荐:

- **下载源**: 从 [LightX2V 官方 Hugging Face](https://huggingface.co/lightx2v/)或者其他开源模型库下载模型
- **存储位置**: 建议将模型存储在 SSD 磁盘上以获得更好的读取性能
- **可用模型**: 包括 Wan2.1-I2V、Wan2.1-T2V 等多种模型,支持不同分辨率和功能

### 📁 配置文件与脚本

推理会用到的配置文件都在[这里](https://github.com/ModelTC/LightX2V/tree/main/configs),脚本都在[这里](https://github.com/ModelTC/LightX2V/tree/main/scripts)

需要将下载的模型路径配置到运行脚本中。除了脚本中的输入参数,`--config_json` 指向的配置文件中也会包含一些必要参数,您可以根据需要自行修改。

### 🚀 开始推理

#### Linux 环境

```bash
# 修改脚本中的路径后运行
helloyongyang's avatar
helloyongyang committed
222
bash scripts/wan/run_wan_t2v.sh
223
224
```

gushiqiao's avatar
gushiqiao committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#### Windows 环境

```cmd
# 使用 Windows 批处理脚本
scripts\win\run_wan_t2v.bat
```

## 📞 获取帮助

如果您在安装或使用过程中遇到问题,请:

1.[GitHub Issues](https://github.com/ModelTC/LightX2V/issues) 中搜索相关问题
2. 提交新的 Issue 描述您的问题

---

🎉 **恭喜!** 现在您已经成功搭建了 LightX2V 环境,可以开始享受视频生成的乐趣了!