From 8ad54e5e4fdcae1ccbbdac55a5c625f4bd5d2545 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Thu, 2 Jan 2025 04:07:13 +0900 Subject: [PATCH] fix: support old torch with warning message --- __init__.py | 2 +- modules/subcore.py | 17 ++++++++++++++--- pyproject.toml | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 46b2777..60a0052 100644 --- a/__init__.py +++ b/__init__.py @@ -8,7 +8,7 @@ import importlib import logging -version_code = [1, 2] +version_code = [1, 2, 1] 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})") diff --git a/modules/subcore.py b/modules/subcore.py index 9804a87..8cca2de 100644 --- a/modules/subcore.py +++ b/modules/subcore.py @@ -120,18 +120,29 @@ 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) + if hasattr(torch.serialization, 'safe_globals'): + return orig_torch_load(*args, **kwargs) + else: + logging.warning("[Impact Subpack] Your torch version is outdated, and security features cannot be applied properly.") + return orig_torch_load(*args, **kwargs, weights_only=False) 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) diff --git a/pyproject.toml b/pyproject.toml index a27b77f..47451d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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.1" license = { file = "LICENSE.txt" } dependencies = ["matplotlib", "ultralytics==8.3.40"]