From 03842fab0a78fd142b020e42ec76d871d947bc32 Mon Sep 17 00:00:00 2001 From: City <125218114+city96@users.noreply.github.com> Date: Wed, 7 May 2025 04:42:20 +0200 Subject: [PATCH] Remove old workaround --- nodes.py | 11 ++++------- ops.py | 9 +++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/nodes.py b/nodes.py index a7f4313..4159142 100644 --- a/nodes.py +++ b/nodes.py @@ -5,6 +5,8 @@ import collections import nodes import comfy.sd +import comfy.lora +import comfy.float import comfy.utils import comfy.model_patcher import comfy.model_management @@ -37,17 +39,12 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): return weight = comfy.utils.get_attr(self.model, key) - try: - from comfy.lora import calculate_weight - except Exception: - calculate_weight = self.calculate_weight - patches = self.patches[key] if is_quantized(weight): out_weight = weight.to(device_to) patches = move_patch_to_device(patches, self.load_device if self.patch_on_device else self.offload_device) # TODO: do we ever have legitimate duplicate patches? (i.e. patch on top of patched weight) - out_weight.patches = [(calculate_weight, patches, key)] + out_weight.patches = [(patches, key)] else: inplace_update = self.weight_inplace_update or inplace_update if key not in self.backup: @@ -60,7 +57,7 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): else: temp_weight = weight.to(torch.float32, copy=True) - out_weight = calculate_weight(patches, temp_weight, key) + out_weight = comfy.lora.calculate_weight(patches, temp_weight, key) out_weight = comfy.float.stochastic_rounding(out_weight, weight.dtype) if inplace_update: diff --git a/ops.py b/ops.py index 441b301..41d42f5 100644 --- a/ops.py +++ b/ops.py @@ -4,6 +4,7 @@ import torch import logging import comfy.ops +import comfy.lora import comfy.model_management from .dequant import dequantize_tensor, is_quantized @@ -169,7 +170,7 @@ class GGMLLayer(torch.nn.Module): # consolidate and load patches to GPU in async patch_list = [] device = tensor.device - for function, patches, key in getattr(tensor, "patches", []): + for patches, key in getattr(tensor, "patches", []): patch_list += move_patch_to_device(patches, device) # dequantize tensor while patches load @@ -180,13 +181,13 @@ class GGMLLayer(torch.nn.Module): weight = torch.Tensor(weight) # apply patches - if patch_list: + if len(patch_list) > 0: if self.patch_dtype is None: - weight = function(patch_list, weight, key) + weight = comfy.lora.calculate_weight(patch_list, weight, key) else: # for testing, may degrade image quality patch_dtype = dtype if self.patch_dtype == "target" else self.patch_dtype - weight = function(patch_list, weight, key, patch_dtype) + weight = comfy.lora.calculate_weight(patch_list, weight, key, patch_dtype) return weight @torch_compiler_disable()