Skip to content

Commit

Permalink
Adapt calculate_weight patch (moved from ModelPatcher to comfy.lora) #78
Browse files Browse the repository at this point in the history
  • Loading branch information
Acly committed Aug 24, 2024
1 parent 48a8913 commit 6ce66ff
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ def load_fooocus_patch(lora: dict, to_load: dict):
return patch_dict


original_calculate_weight = ModelPatcher.calculate_weight
if not hasattr(comfy.lora, "calculate_weight") and hasattr(ModelPatcher, "calculate_weight"):
too_old_msg = "comfyui-inpaint-nodes requires a newer version of ComfyUI (v0.1.1 or later), please update!"
raise RuntimeError(too_old_msg)


original_calculate_weight = comfy.lora.calculate_weight
injected_model_patcher_calculate_weight = False


def calculate_weight_patched(self: ModelPatcher, patches, weight, key):
def calculate_weight_patched(patches, weight, key, intermediate_dtype=torch.float32):
remaining = []

for p in patches:
Expand All @@ -88,7 +93,7 @@ def calculate_weight_patched(self: ModelPatcher, patches, weight, key):
)

if len(remaining) > 0:
return original_calculate_weight(self, remaining, weight, key)
return original_calculate_weight(remaining, weight, key, intermediate_dtype)
return weight


Expand All @@ -98,7 +103,7 @@ def inject_patched_calculate_weight():
print(
"[comfyui-inpaint-nodes] Injecting patched comfy.model_patcher.ModelPatcher.calculate_weight"
)
ModelPatcher.calculate_weight = calculate_weight_patched
comfy.lora.calculate_weight = calculate_weight_patched
injected_model_patcher_calculate_weight = True


Expand Down

0 comments on commit 6ce66ff

Please sign in to comment.