Skip to content

Commit 5912141

Browse files
authored
Update distorch_2.py: Add compatibility for GGUFModelPatcher and ModelPatcher lacking model_patches_models attribute
Some model patchers define only model_patches_to() and not model_patches_models(), which ComfyUI expects for dependency discovery. This patch adds a targeted fallback for GGUFModelPatcher and ModelPatcher to prevent AttributeError when model_patches_models() is missing.
1 parent a24f0a6 commit 5912141

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

distorch_2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ def patched_load_models_gpu(models, memory_required=0, force_patch_weights=False
5151
models_temp = set()
5252
for m in models:
5353
models_temp.add(m)
54+
model_type = type(m).__name__
55+
56+
if ("GGUF" in model_type or "ModelPatcher" in model_type) and hasattr(m, "model_patches_to"):
57+
print(f"[MultiGPU] {type(m).__name__} missing 'model_patches_models' attribute, using 'model_patches_to' fallback.")
58+
target_device = getattr(m, "load_device",
59+
f"cuda:{torch.cuda.current_device()}" if torch.cuda.is_available() else "cpu")
60+
print(f"Target device: {target_device}")
61+
patches = m.model_patches_to(target_device)
62+
if patches:
63+
print(f"[MultiGPU] Found {len(patches)} mm_patch(es) for {type(m).__name__} on device {target_device}")
64+
for mm_patch in patches:
65+
print(f"[MultiGPU] Registering mm_patch: {type(mm_patch).__name__}")
66+
models_temp.add(mm_patch)
67+
continue
68+
5469
for mm_patch in m.model_patches_models():
5570
models_temp.add(mm_patch)
5671
patches = m.model_patches_to(m.load_device)

0 commit comments

Comments
 (0)