-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ModelPatcher] object patch not properly removed between runs #6303
Comments
Note: Previously the code was calling |
Minimal reproduction: object_patch_reproduction.json Steps:
patch_error.mp4Relevant code: class DummyPatch(torch.nn.Module):
def __init__(self, module: torch.nn.Module, dummy_float: float = 0.0):
super().__init__()
self.module = module
self.dummy_float = dummy_float
def forward(self, *args, **kwargs):
if isinstance(self.module, DummyPatch):
raise Exception(f"Calling nested dummy patch! {self.dummy_float}")
return self.module(*args, **kwargs)
class ObjectPatchNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("MODEL",),
"target_module": ("STRING", {"multiline": True}),
},
"optional": {
"dummy_float": ("FLOAT", {"default": 0.0 }),
}
}
RETURN_TYPES = ("MODEL",)
FUNCTION = "apply_patch"
CATEGORY = "DevTools"
DESCRIPTION = "A node that applies an object patch"
def apply_patch(
self, model: ModelPatcher, target_module: str, dummy_float: float = 0.0
) -> ModelPatcher:
module = utils.get_attr(model.model, target_module)
work_model = model.clone()
work_model.add_object_patch(target_module, DummyPatch(module, dummy_float))
return (work_model,) The issue is that when I want to apply a different patch by adjusting dummy_float input, the previous patch was not removed. |
Context: Add |
From @Kosinkadink
Actionable:
|
Codesearch shows there are about 8 repos affected: https://cs.comfy.org/search?q=context:global+get_attr%28&patternType=keyword&sm=0 |
Expected Behavior
Object patch is properly removed from different workflow execution.
Actual Behavior
Object patches are not removed when executing different patches.
Steps to Reproduce
Install ComfyUI-layerdiffuse and patch PR: Fix SD15 memory sharing huchenlei/ComfyUI-layerdiffuse#119
Start ComfyUI server
Execute workflow1 and observe that it executes normally layer_diffusion_fg_example (1).json

Execute workflow 2 and observe error

layer_diffusion_cond_joint_bg (1).json
Restart ComfyUI server
Execute workflow 2 and observe that it executes normally

Execute wrkflow 1 and observe the same error as in step 4 on workflow 2

Putting a breakpoint here https://github.com/huchenlei/ComfyUI-layerdiffuse/blob/ab409eefbba15ecc322a6ea830e077576e904326/lib_layerdiffusion/attention_sharing.py#L334
on step 7 run indicates that the objectes_backup is not restored after the previous run.

Debug Logs
N/A
Other
Ref issue: huchenlei/ComfyUI-layerdiffuse#115
Workflow 2 input image:

The text was updated successfully, but these errors were encountered: