{"record":{"id":"45f6e344d0149906","repo":"Comfy-Org/ComfyUI","slug":"cannot-create-non-dynamic-delegate-cached-patcher","errorCode":null,"errorMessage":"Cannot create non-dynamic delegate: cached_patcher_init is not initialized.","messagePattern":"Cannot create non-dynamic delegate: cached_patcher_init is not initialized\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy/model_patcher.py","lineNumber":437,"sourceCode":"        #the vast majority of setups a little bit of offloading on the giant model more\n        #than pays for CFG. So return everything both torch and Aimdo could give us\n        aimdo_mem = 0\n        if comfy.memory_management.aimdo_enabled:\n            aimdo_device = device.index if getattr(device, \"type\", None) == \"cuda\" else None\n            aimdo_mem = comfy_aimdo.model_vbar.vbars_analyze(aimdo_device)\n        return comfy.model_management.get_free_memory(device) + aimdo_mem\n\n    def get_clone_model_override(self):\n        return self.model, (self.backup, self.backup_buffers, self.object_patches_backup, self.pinned)\n\n    def clone(self, disable_dynamic=False, model_override=None, force_deepcopy=False):\n        class_ = self.__class__\n        if self.is_dynamic() and disable_dynamic or force_deepcopy:\n            if self.is_dynamic() and disable_dynamic:\n                class_ = ModelPatcher\n            if model_override is None:\n                if self.cached_patcher_init is None:\n                    raise RuntimeError(\"Cannot create non-dynamic delegate: cached_patcher_init is not initialized.\")\n                temp_model_patcher = self.cached_patcher_init[0](*self.cached_patcher_init[1], disable_dynamic=True)\n                if len(self.cached_patcher_init) > 2:\n                    temp_model_patcher = temp_model_patcher[self.cached_patcher_init[2]]\n                model_override = temp_model_patcher.get_clone_model_override()\n        if model_override is None:\n            model_override = self.get_clone_model_override()\n\n        n = class_(model_override[0], self.load_device, self.offload_device, self.model_size(), weight_inplace_update=self.weight_inplace_update)\n        n.patches = {}\n        for k in self.patches:\n            n.patches[k] = self.patches[k][:]\n        n.patches_uuid = self.patches_uuid\n\n        n.object_patches = self.object_patches.copy()\n        n.weight_wrapper_patches = self.weight_wrapper_patches.copy()\n        n.model_options = comfy.utils.deepcopy_list_dict(self.model_options)\n        n.parent = self\n","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/model_patcher.py#L419-L455","documentation":"Cloning a dynamic ModelPatcher into a non-dynamic delegate requires re-instantiating the model through the loader factory stored in cached_patcher_init. If that factory was never registered (custom loader bypassed the core loader plumbing), the clone path has no way to rebuild a clean model and raises RuntimeError rather than producing a half-configured delegate.","triggerScenarios":"patcher.clone(disable_dynamic=True) or clone(force_deepcopy=True) on a ModelPatcher whose cached_patcher_init is None — typically a patcher returned by a custom node loader that constructed ModelPatcher directly.","commonSituations":"Using --fast (dynamic patcher) together with a custom-node model loader; nodes that call clone(disable_dynamic=True) for hooks or sampling on models from non-core loaders; older custom loaders not updated for the cached_patcher_init contract.","solutions":["Load the model with a core loader (CheckpointLoaderSimple, UNETLoader, CLIPLoader/DualCLIPLoader, VAELoader) so cached_patcher_init is registered.","If you maintain the custom loader, register a cached_patcher_init factory that rebuilds the patcher from the checkpoint.","As a user, drop --fast startup arguments when working with models from custom loaders."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"patcher = loader_output\nif getattr(patcher, \"is_dynamic\", lambda: False)() and patcher.cached_patcher_init is None:\n    raise RuntimeError(\"custom loader did not register cached_patcher_init; cannot make non-dynamic clone\")\nclone = patcher.clone(disable_dynamic=True)","typeGuard":"def supports_dynamic_delegate(patcher) -> bool:\n    return (not patcher.is_dynamic()) or patcher.cached_patcher_init is not None","tryCatchPattern":null,"preventionTips":["Prefer core loaders for models that will be cloned or used with hooks.","Custom loader authors: register cached_patcher_init when constructing the ModelPatcher.","Avoid --fast when mixing custom loaders into the workflow."],"tags":["model-patcher","dynamic","clone","custom-loader","fast"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}