Upload lora-scripts/svd_merge.ps1 with huggingface_hub
Browse files- lora-scripts/svd_merge.ps1 +43 -43
lora-scripts/svd_merge.ps1
CHANGED
@@ -1,43 +1,43 @@
|
|
1 |
-
# LoRA svd_merge script by @bdsqlsz
|
2 |
-
|
3 |
-
$save_precision = "fp16" # precision in saving, default float | 保存精度, 可选 float、fp16、bf16, 默认 和源文件相同
|
4 |
-
$precision = "float" # precision in merging (float is recommended) | 合并时计算精度, 可选 float、fp16、bf16, 推荐float
|
5 |
-
$new_rank = 4 # dim rank of output LoRA | dim rank等级, 默认 4
|
6 |
-
$models = "./output/modelA.safetensors ./output/modelB.safetensors" # original LoRA model path need to resize, save as cpkt or safetensors | 需要合并的模型路径, 保存格式 cpkt 或 safetensors,多个用空格隔开
|
7 |
-
$ratios = "1.0 -1.0" # ratios for each model / LoRA模型合并比例,数量等于模型数量,多个用空格隔开
|
8 |
-
$save_to = "./output/lora_name_new.safetensors" # output LoRA model path, save as ckpt or safetensors | 输出路径, 保存格式 cpkt 或 safetensors
|
9 |
-
$device = "cuda" # device to use, cuda for GPU | 使用 GPU跑, 默认 CPU
|
10 |
-
$new_conv_rank = 0 # Specify rank of output LoRA for Conv2d 3x3, None for same as new_rank | Conv2d 3x3输出,没有默认同new_rank
|
11 |
-
|
12 |
-
# Activate python venv
|
13 |
-
.\venv\Scripts\activate
|
14 |
-
|
15 |
-
$Env:HF_HOME = "huggingface"
|
16 |
-
$Env:XFORMERS_FORCE_DISABLE_TRITON = "1"
|
17 |
-
$ext_args = [System.Collections.ArrayList]::new()
|
18 |
-
|
19 |
-
[void]$ext_args.Add("--models")
|
20 |
-
foreach ($model in $models.Split(" ")) {
|
21 |
-
[void]$ext_args.Add($model)
|
22 |
-
}
|
23 |
-
|
24 |
-
[void]$ext_args.Add("--ratios")
|
25 |
-
foreach ($ratio in $ratios.Split(" ")) {
|
26 |
-
[void]$ext_args.Add([float]$ratio)
|
27 |
-
}
|
28 |
-
|
29 |
-
if ($new_conv_rank) {
|
30 |
-
[void]$ext_args.Add("--new_conv_rank=" + $new_conv_rank)
|
31 |
-
}
|
32 |
-
|
33 |
-
# run svd_merge
|
34 |
-
accelerate launch --num_cpu_threads_per_process=8 "./
|
35 |
-
--save_precision=$save_precision `
|
36 |
-
--precision=$precision `
|
37 |
-
--new_rank=$new_rank `
|
38 |
-
--save_to=$save_to `
|
39 |
-
--device=$device `
|
40 |
-
$ext_args
|
41 |
-
|
42 |
-
Write-Output "SVD Merge finished"
|
43 |
-
Read-Host | Out-Null ;
|
|
|
1 |
+
# LoRA svd_merge script by @bdsqlsz
|
2 |
+
|
3 |
+
$save_precision = "fp16" # precision in saving, default float | 保存精度, 可选 float、fp16、bf16, 默认 和源文件相同
|
4 |
+
$precision = "float" # precision in merging (float is recommended) | 合并时计算精度, 可选 float、fp16、bf16, 推荐float
|
5 |
+
$new_rank = 4 # dim rank of output LoRA | dim rank等级, 默认 4
|
6 |
+
$models = "./output/modelA.safetensors ./output/modelB.safetensors" # original LoRA model path need to resize, save as cpkt or safetensors | 需要合并的模型路径, 保存格式 cpkt 或 safetensors,多个用空格隔开
|
7 |
+
$ratios = "1.0 -1.0" # ratios for each model / LoRA模型合并比例,数量等于模型数量,多个用空格隔开
|
8 |
+
$save_to = "./output/lora_name_new.safetensors" # output LoRA model path, save as ckpt or safetensors | 输出路径, 保存格式 cpkt 或 safetensors
|
9 |
+
$device = "cuda" # device to use, cuda for GPU | 使用 GPU跑, 默认 CPU
|
10 |
+
$new_conv_rank = 0 # Specify rank of output LoRA for Conv2d 3x3, None for same as new_rank | Conv2d 3x3输出,没有默认同new_rank
|
11 |
+
|
12 |
+
# Activate python venv
|
13 |
+
.\venv\Scripts\activate
|
14 |
+
|
15 |
+
$Env:HF_HOME = "huggingface"
|
16 |
+
$Env:XFORMERS_FORCE_DISABLE_TRITON = "1"
|
17 |
+
$ext_args = [System.Collections.ArrayList]::new()
|
18 |
+
|
19 |
+
[void]$ext_args.Add("--models")
|
20 |
+
foreach ($model in $models.Split(" ")) {
|
21 |
+
[void]$ext_args.Add($model)
|
22 |
+
}
|
23 |
+
|
24 |
+
[void]$ext_args.Add("--ratios")
|
25 |
+
foreach ($ratio in $ratios.Split(" ")) {
|
26 |
+
[void]$ext_args.Add([float]$ratio)
|
27 |
+
}
|
28 |
+
|
29 |
+
if ($new_conv_rank) {
|
30 |
+
[void]$ext_args.Add("--new_conv_rank=" + $new_conv_rank)
|
31 |
+
}
|
32 |
+
|
33 |
+
# run svd_merge
|
34 |
+
accelerate launch --num_cpu_threads_per_process=8 "./scripts/networks/svd_merge_lora.py" `
|
35 |
+
--save_precision=$save_precision `
|
36 |
+
--precision=$precision `
|
37 |
+
--new_rank=$new_rank `
|
38 |
+
--save_to=$save_to `
|
39 |
+
--device=$device `
|
40 |
+
$ext_args
|
41 |
+
|
42 |
+
Write-Output "SVD Merge finished"
|
43 |
+
Read-Host | Out-Null ;
|