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
This commit is contained in:
Octopus 2026-04-03 16:00:12 +08:00
parent eb0686bbb6
commit 8705579536

36
main.py
View File

@ -31,7 +31,41 @@ setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
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()