{"id":2896,"library":"comfy-aimdo","title":"Comfy AIMDO","description":"Comfy AIMDO (AI Model Dynamic Offloader) is a core utility for ComfyUI, acting as a PyTorch VRAM allocator. It implements on-demand offloading of model weights when the primary PyTorch VRAM allocator comes under pressure, aiming to prevent out-of-memory errors and optimize GPU memory usage for AI models. It is currently at version 0.2.12 and is actively maintained as an integral part of the ComfyUI ecosystem.","status":"active","version":"0.2.12","language":"en","source_language":"en","source_url":"https://github.com/Comfy-Org/comfy-aimdo","tags":["ComfyUI","VRAM","memory management","PyTorch","AI models","GPU"],"install":[{"cmd":"pip install comfy-aimdo","lang":"bash","label":"Standard Installation"},{"cmd":"cd ComfyUI_DIRECTORY\nvirtual_env_path\\python.exe -m pip install comfy-aimdo","lang":"bash","label":"Installation within ComfyUI's virtual environment (Windows)"}],"dependencies":[{"reason":"Core PyTorch VRAM allocator and model operations.","package":"torch","optional":false},{"reason":"Comfy AIMDO is designed as a core memory management utility for ComfyUI.","package":"ComfyUI","optional":false},{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"The primary public API is within the 'control' submodule, not the top-level package.","wrong":"import comfy_aimdo","symbol":"control","correct":"import comfy_aimdo.control"}],"quickstart":{"code":"# 1. Ensure Comfy AIMDO is installed (it's often a dependency of ComfyUI).\n# pip install comfy-aimdo\n\n# 2. Launch ComfyUI with dynamic VRAM management enabled.\n# Comfy AIMDO operates as a backend, and its functionality is typically activated\n# by launching ComfyUI with specific flags, rather than direct Python API calls.\n# This example assumes you have ComfyUI installed and its 'main.py' is runnable.\n\nimport subprocess\nimport os\n\n# Path to your ComfyUI directory\ncomfyui_path = os.environ.get('COMFYUI_PATH', './ComfyUI')\n\n# Command to launch ComfyUI with dynamic VRAM (AIMDO) enabled\n# The --enable-dynamic-vram flag tells ComfyUI to utilize comfy-aimdo if detected\ncommand = [\n    os.path.join(comfyui_path, 'python_env/python.exe') if os.name == 'nt' else os.path.join(comfyui_path, 'venv/bin/python'),\n    os.path.join(comfyui_path, 'main.py'),\n    '--enable-dynamic-vram',\n    '--listen' # Optional: listen on all interfaces\n]\n\nprint(f\"Launching ComfyUI with AIMDO: {' '.join(command)}\")\n\ntry:\n    # This will block until ComfyUI exits. For non-blocking, use Popen without .wait()\n    process = subprocess.run(command, check=True, text=True, capture_output=True)\n    print(\"ComfyUI output:\")\n    print(process.stdout)\n    if process.stderr:\n        print(\"ComfyUI errors (if any):\")\n        print(process.stderr)\nexcept FileNotFoundError:\n    print(f\"Error: ComfyUI or its Python environment not found at {comfyui_path}.\")\n    print(\"Please ensure COMFYUI_PATH environment variable is set correctly or adjust the 'comfyui_path' variable.\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error launching ComfyUI: {e}\")\n    print(\"Stderr:\")\n    print(e.stderr)\n    print(\"Stdout:\")\n    print(e.stdout)\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n\nprint(\"ComfyUI launched (or attempted to launch). Check your browser at http://127.0.0.1:8188 (or specified --listen address).\")\n","lang":"python","description":"Comfy AIMDO is a backend VRAM management solution, not typically used directly by end-user Python scripts. Its functionality is integrated into ComfyUI and activated upon launching ComfyUI, often via the `--enable-dynamic-vram` flag. This quickstart demonstrates how to launch ComfyUI to utilize Comfy AIMDO's features. Replace `COMFYUI_PATH` with your actual ComfyUI installation directory."},"warnings":[{"fix":"Manually install or update `comfy-aimdo` within ComfyUI's Python environment (e.g., `path/to/ComfyUI/venv/bin/python -m pip install --upgrade comfy-aimdo` or `path/to/ComfyUI/python_env/python.exe -m pip install --upgrade comfy-aimdo` for portable Windows versions).","message":"After updating ComfyUI, users frequently encounter `ModuleNotFoundError: No module named 'comfy_aimdo'`. This often happens because ComfyUI's update mechanism might not automatically update or install all its core dependencies in the virtual environment.","severity":"gotcha","affected_versions":"All versions when used with ComfyUI updates"},{"fix":"Ensure your PyTorch installation is version 2.8 or newer. Update PyTorch if necessary (e.g., `pip install --upgrade torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu1XX` for CUDA).","message":"Dynamic VRAM support via Comfy AIMDO requires PyTorch version 2.8 or later. Using `--enable-dynamic-vram` with older PyTorch versions (e.g., < 2.8) will result in a fallback to legacy `ModelPatcher`, leading to potentially unreliable VRAM estimates and reduced performance benefits, especially on Windows.","severity":"breaking","affected_versions":"< 0.2.x (when used with PyTorch < 2.8)"},{"fix":"If encountering unexpected PyTorch warnings or recompilation loops, temporarily disable dynamic VRAM by removing the `--enable-dynamic-vram` flag when launching ComfyUI to isolate the issue. Consult ComfyUI and PyTorch documentation/issues for specific workarounds or updates.","message":"Some users have reported 'Torch Dynamo recompilation issues' or warnings from PyTorch when `comfy-aimdo` is active, leading to temporary disabling of AIMDO for troubleshooting. These issues can be subtle and might relate to specific hardware or PyTorch configurations.","severity":"gotcha","affected_versions":"Potentially all versions, depending on system configuration"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}