From 8705579536c2c5b5c09c5ea153c1195892177145 Mon Sep 17 00:00:00 2001 From: Octopus Date: Fri, 3 Apr 2026 16:00:12 +0800 Subject: [PATCH] fix: make comfy_aimdo import optional for AMD/ROCm GPU support When comfy-aimdo is not installed (e.g. on AMD/ROCm systems), the bare 'import comfy_aimdo.control' at module level causes an immediate ModuleNotFoundError that prevents ComfyUI from starting at all. This change wraps the import in a try/except block. On ImportError, a minimal no-op stub is installed in sys.modules so that subsequent 'import comfy_aimdo.*' statements in other modules (execution.py, comfy/ops.py, comfy/model_patcher.py, comfy/pinned_memory.py, etc.) also succeed without modification. The stub returns False from all calls, which: - Prevents comfy_aimdo.control.init_device() from signalling success - Keeps comfy.memory_management.aimdo_enabled=False (its default) - Allows all aimdo-guarded code paths to be safely skipped Fixes #13182 --- main.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 12b04719d572..bf6ba48895c1 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,41 @@ faulthandler.enable(file=sys.stderr, all_threads=False) -import comfy_aimdo.control +try: + import comfy_aimdo.control +except ImportError: + logging.info("comfy-aimdo not installed. DynamicVRAM will not be available.") + import types + + class _AimdoStub: + """No-op stub for comfy_aimdo submodules when the package is not installed. + + All attribute accesses return self and all calls return False (falsy), + which prevents any aimdo-guarded code paths from activating while still + allowing the import to succeed on non-NVIDIA hardware (e.g. AMD/ROCm). + """ + def __getattr__(self, name): + return _AimdoStub() + + def __call__(self, *args, **kwargs): + return False + + def __bool__(self): + return False + + def __int__(self): + return 0 + + def __float__(self): + return 0.0 + + _aimdo_pkg = types.ModuleType('comfy_aimdo') + for _submod_name in ('control', 'model_vbar', 'torch', 'host_buffer', 'model_mmap'): + _stub = _AimdoStub() + setattr(_aimdo_pkg, _submod_name, _stub) + sys.modules[f'comfy_aimdo.{_submod_name}'] = _stub + sys.modules['comfy_aimdo'] = _aimdo_pkg + import comfy_aimdo # Now resolves to the stub from sys.modules if enables_dynamic_vram(): comfy_aimdo.control.init()