Compare commits

..
10 Commits
Author SHA1 Message Date
Dr.Lt.Data f5467e1a37 fixed: torch_wrapper – When weights_only is explicitly provided, pass the arg as is. 2025-01-04 10:08:34 +09:00
Dr.Lt.Data 769bc0f14a add a note for torch.load 2025-01-04 03:27:54 +09:00
Dr.Lt.Data 3345986dd7 version marker 2025-01-03 22:38:25 +09:00
Dr.Lt.Data d21517351d Merge pull request #20 from gremlation/add-dill-dep
Add the `dill` dependency
2025-01-03 22:33:22 +09:00
Gremlation 3d54756136 Add the dill dependency 2025-01-03 19:58:39 +08:00
Dr.Lt.Data b61465c06f hotfix 2025-01-03 12:24:39 +09:00
Dr.Lt.Data 55dd4ccef5 fixed: numpy dependency error
- requirements.txt - pin `numpy==1.26.4`
- subcore - provide error with guide
2025-01-03 12:21:42 +09:00
Dr.Lt.Data 4401965637 fixed: compatibility patch
https://github.com/EvilBT/ComfyUI_SLK_joy_caption_two/issues/109
2025-01-03 02:35:01 +09:00
Dr.Lt.Data d22e2fa534 improve: security - restriected_getattr 2025-01-02 18:44:17 +09:00
Dr.Lt.Data 8ad54e5e4f fix: support old torch with warning message 2025-01-02 04:07:13 +09:00
4 changed files with 53 additions and 10 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
import importlib
import logging
version_code = [1, 2]
version_code = [1, 2, 7]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
logging.info(f"### Loading: ComfyUI-Impact-Subpack ({version_str})")
+48 -6
View File
@@ -37,6 +37,18 @@ def create_segmasks(results):
return results
# Limit the commands that can be executed through `getattr` to `ultralytics.nn.modules.head.Detect.forward`.
def restricted_getattr(obj, name, *args):
if name != "forward":
logging.error(f"Access to potentially dangerous attribute '{obj.__module__}.{obj.__name__}.{name}' is blocked.\nIf you believe the use of this code is genuinely safe, please report it.\nhttps://github.com/ltdrdata/ComfyUI-Impact-Subpack/issues")
raise RuntimeError(f"Access to potentially dangerous attribute '{obj.__module__}.{obj.__name__}.{name}' is blocked.")
return getattr(obj, name, *args)
restricted_getattr.__module__ = 'builtins'
restricted_getattr.__name__ = 'getattr'
try:
from ultralytics import YOLO
from ultralytics.nn.tasks import DetectionModel
@@ -49,8 +61,13 @@ try:
import ultralytics.utils.loss as loss_modules
import dill._dill
from numpy.core.multiarray import scalar
from numpy import dtype
from numpy.dtypes import Float64DType
try:
from numpy import dtype
from numpy.dtypes import Float64DType
except:
logging.error("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy' to 1.26.4")
raise Exception("[Impact Subpack] installed 'numpy' is outdated. Please update 'numpy' to 1.26.4")
torch_whitelist = []
@@ -108,7 +125,7 @@ try:
torch_whitelist += [DetectionModel, aliasYOLOv10DetectionModel, SegmentationModel, IterableSimpleNamespace,
aliasIterableSimpleNamespace, TaskAlignedAssigner, aliasTaskAlignedAssigner, aliasv10DetectLoss,
getattr, dill._dill._load_type, scalar, dtype, Float64DType]
restricted_getattr, dill._dill._load_type, scalar, dtype, Float64DType]
build_torch_whitelist()
@@ -120,18 +137,43 @@ except Exception as e:
# HOTFIX: https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/754
# importing YOLO breaking original torch.load capabilities
def torch_wrapper(*args, **kwargs):
return orig_torch_load(*args, **kwargs)
# NOTE: A trick to support code based on `'weights_only' in torch.load.__code__.co_varnames`.
if 'weights_only' in kwargs:
weights_only = kwargs.pop('weights_only')
else:
weights_only = None
if hasattr(torch.serialization, 'safe_globals'):
if weights_only is not None:
kwargs['weights_only'] = weights_only
return orig_torch_load(*args, **kwargs) # NOTE: This code simply delegates the call to torch.load, and any errors that occur here are not the responsibility of Subpack.
else:
if weights_only is not None:
kwargs['weights_only'] = weights_only
else:
logging.warning("[Impact Subpack] Your torch version is outdated, and security features cannot be applied properly.")
kwargs['weights_only'] = False
return orig_torch_load(*args, **kwargs)
torch.load = torch_wrapper
def load_yolo(model_path: str):
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
with torch.serialization.safe_globals(torch_whitelist):
if hasattr(torch.serialization, 'safe_globals'):
with torch.serialization.safe_globals(torch_whitelist):
try:
return YOLO(model_path)
except ModuleNotFoundError:
# https://github.com/ultralytics/ultralytics/issues/3856
YOLO("yolov8n.pt")
return YOLO(model_path)
else:
try:
return YOLO(model_path)
except ModuleNotFoundError:
# https://github.com/ultralytics/ultralytics/issues/3856
YOLO("yolov8n.pt")
return YOLO(model_path)
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-impact-subpack"
description = "This node pack provides nodes that complement the Impact Pack, such as the UltralyticsDetectorProvider."
version = "1.2"
version = "1.2.7"
license = { file = "LICENSE.txt" }
dependencies = ["matplotlib", "ultralytics==8.3.40"]
+3 -2
View File
@@ -1,4 +1,5 @@
matplotlib
ultralytics==8.3.40
numpy<2
opencv-python-headless
numpy==1.26.4
opencv-python-headless
dill