README.md 5.99 KB
Newer Older
litzh's avatar
litzh 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
# Wan2.1-14B-480P-INT8-Lightx2v

## 项目简介

基于 Lightx2v 组件实现 Wan2.1-14B-480P-INT8 模型推理部署

---

## 环境部署

### 1. 拉取镜像

```bash
docker pull harbor.sourcefind.cn:5443/dcu/admin/base/vllm:0.11.0-ubuntu22.04-dtk25.04.2-1226-das1.7-py3.10-20251226
```

### 2. 创建容器

```bash
docker run -dit \
  --name Wan2_1_Lightx2v \
  --network=host \
  --ipc=host \
  --shm-size=256G \
  --group-add video \
  --cap-add=SYS_PTRACE \
  --device /dev/kfd \
  --device /dev/dri \
  -v /opt/hyhal:/opt/hyhal:ro \
  -v $(pwd):/workspace \
  -w /workspace \
  --privileged \
  -u root \
  --ulimit stack=-1:-1 \
  --ulimit memlock=-1:-1 \
  --security-opt seccomp=unconfined \
  harbor.sourcefind.cn:5443/dcu/admin/base/vllm:0.11.0-ubuntu22.04-dtk25.04.2-1226-das1.7-py3.10-20251226 \
  /bin/bash
```

进入容器
```bash
docker exec -it Wan2_1_Lightx2v bash
```

---

## 测试步骤

### 1. 拉取代码&安装

```bash
git clone http://developer.sourcefind.cn/codes/bw-bestperf/wan2.1-14b-480p-int8-lightx2v.git
cd wan2.1-14b-480p-int8-lightx2v
pip install -v . -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy==1.25.0
```

### 2. 获取&安装定制依赖

```bash
# flash_attn
curl -f -C - -o flash_attn-2.6.1+das.opt1.dtk25044-cp310-cp310-manylinux_2_28_x86_64.whl https://ksefile.hpccube.com:65241/efile/s/d/bGl0emg=/19aeccd37c82cb66  
# torch
curl -f -C - -o torch-2.5.1+das.opt1.dtk25042.20260114.g7b1e7e04-cp310-cp310-manylinux_2_28_x86_64.whl https://ksefile.hpccube.com:65241/efile/s/d/bGl0emg=/a7d181806c7829e1  
# lmslim
curl -f -C - -o lmslim-0.3.1+das.opt2.bc977a7.dtk25042-cp310-cp310-linux_x86_64.whl https://ksefile.hpccube.com:65241/efile/s/d/bGl0emg=/3de9e867ee5f7014  
```

### 3. 下载优化包

```bash
# hipblaslt
curl -f -C - -o hipblaslt.tar.gz https://ksefile.hpccube.com:65241/efile/s/d/bGl0emg=/060c023d2a62ec6f  
# 解压到指定路径
tar -xzvf hipblaslt.tar.gz -C /path/to/hipblaslt
```


### 4. 下载模型

安装 ModelScope

```bash
pip install modelscope
```

下载所需模型

```bash
# Wan2.1 过滤不需要的 dit_fp32 权重
modelscope download --model 'Wan-AI/Wan2.1-I2V-14B-480P' --exclude '*.safetensors' --local_dir 'path/to/models'

# 下载 dit_int8 权重
curl -f -C - -o wan2.1_i2v_480p_int8_lightx2v.safetensors https://ksefile.hpccube.com:65241/efile/s/d/bGl0emg=/ea72503e06c25ddb
# 移动到指定路径
mv wan2.1_i2v_480p_int8_lightx2v.safetensors path/to/models
```

---

## 测试脚本(8卡)

脚本位于 `wan2.1-14b-480p-int8-lightx2v/scripts/platforms/hygon_dcu/run_wan21_i2v_int8.sh`, 注意指定项目路径 `lightx2v_path` 和模型权重文件路径 `model_path`

```bash
#!/bin/bash
# System management interface: hy-smi
export PLATFORM=hygon_dcu

# Set paths
# 项目路径
lightx2v_path=/workspace/wan2.1-14b-480p-int8-lightx2v
# 模型下载路径
model_path=path/to/models

# Set HIP devices for 8 GPUs
export HIP_VISIBLE_DEVICES=0,1,2,4,5,6,7

# Set environment variables
source ${lightx2v_path}/scripts/base/base.sh

torchrun --nproc_per_node=8 -m lightx2v.infer \
--model_cls wan2.1 \
--task i2v \
--model_path $model_path \
--config_json ${lightx2v_path}/configs/platforms/hygon_dcu/wan_i2v_int8.json \
--prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside." \
--negative_prompt "镜头晃动,色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得
不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走" \
--image_path ${lightx2v_path}/assets/inputs/imgs/img_0.jpg \
--save_result_path ${lightx2v_path}/save_results/output_lightx2v_wan_i2v_int8.mp4
```

模型配置文件 `wan2.1-14b-480p-int8-lightx2v/configs/platforms/hygon_dcu/wan_i2v_int8.json`, 注意指定dit_int8模型权重路径 `dit_quantized_ckpt`

```bash
{
    "infer_steps": 40,
    "target_video_length": 81,
    "target_height": 480,
    "target_width": 832,
    "self_attn_1_type": "flash_attn_hygon_dcu",
    "cross_attn_1_type": "flash_attn_hygon_dcu",
    "cross_attn_2_type": "flash_attn_hygon_dcu",
    "sample_guide_scale": 5.0,
    "sample_shift": 5.0,
    "enable_cfg": true,
    "cpu_offload": false,
    "modulate_type": "torch",
    "rope_type": "torch",
    "layer_norm_type": "torch",
    "rms_norm_type": "torch",
    "dit_quantized": true,
    "dit_quant_scheme": "int8-vllm-hygon-dcu",
   "dit_quantized_ckpt": "/path/to/models/wan2.1_i2v_480p_int8_lightx2v.safetensors"
}
```

启动指令

```bash
cd wan2.1-14b-480p-int8-lightx2v
export LD_LIBRARY_PATH=/path/to/hipblaslt/lib/:$LD_LIBRARY_PATH
export USE_SLA=1
export SPARSE_ATTN_TOPK=0.4

bash scripts/platforms/hygon_dcu/run_wan21_i2v_int8.sh
```

---

## 贡献指南

欢迎对 wan2.1-14b-480p-int8-lightx2v 项目进行贡献!请遵循以下步骤:

1. Fork 本仓库,并新建分支进行功能开发或问题修复。
2. 提交规范的 commit 信息,描述清晰。
3. 提交 Pull Request,简述修改内容及目的。
4. 遵守项目代码规范和测试标准。
5. 参与代码评审,积极沟通改进方案。

---

## 许可证

本项目遵循 Apache 2.0 许可证,详见 [LICENSE](./LICENSE) 文件。

---

感谢您的关注与支持!如有问题,欢迎提交 Issue 或联系维护团队。