From cbbb5d97fd2750262b1ae406b0009a0eb9796685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=91=E9=B9=8F?= Date: Thu, 5 Sep 2024 14:39:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0approver=E4=BB=A5?= =?UTF-8?q?=E5=8F=8Areviewers=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加approver以及reviewers名单 --- OWNERS | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OWNERS b/OWNERS index 05a0867100..9ee9484655 100644 --- a/OWNERS +++ b/OWNERS @@ -19,6 +19,7 @@ approvers: - fighting_zhen - kezhan1 - jyoung6652 +- Gongen reviewers: - ginray0215 - matrixplayer @@ -53,4 +54,16 @@ reviewers: - han_yifeng - jyoung6652 - maoxx241 -- chenchuw \ No newline at end of file +- chenchuw +- guowenna +- lanwangli +- mazhixin00 +- zhou-wenxue +- huanghao7 +- Gongen +- kezhan1 +- terrychen1982 +- fan2956 +- Yansifu +- yliuls +- shaopeng666 \ No newline at end of file -- Gitee From a54870a32e286e7c0b7b20ef2432832c5c6c9885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=91=E9=B9=8F?= Date: Thu, 5 Sep 2024 19:28:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9lora=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E4=B8=8E=E5=9F=BA=E7=A1=80=E6=9D=83=E9=87=8D=E8=9E=8D=E5=90=88?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert_lora_safetensors_to_diffusers.py | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/MindIE/MindIE-Torch/built-in/foundation/stable_diffusion_xl/convert_lora_safetensors_to_diffusers.py b/MindIE/MindIE-Torch/built-in/foundation/stable_diffusion_xl/convert_lora_safetensors_to_diffusers.py index 2f449cc28d..940bc0c893 100644 --- a/MindIE/MindIE-Torch/built-in/foundation/stable_diffusion_xl/convert_lora_safetensors_to_diffusers.py +++ b/MindIE/MindIE-Torch/built-in/foundation/stable_diffusion_xl/convert_lora_safetensors_to_diffusers.py @@ -20,6 +20,7 @@ import torch from safetensors.torch import load_file from diffusers import StableDiffusionXLPipeline +from diffusers.models.lora import LoRACompatibleConv, LoRACompatibleLinear def convert(base_model_path, checkpoint_path, LORA_PREFIX_UNET, LORA_PREFIX_TEXT_ENCODER, alpha): @@ -78,24 +79,17 @@ def convert(base_model_path, checkpoint_path, LORA_PREFIX_UNET, LORA_PREFIX_TEXT pair_keys.append(key.replace("lora_up", "lora_down")) # update weight - if len(state_dict[pair_keys[0]].shape) == 4: - weight_up = state_dict[pair_keys[0]].squeeze(3).squeeze(2).to(torch.float32) - weight_down = state_dict[pair_keys[1]].squeeze(3).squeeze(2).to(torch.float32) - try: - if len(curr_layer.weight.shape) == 2: - curr_layer.weight.data += alpha * torch.mm(weight_up, weight_down) # for SD2.1 - else: - curr_layer.weight.data += alpha * torch.mm(weight_up, weight_down).unsqueeze(2).unsqueeze(3) - except Exception: - shape4failed += 1 - else: - weight_up = state_dict[pair_keys[0]].to(torch.float32) - weight_down = state_dict[pair_keys[1]].to(torch.float32) - try: - curr_layer.weight.data += alpha * torch.mm(weight_up, weight_down) - except Exception: - shapeno4failed += 1 - + if isinstance(curr_layer, LoRACompatibleConv): + upmat = state_dict[pair_keys[0]].to(torch.float32).flatten(start_dim=1) + downmat = state_dict[pair_keys[1]].to(torch.float32).flatten(start_dim=1) + fusionupdown = torch.mm(upmat, downmat) + fusionupdown = fusionupdown.reshape(curr_layer.weight.data.shape) + curr_layer.weight.data += alpha * fusionupdown + elif isinstance(curr_layer,LoRACompatibleLinear): + upmat = state_dict[pair_keys[0]].to(torch.float32)[None, :] + downmat = state_dict[pair_keys[1]].to(torch.float32)[None, :] + fusion = torch.bmm(upmat, downmat)[0] + curr_layer.weight.data += alpha * fusion # update visited list for item in pair_keys: visited.append(item) -- Gitee