Skip to content

fix: make comfy_aimdo import optional for AMD/ROCm GPU support#13266

Open
octo-patch wants to merge 1 commit intoComfy-Org:masterfrom
octo-patch:fix/issue-13182-amd-gpu-comfy-aimdo-optional
Open

fix: make comfy_aimdo import optional for AMD/ROCm GPU support#13266
octo-patch wants to merge 1 commit intoComfy-Org:masterfrom
octo-patch:fix/issue-13182-amd-gpu-comfy-aimdo-optional

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #13182

Problem

Since commit f8acd9c40, main.py contains a bare top-level import:

import comfy_aimdo.control

comfy-aimdo is an NVIDIA-specific package for the DynamicVRAM feature. On AMD/ROCm systems (and any other non-NVIDIA setup where it is not installed), this import raises ModuleNotFoundError immediately at startup, preventing ComfyUI from running at all.

The subsequent imports in comfy/ops.py, comfy/model_patcher.py, comfy/pinned_memory.py, and execution.py also reference comfy_aimdo.* at module level, and would fail in turn once the first import is attempted.

Solution

Wrap the import comfy_aimdo.control in a try/except ImportError block. On failure, a minimal no-op stub is installed into sys.modules so that all subsequent import comfy_aimdo.* statements in other modules succeed without requiring changes to those files.

The stub class:

  • Returns _AimdoStub() from all attribute accesses (__getattr__)
  • Returns False (falsy) from all calls (__call__)
  • Implements __bool__, __int__, __float__ returning False/0/0.0

This means:

  • comfy_aimdo.control.init_device(...) returns Falseaimdo_enabled stays False
  • comfy.memory_management.aimdo_enabled remains False (its default value)
  • All existing if comfy.memory_management.aimdo_enabled: guards correctly skip Dynamic VRAM code paths
  • comfy_aimdo.control.get_total_vram_usage() returns 0 (correct for comfy/windows.py RAM calculation)

No other files need to be changed because all actual uses of comfy_aimdo.* functions are already guarded by runtime checks that prevent them from executing when aimdo is not active.

Testing

  • On NVIDIA systems with comfy-aimdo installed, the try branch succeeds and behavior is unchanged.
  • On AMD/ROCm systems without comfy-aimdo, ComfyUI now starts successfully with DynamicVRAM disabled (the existing warning message is preserved via the else branch at line 229).

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 Comfy-Org#13182
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

The main.py file has been modified to handle missing comfy_aimdo package dependencies gracefully. Previously, a direct import of comfy_aimdo.control would fail if the package was not installed. The change introduces a guarded import with error handling that catches ImportError exceptions. When the package is unavailable, an _AimdoStub class is instantiated and stub modules are dynamically injected into sys.modules for comfy_aimdo and its submodules. The stub absorbs attribute access and returns falsy values for calls and boolean checks, allowing runtime code to execute without raising exceptions even when the package is absent.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making the comfy_aimdo import optional to support AMD/ROCm systems where this NVIDIA-specific package is unavailable.
Description check ✅ Passed The description clearly explains the problem (comfy_aimdo import blocking AMD/ROCm systems), the solution (try/except with stub), and testing approach, all directly related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #13182 by wrapping the comfy_aimdo import in try/except and providing a stub module so ComfyUI starts successfully on non-NVIDIA systems without requiring widespread code changes.
Out of Scope Changes check ✅ Passed All changes in main.py are directly scoped to fixing the comfy_aimdo import issue and creating the minimal stub needed; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@main.py`:
- Around line 34-37: The import block for comfy_aimdo.control currently swallows
all ImportError instances; change it so only a missing-module error falls back:
catch ModuleNotFoundError (or catch ImportError as e and re-raise unless e.name
indicates the comfy_aimdo module is missing) for the import of
comfy_aimdo.control and log the "not installed" message only in that case, while
allowing other ImportError failures in comfy_aimdo.control to propagate so
DynamicVRAM does not silently disappear.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d76a5366-8a50-4237-b549-94f0f7f30331

📥 Commits

Reviewing files that changed from the base of the PR and between eb0686b and 8705579.

📒 Files selected for processing (1)
  • main.py

Comment on lines +34 to +37
try:
import comfy_aimdo.control
except ImportError:
logging.info("comfy-aimdo not installed. DynamicVRAM will not be available.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check the git history and diff around main.py to confirm if lines 34-37 are newly introduced
git log --oneline -n 20 main.py 2>/dev/null || echo "Git history unavailable"
git diff HEAD~1 main.py 2>/dev/null | head -100 || echo "Git diff unavailable - checking file directly"

Repository: Comfy-Org/ComfyUI

Length of output: 131


🏁 Script executed:

# Look at the actual main.py file to see the import block and surrounding context
wc -l main.py
head -80 main.py

Repository: Comfy-Org/ComfyUI

Length of output: 2611


🏁 Script executed:

# Search for all uses of comfy_aimdo in the codebase
rg "comfy_aimdo" --type py -n

Repository: Comfy-Org/ComfyUI

Length of output: 2364


🏁 Script executed:

# Search for model_mmap usage specifically
rg "model_mmap\|ModelMMAP" --type py -n -A 2 -B 2

Repository: Comfy-Org/ComfyUI

Length of output: 43


🏁 Script executed:

# Verify Python ImportError.name behavior and availability
python3 << 'EOF'
import sys
print(f"Python version: {sys.version}")

# Test 1: ImportError.name attribute
try:
    import nonexistent_module_xyz
except ImportError as e:
    print(f"ImportError.name: {getattr(e, 'name', 'ATTR_NOT_PRESENT')}")
    print(f"ImportError attributes: {dir(e)}")
    print(f"ImportError str: {str(e)}")

# Test 2: ImportError with submodule
try:
    import os.nonexistent_submod
except ImportError as e:
    print(f"Submodule ImportError.name: {getattr(e, 'name', 'ATTR_NOT_PRESENT')}")
    print(f"Submodule ImportError str: {str(e)}")
EOF

Repository: Comfy-Org/ComfyUI

Length of output: 867


🏁 Script executed:

# Check comfy/utils.py to understand model_mmap usage pattern
sed -n '80,100p' comfy/utils.py

Repository: Comfy-Org/ComfyUI

Length of output: 676


🏁 Script executed:

# Check if there are any guards or conditionals around the model_mmap usage
rg "model_mmap" -B 5 -A 10 comfy/utils.py

Repository: Comfy-Org/ComfyUI

Length of output: 1439


🏁 Script executed:

# Check execution.py to understand how aimdo_enabled guards work
sed -n '530,550p' execution.py

Repository: Comfy-Org/ComfyUI

Length of output: 1329


🏁 Script executed:

# Check if load_safetensors is always called or if there's a guard
rg "load_safetensors" -B 3 -A 3 --type py | head -50

Repository: Comfy-Org/ComfyUI

Length of output: 696


🏁 Script executed:

# Check the full context of comfy/utils.py load_safetensors to see if there's any guard we missed
sed -n '85,120p' comfy/utils.py

Repository: Comfy-Org/ComfyUI

Length of output: 1583


🏁 Script executed:

# Verify if comfy_aimdo.model_mmap is imported conditionally anywhere
rg "aimdo_enabled|comfy_aimdo.model_mmap" --type py -B 2 -A 2

Repository: Comfy-Org/ComfyUI

Length of output: 5693


🏁 Script executed:

# Final check: confirm that when load_safetensors is called, aimdo_enabled must be True
sed -n '100,140p' comfy/utils.py | grep -A 10 -B 5 "load_safetensors"

Repository: Comfy-Org/ComfyUI

Length of output: 839


🏁 Script executed:

# Verify what happens in main.py when aimdo_enabled is set
sed -n '240,260p' main.py

Repository: Comfy-Org/ComfyUI

Length of output: 1214


Only fall back when comfy_aimdo is actually missing.

Line 36 catches every ImportError, so a broken comfy_aimdo.control install on a supported system gets silently reclassified as "not installed" and DynamicVRAM just disappears. Gate the fallback on the missing-module case instead of swallowing all import failures.

Proposed fix
 try:
     import comfy_aimdo.control
-except ImportError:
+except ImportError as e:
+    if getattr(e, "name", None) not in {"comfy_aimdo", "comfy_aimdo.control"}:
+        raise
     logging.info("comfy-aimdo not installed. DynamicVRAM will not be available.")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main.py` around lines 34 - 37, The import block for comfy_aimdo.control
currently swallows all ImportError instances; change it so only a missing-module
error falls back: catch ModuleNotFoundError (or catch ImportError as e and
re-raise unless e.name indicates the comfy_aimdo module is missing) for the
import of comfy_aimdo.control and log the "not installed" message only in that
case, while allowing other ImportError failures in comfy_aimdo.control to
propagate so DynamicVRAM does not silently disappear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComfyUI regression for AMD GPUs since 2026-01-31 (commit f8acd9c40)

1 participant