Comfy AIMDO

0.2.12 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

# 1. Ensure Comfy AIMDO is installed (it's often a dependency of ComfyUI).
# pip install comfy-aimdo

# 2. Launch ComfyUI with dynamic VRAM management enabled.
# Comfy AIMDO operates as a backend, and its functionality is typically activated
# by launching ComfyUI with specific flags, rather than direct Python API calls.
# This example assumes you have ComfyUI installed and its 'main.py' is runnable.

import subprocess
import os

# Path to your ComfyUI directory
comfyui_path = os.environ.get('COMFYUI_PATH', './ComfyUI')

# Command to launch ComfyUI with dynamic VRAM (AIMDO) enabled
# The --enable-dynamic-vram flag tells ComfyUI to utilize comfy-aimdo if detected
command = [
    os.path.join(comfyui_path, 'python_env/python.exe') if os.name == 'nt' else os.path.join(comfyui_path, 'venv/bin/python'),
    os.path.join(comfyui_path, 'main.py'),
    '--enable-dynamic-vram',
    '--listen' # Optional: listen on all interfaces
]

print(f"Launching ComfyUI with AIMDO: {' '.join(command)}")

try:
    # This will block until ComfyUI exits. For non-blocking, use Popen without .wait()
    process = subprocess.run(command, check=True, text=True, capture_output=True)
    print("ComfyUI output:")
    print(process.stdout)
    if process.stderr:
        print("ComfyUI errors (if any):")
        print(process.stderr)
except FileNotFoundError:
    print(f"Error: ComfyUI or its Python environment not found at {comfyui_path}.")
    print("Please ensure COMFYUI_PATH environment variable is set correctly or adjust the 'comfyui_path' variable.")
except subprocess.CalledProcessError as e:
    print(f"Error launching ComfyUI: {e}")
    print("Stderr:")
    print(e.stderr)
    print("Stdout:")
    print(e.stdout)
except Exception as e:
    print(f"An unexpected error occurred: {e}")

print("ComfyUI launched (or attempted to launch). Check your browser at http://127.0.0.1:8188 (or specified --listen address).")

view raw JSON →