From a64fe846afa271525daa6edc1d3144a187440bab Mon Sep 17 00:00:00 2001 From: V0pr0S Date: Thu, 25 Dec 2025 21:28:54 +0300 Subject: [PATCH] Fix AttributeError in ModelPatcher.__del__ by adding safety check for 'pinned' --- comfy/model_patcher.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/comfy/model_patcher.py b/comfy/model_patcher.py index 93d26c690..1cf05ee39 100644 --- a/comfy/model_patcher.py +++ b/comfy/model_patcher.py @@ -651,8 +651,12 @@ class ModelPatcher: self.pinned.remove(key) def unpin_all_weights(self): - for key in list(self.pinned): - self.unpin_weight(key) + if hasattr(self, 'pinned'): # Safety check + for key in list(self.pinned): + self.unpin_weight(key) + else: + # Log or skip: self.pinned was not set + pass def _load_list(self): loading = [] @@ -1354,6 +1358,12 @@ class ModelPatcher: self.clear_cached_hook_weights() def __del__(self): - self.unpin_all_weights() - self.detach(unpatch_all=False) + try: + if hasattr(self, 'pinned'): + self.unpin_all_weights() + # Existing code... + except Exception as e: + # Suppress errors in destructor to avoid noise + pass +