From d4fbdb01390230d02d4b33c9b4ad721321f22d67 Mon Sep 17 00:00:00 2001 From: City <125218114+city96@users.noreply.github.com> Date: Tue, 4 Nov 2025 07:04:11 +0100 Subject: [PATCH 1/2] Add type string for older mmproj files --- loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.py b/loader.py index fd35e13..032c739 100644 --- a/loader.py +++ b/loader.py @@ -11,7 +11,7 @@ from .dequant import is_quantized, dequantize_tensor IMG_ARCH_LIST = {"flux", "sd1", "sdxl", "sd3", "aura", "hidream", "cosmos", "ltxv", "hyvid", "wan", "lumina2", "qwen_image"} TXT_ARCH_LIST = {"t5", "t5encoder", "llama", "qwen2vl"} -VIS_TYPE_LIST = {"clip-vision"} +VIS_TYPE_LIST = {"clip-vision", "mmproj"} def get_orig_shape(reader, tensor_name): field_key = f"comfy.gguf.orig_shape.{tensor_name}" From 02dac863ee1b65852d39ce6b9180bf5d9bc8a636 Mon Sep 17 00:00:00 2001 From: rattus <46076784+rattus128@users.noreply.github.com> Date: Sat, 8 Nov 2025 08:31:20 +1000 Subject: [PATCH 2/2] add default named_modules_to_munmap variable (#357) * add default named_modules_to_munmap variable Default this to handle to case of cloning a GGUFModelPatcher which then expects it to exist on the clone. I could never reproduce this condition, however 4 users have the error. This error path is very sensitive to VRAM condtions and workflow and I never got the details so its a bit of a guess. But from a code point of view, its the right thing anyway * nodes: carry the mmap_released state through a clone() There are workflows where the same underlying model will be loaded twice by two different ModelPatchers. With the current code as-is, the first patcher will load fine and intercept the pins while removing already done pins from the free modules list. It then will load again with the second MP however, this one will not get the callbacks for the already pinned stuff and then rip through and .to().to() them all. This destroys the pinning setup while comfy core still keeps the modules registered as unpinned. This causes a crash on einval when core goes to unpin the not pinned tensors. Comfy core now has a guard against unpinning the not-pinned, however what I think is happening, is the RAM of the pin in freed in the .to().to() and then malloc re-allocates it to new tensors with cuda keeping its records of previous pinning. einval can happen when you try and unpin a tensor in the middle of the block which is definately possible on this use after free pattern. --- nodes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodes.py b/nodes.py index 08849df..ff5aaf0 100644 --- a/nodes.py +++ b/nodes.py @@ -79,13 +79,14 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): def pin_weight_to_device(self, key): op_key = key.rsplit('.', 1)[0] - if self.named_modules_to_munmap is not None and op_key in self.named_modules_to_munmap: + if not self.mmap_released and op_key in self.named_modules_to_munmap: # TODO: possible to OOM, find better way to detach self.named_modules_to_munmap[op_key].to(self.load_device).to(self.offload_device) del self.named_modules_to_munmap[op_key] super().pin_weight_to_device(key) mmap_released = False + named_modules_to_munmap = {} def load(self, *args, force_patch_weights=False, **kwargs): if not self.mmap_released: @@ -115,7 +116,7 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): # TODO: possible to OOM, find better way to detach m.to(self.load_device).to(self.offload_device) self.mmap_released = True - self.named_modules_to_munmap = None + self.named_modules_to_munmap = {} def clone(self, *args, **kwargs): src_cls = self.__class__ @@ -125,6 +126,7 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): self.__class__ = src_cls # GGUF specific clone values below n.patch_on_device = getattr(self, "patch_on_device", False) + n.mmap_released = getattr(self, "mmap_released", False) if src_cls != GGUFModelPatcher: n.size = 0 # force recalc return n