README.md 4.3 KB
Newer Older
xuwx1's avatar
xuwx1 committed
1
# 模型转换工具
dcuai's avatar
dcuai committed
2

xuwx1's avatar
xuwx1 committed
3
这是一个功能强大的模型权重转换工具,支持格式转换、量化、LoRA融合等多种功能。
xuwx1's avatar
xuwx1 committed
4
5


xuwx1's avatar
xuwx1 committed
6
## 使用示例
xuwx1's avatar
xuwx1 committed
7

xuwx1's avatar
xuwx1 committed
8
9
### 1. 模型量化
#### 1.1 Wan DiT 量化为 INT8
xuwx1's avatar
xuwx1 committed
10
```bash
xuwx1's avatar
xuwx1 committed
11
12
13
14
15
16
17
18
19
20
21
export PLATFORM=cuda
python converter.py \
    --source /path/to/Wan2.2-I2V-A14B/low_noise_model \
    --output /path/to/Wan2.2-I2V-A14B-INT8/low_noise_model \
    --output_ext .safetensors \
    --output_name Wan2.2-I2V-A14B-INT8 \
    --linear_type int8 \
    --non_linear_dtype torch.bfloat16 \
    --model_type wan_dit \
    --quantized \
    --save_by_block
xuwx1's avatar
xuwx1 committed
22
23
```
```bash
xuwx1's avatar
xuwx1 committed
24
25
26
27
28
29
30
31
32
33
34
export PLATFORM=cuda
python converter.py \
    --source /path/to/Wan2.2-I2V-A14B/high_noise_model \
    --output /path/to/Wan2.2-I2V-A14B-INT8/high_noise_model \
    --output_ext .safetensors \
    --output_name wan_int8 \
    --linear_type torch.int8 \
    --non_linear_dtype torch.bfloat16 \
    --model_type wan_dit \
    --quantized \
    --save_by_block
xuwx1's avatar
xuwx1 committed
35
```
xuwx1's avatar
xuwx1 committed
36
**模型量化完之后需要把Wan2.2-I2V-A14B中除了low_noise_model和high_noise_model以外的文件复制一份到Wan2.2-I2V-A14B-INT8**
xuwx1's avatar
xuwx1 committed
37

xuwx1's avatar
xuwx1 committed
38
39
40
41
42
43
44
45
46
47
48
49
50
#### 1.2 Wan2.1-I2V-14B-480P 量化为 INT8
```bash
export PLATFORM=cuda
python converter.py \
    --source /path/to/Wan2.1-I2V-14B-480P \
    --output /path/to/Wan2.1-I2V-14B-480P-INT8 \
    --output_ext .safetensors \
    --output_name wan_int8 \
    --linear_type int8 \
    --non_linear_dtype torch.bfloat16 \
    --model_type wan_dit \
    --quantized \
    --save_by_block
xuwx1's avatar
xuwx1 committed
51
```
xuwx1's avatar
xuwx1 committed
52
**模型量化完之后需要把Wan2.1-I2V-14B-480P中除了.safetensors以外的文件复制一份到Wan2.1-I2V-14B-480-INT8**
xuwx1's avatar
xuwx1 committed
53

xuwx1's avatar
xuwx1 committed
54
55
56
57
58
59
60
61
62
63
64
65
66
#### 1.2 Wan2.1-I2V-14B-480P 量化为 INT8
```bash
export PLATFORM=cuda
python converter.py \
    --source /path/to/Wan2.2-TI2V-5B \
    --output /path/to/Wan2.2-TI2V-5B-INT8 \
    --output_ext .safetensors \
    --output_name wan_int8 \
    --linear_type int8 \
    --non_linear_dtype torch.bfloat16 \
    --model_type wan_dit \
    --quantized \
    --save_by_block
xuwx1's avatar
xuwx1 committed
67
```
xuwx1's avatar
xuwx1 committed
68
**模型量化完之后需要把Wan2.2-TI2V-5B中除了.safetensors以外的文件复制一份到Wan2.2-TI2V-5B-INT8**
xuwx1's avatar
xuwx1 committed
69
70


xuwx1's avatar
xuwx1 committed
71
72
73
74
75
76
77
78
79
80
81
82
83
### 2. LoRA 融合
#### 2.1 融合单个 LoRA
```bash
python converter.py \
    --source /path/to/base_model/ \
    --output /path/to/output \
    --output_ext .safetensors \
    --output_name merged_model \
    --model_type wan_dit \
    --lora_path /path/to/lora.safetensors \
    --lora_strength 1.0 \
    --single_file
```
xuwx1's avatar
xuwx1 committed
84

xuwx1's avatar
xuwx1 committed
85
86
87
88
89
90
91
92
93
94
95
96
#### 2.2 融合多个 LoRA
```bash
python converter.py \
    --source /path/to/base_model/ \
    --output /path/to/output \
    --output_ext .safetensors \
    --output_name merged_model \
    --model_type wan_dit \
    --lora_path /path/to/lora1.safetensors /path/to/lora2.safetensors \
    --lora_strength 1.0 0.8 \
    --single_file
```
xuwx1's avatar
xuwx1 committed
97

xuwx1's avatar
xuwx1 committed
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
## 核心参数说明
### 基础参数
- `-s, --source`: 输入路径(文件或目录)
- `-o, --output`: 输出目录路径
- `-o_e, --output_ext`: 输出格式,可选 `.pth``.safetensors`(默认)
- `-o_n, --output_name`: 输出文件名(默认: `converted`
- `-t, --model_type`: 模型类型(默认: `wan_dit`

### 量化参数
- `--quantized`: 启用量化
- `--bits`: 量化位宽,当前仅支持 8 位
- `--linear_type`: 线性层量化类型
  - `int8`: INT8 量化
  - `float8_e4m3fn`: FP8 量化
- `--non_linear_dtype`: 非线性层数据类型
  - `torch.bfloat16`: BF16
  - `torch.float16`: FP16
  - `torch.float32`: FP32(默认)
- `--device`: 量化使用的设备,可选 `cpu``cuda`(默认)
- `--comfyui_mode`: ComfyUI 兼容模式
- `--full_quantized`: 全量化模式(ComfyUI 模式下有效)

### LoRA 参数
- `--lora_path`: LoRA 文件路径,支持多个(用空格分隔)
- `--lora_strength`: LoRA 强度系数,支持多个(默认: 1.0)
- `--alpha`: LoRA alpha 参数,支持多个
- `--lora_key_convert`: LoRA 键转换模式
  - `auto`: 自动检测(默认)
  - `same`: 使用原始键名
  - `convert`: 应用与模型相同的转换

### 保存参数
- `--single_file`: 保存为单个文件(注意: 大模型会消耗大量内存)
- `-b, --save_by_block`: 按块保存(推荐用于 backward 转换)
- `-c, --chunk-size`: 分块大小(默认: 100,0 表示不分块)
- `--copy_no_weight_files`: 复制源目录中的非权重文件

### 性能参数
- `--parallel`: 启用并行处理(默认: True)
- `--no-parallel`: 禁用并行处理