Skip to content

Optimizations

optimizations

Performance optimizations — Step 10.

Installs GPU acceleration libraries from a config-driven package list.

Each package in dependencies.jsonoptimizations.packages[] declares: - requires: environment filters (e.g. ["nvidia", "linux"]) - pypi_package: pip name, optionally per-platform - torch_constraints: version-aware pip specifiers - install_options / retry_options: uv pip install flags

Skipped entirely if no NVIDIA GPU is detected (all current packages require "nvidia" in their requires list).

No external scripts are downloaded or executed.

install_optimizations(python_exe, comfy_path, install_path, deps, log)

Install GPU optimization packages from the config-driven list.

Iterates over deps.optimizations.packages, filters by platform and GPU, and installs each compatible package via uv.

Skipped entirely if no NVIDIA GPU is detected (all current packages require "nvidia").

Parameters:

Name Type Description Default
python_exe Path

Path to the venv Python executable.

required
comfy_path Path

ComfyUI repository directory.

required
install_path Path

Root installation directory.

required
deps DependenciesConfig

Parsed dependencies.json.

required
log InstallerLogger

Installer logger for user-facing messages.

required
Source code in src/installer/optimizations.py
def install_optimizations(
    python_exe: Path,
    comfy_path: Path,
    install_path: Path,
    deps: DependenciesConfig,
    log: InstallerLogger,
) -> None:
    """Install GPU optimization packages from the config-driven list.

    Iterates over ``deps.optimizations.packages``, filters by platform
    and GPU, and installs each compatible package via ``uv``.

    Skipped entirely if no NVIDIA GPU is detected (all current packages
    require ``"nvidia"``).

    Args:
        python_exe: Path to the venv Python executable.
        comfy_path: ComfyUI repository directory.
        install_path: Root installation directory.
        deps: Parsed ``dependencies.json``.
        log: Installer logger for user-facing messages.
    """
    has_nvidia = detect_nvidia_gpu()

    if not has_nvidia:
        log.info("No NVIDIA GPU — skipping GPU optimizations.")
        return

    platform = _get_current_platform()

    # Gather the list of packages from config
    packages: list[OptimizationPackage] = []
    if deps.optimizations:
        packages = deps.optimizations.packages

    if not packages:
        log.info("No optimization packages configured.")
        return

    log.item("Installing GPU optimization packages...")

    # Set CUDA_HOME if available
    cuda_path = os.environ.get("CUDA_PATH")
    if cuda_path:
        os.environ["CUDA_HOME"] = cuda_path

    # Detect torch version once for all packages
    cuda_ver = _get_cuda_version_from_torch(python_exe)
    if cuda_ver:
        log.sub(f"CUDA {cuda_ver} detected from torch.", style="success")
    else:
        log.warning("Could not detect CUDA from torch.", level=2)

    torch_ver = _get_torch_version(python_exe)

    # Install each compatible package
    for pkg in packages:
        if not _check_requirements(
            pkg.requires,
            has_nvidia=has_nvidia,
            platform=platform,
        ):
            log.info(f"{pkg.name}: skipped (requires {pkg.requires}, env={platform}).")
            continue

        _install_package(pkg, python_exe, platform, torch_ver, log)