Fix Unfuse Lora (#4833) · zzmjohn/diffusers@9f1936d · GitHub
Skip to content

Commit 9f1936d

Browse files
Fix Unfuse Lora (huggingface#4833)
* Fix Unfuse Lora * add tests * Fix more * Fix more * Fix all * make style * make style
1 parent fbca2e0 commit 9f1936d

3 files changed

Lines changed: 131 additions & 22 deletions

File tree

‎src/diffusers/loaders.py‎

Lines changed: 56 additions & 17 deletions

‎src/diffusers/models/lora.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def _fuse_lora(self):
168168
return
169169

170170
dtype, device = self.weight.data.dtype, self.weight.data.device
171-
logger.info(f"Fusing LoRA weights for {self.__class__}")
172171

173172
w_orig = self.weight.data.float()
174173
w_up = self.lora_layer.up.weight.data.float()
@@ -190,14 +189,14 @@ def _fuse_lora(self):
190189
def _unfuse_lora(self):
191190
if not (hasattr(self, "w_up") and hasattr(self, "w_down")):
192191
return
193-
logger.info(f"Unfusing LoRA weights for {self.__class__}")
194192

195193
fused_weight = self.weight.data
196194
dtype, device = fused_weight.dtype, fused_weight.device
197195

198-
self.w_up = self.w_up.to(device=device, dtype=dtype)
199-
self.w_down = self.w_down.to(device, dtype=dtype)
200-
unfused_weight = fused_weight - torch.bmm(self.w_up[None, :], self.w_down[None, :])[0]
196+
w_up = self.w_up.to(device=device).float()
197+
w_down = self.w_down.to(device).float()
198+
199+
unfused_weight = fused_weight.float() - torch.bmm(w_up[None, :], w_down[None, :])[0]
201200
self.weight.data = unfused_weight.to(device=device, dtype=dtype)
202201

203202
self.w_up = None

‎tests/models/test_lora_layers.py‎

Lines changed: 71 additions & 0 deletions

0 commit comments

Comments
 (0)