mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
mp: dont deep-clone objects from model_options (#12382)
If there are non-trivial python objects nested in the model_options, this causes all sorts of issues. Traverse lists and dicts so clones can safely overide settings and BYO objects but stop there on the deepclone.
This commit is contained in:
parent
6648ab68bc
commit
fe053ba5eb
@ -19,7 +19,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import copy
|
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
@ -317,7 +316,7 @@ class ModelPatcher:
|
|||||||
|
|
||||||
n.object_patches = self.object_patches.copy()
|
n.object_patches = self.object_patches.copy()
|
||||||
n.weight_wrapper_patches = self.weight_wrapper_patches.copy()
|
n.weight_wrapper_patches = self.weight_wrapper_patches.copy()
|
||||||
n.model_options = copy.deepcopy(self.model_options)
|
n.model_options = comfy.utils.deepcopy_list_dict(self.model_options)
|
||||||
n.backup = self.backup
|
n.backup = self.backup
|
||||||
n.object_patches_backup = self.object_patches_backup
|
n.object_patches_backup = self.object_patches_backup
|
||||||
n.parent = self
|
n.parent = self
|
||||||
|
|||||||
@ -1376,3 +1376,21 @@ def string_to_seed(data):
|
|||||||
else:
|
else:
|
||||||
crc >>= 1
|
crc >>= 1
|
||||||
return crc ^ 0xFFFFFFFF
|
return crc ^ 0xFFFFFFFF
|
||||||
|
|
||||||
|
def deepcopy_list_dict(obj, memo=None):
|
||||||
|
if memo is None:
|
||||||
|
memo = {}
|
||||||
|
|
||||||
|
obj_id = id(obj)
|
||||||
|
if obj_id in memo:
|
||||||
|
return memo[obj_id]
|
||||||
|
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
res = {deepcopy_list_dict(k, memo): deepcopy_list_dict(v, memo) for k, v in obj.items()}
|
||||||
|
elif isinstance(obj, list):
|
||||||
|
res = [deepcopy_list_dict(i, memo) for i in obj]
|
||||||
|
else:
|
||||||
|
res = obj
|
||||||
|
|
||||||
|
memo[obj_id] = res
|
||||||
|
return res
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user