Allowlist dataset conditioning hook classes for safe loading

Datasets built with CLIP hooks store comfy.hooks objects in conditioning;
register them as safe globals so they still load with weights_only=True.
This commit is contained in:
CFionaBF 2026-06-14 01:37:33 -04:00
parent 1b877e583f
commit 0878ec8e5f

View File

@ -10,6 +10,30 @@ from typing_extensions import override
import folder_paths
import node_helpers
from comfy_api.latest import ComfyExtension, io
import comfy.hooks
# Datasets produced by MakeTrainingDataset can embed comfy.hooks objects in their
# conditioning (clip.encode_from_tokens_scheduled stores a HookGroup under "hooks"
# when the CLIP has hooks applied). LoadTrainingDataset loads shards with
# weights_only=True, so register these known classes as safe globals; otherwise such
# datasets fail to load. Only data-bearing hooks (e.g. WeightHook) round-trip this way.
torch.serialization.add_safe_globals([
comfy.hooks.HookGroup,
comfy.hooks.Hook,
comfy.hooks.WeightHook,
comfy.hooks.ObjectPatchHook,
comfy.hooks.AdditionalModelsHook,
comfy.hooks.TransformerOptionsHook,
comfy.hooks.InjectionsHook,
comfy.hooks._HookRef,
comfy.hooks.HookKeyframe,
comfy.hooks.HookKeyframeGroup,
comfy.hooks.EnumHookMode,
comfy.hooks.EnumHookType,
comfy.hooks.EnumWeightTarget,
comfy.hooks.EnumHookScope,
comfy.hooks.default_should_register,
])
def load_and_process_images(image_files, input_dir):