Hermes Bot commited on
Commit ·
2b442eb
1
Parent(s): 6bcb2c3
Clean setup.py: single CPU fallback patch and torch monkey‑patch before import
Browse files
comfy_integration/__pycache__/setup.cpython-311.pyc
CHANGED
|
Binary files a/comfy_integration/__pycache__/setup.cpython-311.pyc and b/comfy_integration/__pycache__/setup.cpython-311.pyc differ
|
|
|
comfy_integration/setup.py
CHANGED
|
@@ -39,7 +39,6 @@ def initialize_comfyui():
|
|
| 39 |
except OSError as e:
|
| 40 |
print(f"⚠️ Could not remove temporary directory '{COMFYUI_TEMP_DIR}': {e}")
|
| 41 |
|
| 42 |
-
|
| 43 |
print("--- Cloning third-party extensions for ComfyUI ---")
|
| 44 |
|
| 45 |
# 1. ComfyUI_IPAdapter_plus
|
|
@@ -84,14 +83,17 @@ def initialize_comfyui():
|
|
| 84 |
|
| 85 |
print(f"✅ Current working directory is: {os.getcwd()}")
|
| 86 |
|
| 87 |
-
|
| 88 |
-
# Patch get_torch_device to ensure CPU fallback on systems without a GPU.
|
| 89 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
def _cpu_fallback_get_torch_device():
|
| 91 |
"""Return appropriate torch device, falling back to CPU when needed.
|
| 92 |
+
|
| 93 |
+ This patch replaces the original implementation that assumed a CUDA GPU
|
| 94 |
-
+ and raised a RuntimeError on CPU‑only systems.
|
| 95 |
+ ``directml_enabled`` and ``cpu_state`` flags, and falls back to CPU when
|
| 96 |
+ no GPU backend is available.
|
| 97 |
+ """
|
|
@@ -111,19 +113,17 @@ def initialize_comfyui():
|
|
| 111 |
return torch.device("npu", torch.npu.current_device())
|
| 112 |
if model_mgmt.is_mlu():
|
| 113 |
return torch.device("mlu", torch.mlu.current_device())
|
| 114 |
-
# CUDA – use if available.
|
| 115 |
if torch.cuda.is_available():
|
| 116 |
return torch.device(torch.cuda.current_device())
|
| 117 |
-
#
|
| 118 |
return torch.device("cpu")
|
| 119 |
model_mgmt.get_torch_device = _cpu_fallback_get_torch_device
|
| 120 |
-
|
| 121 |
-
# Ensure the patched function is used by subsequent imports.
|
| 122 |
import importlib
|
| 123 |
importlib.reload(model_mgmt)
|
| 124 |
|
| 125 |
print("--- Environment Ready ---")
|
| 126 |
-
|
| 127 |
print("✅ ComfyUI initialized with default attention mechanism.")
|
| 128 |
|
| 129 |
for dir_path in CATEGORY_TO_DIR_MAP.values():
|
|
@@ -132,4 +132,4 @@ def initialize_comfyui():
|
|
| 132 |
os.makedirs(os.path.join(APP_DIR, INPUT_DIR), exist_ok=True)
|
| 133 |
os.makedirs(os.path.join(APP_DIR, OUTPUT_DIR), exist_ok=True)
|
| 134 |
|
| 135 |
-
print("✅ All required model directories are present.")
|
|
|
|
| 39 |
except OSError as e:
|
| 40 |
print(f"⚠️ Could not remove temporary directory '{COMFYUI_TEMP_DIR}': {e}")
|
| 41 |
|
|
|
|
| 42 |
print("--- Cloning third-party extensions for ComfyUI ---")
|
| 43 |
|
| 44 |
# 1. ComfyUI_IPAdapter_plus
|
|
|
|
| 83 |
|
| 84 |
print(f"✅ Current working directory is: {os.getcwd()}")
|
| 85 |
|
| 86 |
+
# Ensure torch treats CUDA as unavailable on CPU‑only environment.
|
|
|
|
| 87 |
import torch
|
| 88 |
+
torch.cuda.is_available = lambda: False
|
| 89 |
+
|
| 90 |
+
import comfy.model_management as model_mgmt
|
| 91 |
+
# Patch get_torch_device to enforce CPU fallback.
|
| 92 |
def _cpu_fallback_get_torch_device():
|
| 93 |
"""Return appropriate torch device, falling back to CPU when needed.
|
| 94 |
+
|
| 95 |
+ This patch replaces the original implementation that assumed a CUDA GPU
|
| 96 |
+
+ and raised a RuntimeError on CPU‑only systems. It respects the existing
|
| 97 |
+ ``directml_enabled`` and ``cpu_state`` flags, and falls back to CPU when
|
| 98 |
+ no GPU backend is available.
|
| 99 |
+ """
|
|
|
|
| 113 |
return torch.device("npu", torch.npu.current_device())
|
| 114 |
if model_mgmt.is_mlu():
|
| 115 |
return torch.device("mlu", torch.mlu.current_device())
|
| 116 |
+
# CUDA – use if available (will be False due to monkey‑patch).
|
| 117 |
if torch.cuda.is_available():
|
| 118 |
return torch.device(torch.cuda.current_device())
|
| 119 |
+
# Default to CPU.
|
| 120 |
return torch.device("cpu")
|
| 121 |
model_mgmt.get_torch_device = _cpu_fallback_get_torch_device
|
|
|
|
|
|
|
| 122 |
import importlib
|
| 123 |
importlib.reload(model_mgmt)
|
| 124 |
|
| 125 |
print("--- Environment Ready ---")
|
| 126 |
+
|
| 127 |
print("✅ ComfyUI initialized with default attention mechanism.")
|
| 128 |
|
| 129 |
for dir_path in CATEGORY_TO_DIR_MAP.values():
|
|
|
|
| 132 |
os.makedirs(os.path.join(APP_DIR, INPUT_DIR), exist_ok=True)
|
| 133 |
os.makedirs(os.path.join(APP_DIR, OUTPUT_DIR), exist_ok=True)
|
| 134 |
|
| 135 |
+
print("✅ All required model directories are present.")
|