Skip to content

Commit

Permalink
fix the memory leakage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
openvino-dev-samples committed Mar 6, 2025
1 parent 8558803 commit bc9eb9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion comfy/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,19 @@ def add_patches(self, patches, strength_patch=1.0, strength_model=1.0):
if len(k) > 2:
function = k[2]
org_key=key.replace("diffusion_model", "diffusion_model._orig_mod")
if key in model_sd or org_key in model_sd:
if key in model_sd:
p.add(k)
current_patches = self.patches.get(key, [])
current_patches.append((strength_patch, patches[k], strength_model, offset, function))
self.patches[key] = current_patches
self.patches[org_key] = current_patches
elif org_key in model_sd:
if key in self.patches:
self.patches.pop(key)
p.add(k)
current_patches = self.patches.get(org_key, [])
current_patches.append((strength_patch, patches[k], strength_model, offset, function))
self.patches[org_key] = current_patches

self.patches_uuid = uuid.uuid4()
return list(p)
Expand Down
11 changes: 9 additions & 2 deletions comfy_extras/nodes_torch_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def INPUT_TYPES(s):
"backend": (["inductor", "cudagraphs", "openvino"],),
},
"optional": {
"openvino_device": (available_devices,),
"openvino device": (available_devices,),
},
}

Expand All @@ -30,6 +30,7 @@ def INPUT_TYPES(s):
EXPERIMENTAL = True

def patch(self, model, backend, openvino_device):
print(model.__class__.__name__)
if backend == "openvino":
options = {"device": openvino_device}
try:
Expand All @@ -39,6 +40,12 @@ def patch(self, model, backend, openvino_device):
"Could not import openvino python package. "
"Please install it with `pip install openvino`."
)
import openvino.frontend.pytorch.torchdynamo.execute as ov_ex

torch._dynamo.reset()
ov_ex.compiled_cache.clear()
ov_ex.req_cache.clear()
ov_ex.partitioned_modules.clear()
else:
options = None
m = model.clone()
Expand All @@ -55,4 +62,4 @@ def patch(self, model, backend, openvino_device):

NODE_CLASS_MAPPINGS = {
"TorchCompileModel": TorchCompileModel,
}
}

0 comments on commit bc9eb9d

Please sign in to comment.