diff --git a/__init__.py b/__init__.py index 94ca94e..c4a73c5 100644 --- a/__init__.py +++ b/__init__.py @@ -80,42 +80,58 @@ def detect_cloud_environment(): # Auto-detect CUDA and install appropriate TensorRT packages def _auto_install_tensorrt(): - """Auto-detect CUDA version and install appropriate TensorRT packages if needed""" - # Check if auto-install is disabled + """Auto-detect CUDA version and install the matching TensorRT wheels. + + The NVIDIA CUDA Toolkit must already be installed on the system. + This function installs only the TensorRT packages via pip. + A marker file prevents repeated install attempts on every ComfyUI startup. + """ disable_auto_install = os.environ.get("DISABLE_TENSORRT_AUTO_INSTALL", "false").lower() == "true" if disable_auto_install: print("[ComfyUI-RIFE-TensorRT] Auto-installation disabled via DISABLE_TENSORRT_AUTO_INSTALL") return True - + + node_dir = Path(__file__).resolve().parent + installed_marker = node_dir / ".tensorrt_auto_installed" + failed_marker = node_dir / ".tensorrt_auto_install_failed" + + # Skip if we already installed successfully in a previous run. + if installed_marker.exists(): + return True + + # Avoid retrying too often after a failure (do not block every startup). + if failed_marker.exists(): + try: + last_fail = failed_marker.stat().st_mtime + if time.time() - last_fail < 3600: + print("[ComfyUI-RIFE-TensorRT] Recent failed install attempt; skipping auto-install.") + return False + except Exception: + pass + try: - # Check if TensorRT is already installed - with retry mechanism - max_retries = 3 - for attempt in range(max_retries): - try: - import tensorrt - print(f"✅ TensorRT already installed (version: {tensorrt.__version__})") - return True - except ImportError: - if attempt < max_retries - 1: - print(f"🔍 TensorRT not found (attempt {attempt + 1}/{max_retries}), waiting 2 seconds...") - time.sleep(2) # Wait for potential concurrent installation - else: - print("🔍 TensorRT not found after retries, detecting CUDA version...") - + # Check if TensorRT is already installed. + try: + import tensorrt + print(f"[ComfyUI-RIFE-TensorRT] TensorRT already installed (version: {tensorrt.__version__})") + installed_marker.touch() + return True + except ImportError: + print("[ComfyUI-RIFE-TensorRT] TensorRT not found, detecting CUDA version...") + # Detect CUDA version cuda_version = None - + # Try PyTorch CUDA version first (most reliable on cloud platforms) try: - import torch if hasattr(torch, 'version') and hasattr(torch.version, 'cuda'): pytorch_cuda = torch.version.cuda if pytorch_cuda: cuda_version = pytorch_cuda - print(f"✅ Detected CUDA version from PyTorch: {cuda_version}") + print(f"[ComfyUI-RIFE-TensorRT] Detected CUDA version from PyTorch: {cuda_version}") except Exception as e: - print(f"⚠️ Could not detect CUDA from PyTorch: {e}") - + print(f"[ComfyUI-RIFE-TensorRT] Could not detect CUDA from PyTorch: {e}") + # Try nvcc command as fallback if not cuda_version: try: @@ -124,81 +140,91 @@ def _auto_install_tensorrt(): match = re.search(r"release (\d+\.\d+)", result.stdout) if match: cuda_version = match.group(1) - print(f"✅ Detected CUDA version from nvcc: {cuda_version}") - except: + print(f"[ComfyUI-RIFE-TensorRT] Detected CUDA version from nvcc: {cuda_version}") + except Exception: pass - + # Try CUDA_PATH if not cuda_version and os.environ.get("CUDA_PATH"): nvcc_path = os.path.join(os.environ["CUDA_PATH"], "bin", "nvcc") if os.path.exists(nvcc_path): try: - result = subprocess.run(f"{nvcc_path} --version", shell=True, capture_output=True, text=True) + result = subprocess.run(f'"{nvcc_path}" --version', shell=True, capture_output=True, text=True) if result.returncode == 0: match = re.search(r"release (\d+\.\d+)", result.stdout) if match: cuda_version = match.group(1) - print(f"✅ Detected CUDA via CUDA_PATH: {cuda_version}") - except: + print(f"[ComfyUI-RIFE-TensorRT] Detected CUDA via CUDA_PATH: {cuda_version}") + except Exception: pass - + # Try CUDA_HOME if not cuda_version and os.environ.get("CUDA_HOME"): nvcc_path = os.path.join(os.environ["CUDA_HOME"], "bin", "nvcc") if os.path.exists(nvcc_path): try: - result = subprocess.run(f"{nvcc_path} --version", shell=True, capture_output=True, text=True) + result = subprocess.run(f'"{nvcc_path}" --version', shell=True, capture_output=True, text=True) if result.returncode == 0: match = re.search(r"release (\d+\.\d+)", result.stdout) if match: cuda_version = match.group(1) - print(f"✅ Detected CUDA via CUDA_HOME: {cuda_version}") - except: + print(f"[ComfyUI-RIFE-TensorRT] Detected CUDA via CUDA_HOME: {cuda_version}") + except Exception: pass - + if not cuda_version: - print("⚠️ Could not detect CUDA version automatically") - print("Please run 'python install.py' manually to install TensorRT") + print("[ComfyUI-RIFE-TensorRT] WARNING: Could not detect CUDA version automatically.") + print("The NVIDIA CUDA Toolkit must be installed before TensorRT can work.") + print("Please run 'python install.py' manually after installing CUDA.") + failed_marker.touch() return False - - # Install appropriate TensorRT packages + major_version = int(cuda_version.split('.')[0]) - + if major_version == 13: - print("🚀 Installing CUDA 13 TensorRT packages (RTX 50 series)") - packages = [ - "tensorrt_cu13==10.15.1.29", - "tensorrt_cu13_bindings==10.15.1.29", - "tensorrt_cu13_libs==10.15.1.29", - "cuda-toolkit>=13.0.0,<13.1.0" - ] + print("[ComfyUI-RIFE-TensorRT] Installing CUDA 13 TensorRT packages (RTX 50 series)") + req_file = "requirements_cu13.txt" elif major_version == 12: - print("🔧 Installing CUDA 12 TensorRT packages (RTX 30/40 series)") - packages = [ - "tensorrt-cu12==10.13.3.9", - "tensorrt-cu12-libs==10.13.3.9", - "tensorrt-cu12-bindings==10.13.3.9", - "cuda-toolkit>=12.8.0,<13.0.0" - ] + print("[ComfyUI-RIFE-TensorRT] Installing CUDA 12 TensorRT packages (RTX 30/40 series)") + req_file = "requirements_cu12.txt" else: - print(f"❌ Unsupported CUDA version: {cuda_version}") + print(f"[ComfyUI-RIFE-TensorRT] Unsupported CUDA version: {cuda_version}") + failed_marker.touch() return False - - # Install packages - for package in packages: - print(f"Installing {package}...") - result = subprocess.run([sys.executable, "-m", "pip", "install", package], capture_output=True) + + req_path = node_dir / req_file + if not req_path.exists(): + print(f"[ComfyUI-RIFE-TensorRT] Missing requirements file: {req_path}") + failed_marker.touch() + return False + + # Install base dependencies first, then the CUDA-specific TensorRT wheels. + for req_name in ["requirements.txt", req_file]: + req_file_path = node_dir / req_name + if not req_file_path.exists(): + continue + print(f"[ComfyUI-RIFE-TensorRT] Installing from {req_name}...") + result = subprocess.run( + [sys.executable, "-m", "pip", "install", "--prefer-binary", "-r", str(req_file_path)], + capture_output=True + ) if result.returncode != 0: - print(f"❌ Failed to install {package}") - print(f"Error: {result.stderr.decode()}") + print(f"[ComfyUI-RIFE-TensorRT] Failed to install {req_name}") + print(result.stderr.decode(errors="replace")) + failed_marker.touch() return False - - print("✅ TensorRT installation completed successfully!") + + installed_marker.touch() + print("[ComfyUI-RIFE-TensorRT] TensorRT installation completed successfully!") return True - + except Exception as e: - print(f"❌ Auto-installation failed: {e}") + print(f"[ComfyUI-RIFE-TensorRT] Auto-installation failed: {e}") print("Please run 'python install.py' manually to install TensorRT") + try: + failed_marker.touch() + except Exception: + pass return False # Run auto-install on module import diff --git a/install.bat b/install.bat index f933544..83c729c 100644 --- a/install.bat +++ b/install.bat @@ -1,31 +1,33 @@ @echo off -REM Auto-install script for ComfyUI RIFE TensorRT (Windows) -REM Detects CUDA version and installs appropriate requirements +REM Auto-install script for ComfyUI RIFE TensorRT Auto (Windows) +REM Detects CUDA version and installs only the matching TensorRT wheels. +REM The NVIDIA CUDA Toolkit must already be installed on the system. +setlocal EnableDelayedExpansion -echo 🔍 Detecting CUDA version... +echo Detecting CUDA version... REM Try to detect CUDA version set CUDA_VERSION= where nvcc >nul 2>nul if %ERRORLEVEL% EQU 0 ( for /f "tokens=6 delims=, " %%i in ('nvcc --version ^| findstr "release"') do set CUDA_VERSION=%%i - echo ✅ Found CUDA version: %CUDA_VERSION% + echo Found CUDA version: %CUDA_VERSION% ) else if defined CUDA_PATH ( if exist "%CUDA_PATH%\bin\nvcc.exe" ( for /f "tokens=6 delims=, " %%i in ('"%CUDA_PATH%\bin\nvcc.exe" --version ^| findstr "release"') do set CUDA_VERSION=%%i - echo ✅ Found CUDA version via CUDA_PATH: %CUDA_VERSION% + echo Found CUDA version via CUDA_PATH: %CUDA_VERSION% ) ) else if defined CUDA_HOME ( if exist "%CUDA_HOME%\bin\nvcc.exe" ( for /f "tokens=6 delims=, " %%i in ('"%CUDA_HOME%\bin\nvcc.exe" --version ^| findstr "release"') do set CUDA_VERSION=%%i - echo ✅ Found CUDA version via CUDA_HOME: %CUDA_VERSION% + echo Found CUDA version via CUDA_HOME: %CUDA_VERSION% ) ) if "%CUDA_VERSION%"=="" ( - echo ⚠️ Could not detect CUDA version automatically - echo Please ensure CUDA is installed and nvcc is in your PATH - echo Or set CUDA_PATH or CUDA_HOME environment variables + echo Could not detect CUDA version automatically. + echo Please ensure the NVIDIA CUDA Toolkit is installed and nvcc is in your PATH, + echo or set CUDA_PATH / CUDA_HOME. pause exit /b 1 ) @@ -33,27 +35,29 @@ if "%CUDA_VERSION%"=="" ( REM Extract major version for /f "tokens=1 delims=." %%i in ("%CUDA_VERSION%") do set CUDA_MAJOR=%%i -echo 📦 Installing requirements for CUDA %CUDA_MAJOR%... +echo Installing requirements for CUDA %CUDA_MAJOR%... REM Install appropriate requirements based on CUDA version if "%CUDA_MAJOR%"=="13" ( - echo 🚀 Using CUDA 13 requirements ^(RTX 50 series^) - pip install -r requirements.txt + echo Using CUDA 13 TensorRT packages ^(RTX 50 series^) + python -m pip install --prefer-binary -r requirements.txt + python -m pip install --prefer-binary -r requirements_cu13.txt ) else if "%CUDA_MAJOR%"=="12" ( - echo 🔧 Using CUDA 12 requirements ^(RTX 30/40 series^) - pip install -r requirements_cu12.txt + echo Using CUDA 12 TensorRT packages ^(RTX 30/40 series^) + python -m pip install --prefer-binary -r requirements.txt + python -m pip install --prefer-binary -r requirements_cu12.txt ) else ( - echo ❌ Unsupported CUDA version: %CUDA_VERSION% + echo Unsupported CUDA version: %CUDA_VERSION% echo Supported versions: CUDA 12.x, CUDA 13.x pause exit /b 1 ) if %ERRORLEVEL% EQU 0 ( - echo ✅ Installation completed successfully! - echo 🎯 You can now use the ComfyUI RIFE TensorRT node + echo Installation completed successfully! + echo You can now use the ComfyUI RIFE TensorRT Auto node. ) else ( - echo ❌ Installation failed! + echo Installation failed! pause exit /b 1 ) diff --git a/install.py b/install.py index 91c962c..a5ca8aa 100755 --- a/install.py +++ b/install.py @@ -1,102 +1,121 @@ #!/usr/bin/env python3 """ -Auto-install script for ComfyUI RIFE TensorRT -Detects CUDA version and installs appropriate requirements +Auto-install script for ComfyUI RIFE TensorRT Auto. +Detects the local CUDA version and installs only the matching TensorRT wheels. +The NVIDIA CUDA Toolkit must already be installed on the system. """ import subprocess import sys import os import re +from pathlib import Path + +SCRIPT_DIR = Path(__file__).resolve().parent + def run_command(cmd): - """Run command and return output""" + """Run a shell command and return stdout + return code.""" try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True) return result.stdout.strip(), result.returncode except Exception as e: return "", 1 + def detect_cuda_version(): - """Detect CUDA version""" - print("🔍 Detecting CUDA version...") - + """Detect CUDA version from nvcc, CUDA_PATH or CUDA_HOME.""" + print("Detecting CUDA version...") + # Try nvcc command stdout, returncode = run_command("nvcc --version") if returncode == 0: match = re.search(r"release (\d+\.\d+)", stdout) if match: version = match.group(1) - print(f"✅ Found CUDA version: {version}") + print(f"Found CUDA version: {version}") return version - + # Try CUDA_PATH cuda_path = os.environ.get("CUDA_PATH") if cuda_path: nvcc_path = os.path.join(cuda_path, "bin", "nvcc") if os.path.exists(nvcc_path): - stdout, returncode = run_command(f"{nvcc_path} --version") + stdout, returncode = run_command(f'"{nvcc_path}" --version') if returncode == 0: match = re.search(r"release (\d+\.\d+)", stdout) if match: version = match.group(1) - print(f"✅ Found CUDA version via CUDA_PATH: {version}") + print(f"Found CUDA version via CUDA_PATH: {version}") return version - + # Try CUDA_HOME cuda_home = os.environ.get("CUDA_HOME") if cuda_home: nvcc_path = os.path.join(cuda_home, "bin", "nvcc") if os.path.exists(nvcc_path): - stdout, returncode = run_command(f"{nvcc_path} --version") + stdout, returncode = run_command(f'"{nvcc_path}" --version') if returncode == 0: match = re.search(r"release (\d+\.\d+)", stdout) if match: version = match.group(1) - print(f"✅ Found CUDA version via CUDA_HOME: {version}") + print(f"Found CUDA version via CUDA_HOME: {version}") return version - - print("⚠️ Could not detect CUDA version automatically") - print("Please ensure CUDA is installed and nvcc is in your PATH") - print("Or set CUDA_PATH or CUDA_HOME environment variables") + + print("Could not detect CUDA version automatically.") + print("Please ensure the NVIDIA CUDA Toolkit is installed and nvcc is in your PATH,") + print("or set CUDA_PATH / CUDA_HOME.") return None + def install_requirements(cuda_version): - """Install appropriate requirements based on CUDA version""" + """Install the correct TensorRT packages for the detected CUDA version.""" major_version = int(cuda_version.split('.')[0]) - - print(f"📦 Installing requirements for CUDA {major_version}...") - + print(f"Installing requirements for CUDA {major_version}...") + if major_version == 13: - print("🚀 Using CUDA 13 requirements (RTX 50 series)") - requirements_file = "requirements.txt" + print("Using CUDA 13 TensorRT packages (RTX 50 series)") + req_file = "requirements_cu13.txt" elif major_version == 12: - print("🔧 Using CUDA 12 requirements (RTX 30/40 series)") - requirements_file = "requirements_cu12.txt" + print("Using CUDA 12 TensorRT packages (RTX 30/40 series)") + req_file = "requirements_cu12.txt" else: - print(f"❌ Unsupported CUDA version: {cuda_version}") + print(f"Unsupported CUDA version: {cuda_version}") print("Supported versions: CUDA 12.x, CUDA 13.x") return False - - # Install requirements - returncode = subprocess.run([sys.executable, "-m", "pip", "install", "-r", requirements_file]).returncode - - if returncode == 0: - print("✅ Installation completed successfully!") - print("🎯 You can now use the ComfyUI RIFE TensorRT node") - return True - else: - print("❌ Installation failed!") + + req_path = SCRIPT_DIR / req_file + if not req_path.exists(): + print(f"Missing requirements file: {req_path}") return False + # Install base dependencies first, then the CUDA-specific TensorRT wheels. + # Using a single pip call per file lets pip resolve and cache dependencies efficiently. + for req_name in ["requirements.txt", req_file]: + req_file_path = SCRIPT_DIR / req_name + if not req_file_path.exists(): + continue + print(f"Installing from {req_name}...") + result = subprocess.run( + [sys.executable, "-m", "pip", "install", "--prefer-binary", "-r", str(req_file_path)] + ) + if result.returncode != 0: + print(f"Failed to install {req_name}") + return False + + print("Installation completed successfully!") + print("You can now use the ComfyUI RIFE TensorRT Auto node.") + return True + + def main(): - """Main installation function""" cuda_version = detect_cuda_version() if not cuda_version: sys.exit(1) - + success = install_requirements(cuda_version) sys.exit(0 if success else 1) + if __name__ == "__main__": main() diff --git a/install.sh b/install.sh index 33768eb..6fe52b7 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,9 @@ #!/bin/bash -# FALLBACK install script for ComfyUI RIFE TensorRT -# +# FALLBACK install script for ComfyUI RIFE TensorRT Auto (Linux/macOS) +# # NOTE: This is a BACKUP script - auto-installation is recommended! -# +# # PRIMARY METHOD (Recommended): # 1. pip install -r requirements.txt # 2. Restart ComfyUI @@ -11,9 +11,12 @@ # # Use this script ONLY if auto-installation fails! # +# The NVIDIA CUDA Toolkit must already be installed on the system. +# This script installs only the matching TensorRT wheels via pip. +# -echo "⚠️ FALLBACK INSTALLATION - Use only if auto-installation fails!" -echo "🔍 Detecting CUDA version..." +echo "FALLBACK INSTALLATION - Use only if auto-installation fails!" +echo "Detecting CUDA version..." # Try to detect CUDA version CUDA_VERSION="" @@ -40,28 +43,28 @@ echo "📦 Installing requirements for CUDA $CUDA_MAJOR..." # Install appropriate requirements based on CUDA version if [ "$CUDA_MAJOR" = "13" ]; then - echo "🚀 Installing CUDA 13 requirements (RTX 50 series)" - echo "📦 Installing base dependencies + CUDA 13 TensorRT..." - pip install -r requirements.txt - echo "📦 Installing CUDA 13 specific TensorRT packages..." - pip install -r requirements_cu13.txt + echo "Installing CUDA 13 requirements (RTX 50 series)" + echo "Installing base dependencies + CUDA 13 TensorRT..." + python3 -m pip install --prefer-binary -r requirements.txt + echo "Installing CUDA 13 specific TensorRT packages..." + python3 -m pip install --prefer-binary -r requirements_cu13.txt elif [ "$CUDA_MAJOR" = "12" ]; then - echo "🔧 Installing CUDA 12 requirements (RTX 30/40 series)" - echo "📦 Installing base dependencies + CUDA 12 TensorRT..." - pip install -r requirements.txt - echo "📦 Installing CUDA 12 specific TensorRT packages..." - pip install -r requirements_cu12.txt + echo "Installing CUDA 12 requirements (RTX 30/40 series)" + echo "Installing base dependencies + CUDA 12 TensorRT..." + python3 -m pip install --prefer-binary -r requirements.txt + echo "Installing CUDA 12 specific TensorRT packages..." + python3 -m pip install --prefer-binary -r requirements_cu12.txt else - echo "❌ Unsupported CUDA version: $CUDA_VERSION" + echo "Unsupported CUDA version: $CUDA_VERSION" echo "Supported versions: CUDA 12.x, CUDA 13.x" exit 1 fi if [ $? -eq 0 ]; then - echo "✅ Fallback installation completed!" - echo "🎯 You can now use ComfyUI RIFE TensorRT node" - echo "💡 In the future, try auto-installation by just installing requirements.txt" + echo "Fallback installation completed!" + echo "You can now use ComfyUI RIFE TensorRT Auto node" + echo "In the future, try auto-installation by just installing requirements.txt" else - echo "❌ Installation failed!" + echo "Installation failed!" exit 1 fi diff --git a/pyproject.toml b/pyproject.toml index c7ce2ae..93500c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,10 @@ version = "1.1.1" license = { file = "LICENSE" } [project.urls] -Repository = "https://github.com/silveroxides/ComfyUI_RIFE_TensorRT_Auto" +Repository = "https://github.com/huchukato/ComfyUI-RIFE-TensorRT-Auto" # Used by Comfy Registry https://comfyregistry.org [tool.comfy] -PublisherId = "silveroxides" +PublisherId = "huchukato" DisplayName = "ComfyUI_RIFE_TensorRT_Auto" Icon = "" diff --git a/requirements.txt b/requirements.txt index 12ad39b..248531e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # Base dependencies - TensorRT will be auto-installed based on CUDA detection -# The node will automatically detect CUDA 12/13 and install appropriate TensorRT packages -# +# The node will automatically detect CUDA 12/13 and install appropriate TensorRT packages. +# The NVIDIA CUDA Toolkit must already be installed on the system; it is NOT installed via pip. +# # Installation happens automatically when the node loads for the first time # No manual TensorRT installation required! diff --git a/requirements_cu12.txt b/requirements_cu12.txt index 0bad360..f8319b1 100644 --- a/requirements_cu12.txt +++ b/requirements_cu12.txt @@ -1,12 +1,9 @@ -# CUDA 12 specific packages (RTX 30/40 series, CUDA 12.x) -# -# NOTE: This file is for REFERENCE ONLY - manual installation -# The recommended method is AUTO-INSTALLATION via the node: -# - Just install requirements.txt and restart ComfyUI -# - The node will auto-detect CUDA and install TensorRT automatically +# CUDA 12 specific TensorRT packages (RTX 30/40 series, CUDA 12.x) # -# Use this file ONLY if auto-installation fails or for manual setup +# NOTE: cuda-toolkit is NOT installed via pip. Install the NVIDIA CUDA Toolkit separately if needed. +# The node will auto-detect CUDA 12 and install these packages automatically. # +# Use this file ONLY if auto-installation fails or for manual setup. # Installation order for MANUAL setup only: # 1. pip install -r requirements.txt (base dependencies) # 2. pip install -r requirements_cu12.txt (CUDA 12 specific TensorRT) @@ -14,4 +11,3 @@ tensorrt-cu12==10.13.3.9 tensorrt-cu12-libs==10.13.3.9 tensorrt-cu12-bindings==10.13.3.9 -cuda-toolkit>=12.8.0,<13.0.0 diff --git a/requirements_cu13.txt b/requirements_cu13.txt index 61d8196..2d81521 100644 --- a/requirements_cu13.txt +++ b/requirements_cu13.txt @@ -1,12 +1,9 @@ -# CUDA 13 specific packages (RTX 50 series, CUDA 13.x) -# -# NOTE: This file is for REFERENCE ONLY - manual installation -# The recommended method is AUTO-INSTALLATION via the node: -# - Just install requirements.txt and restart ComfyUI -# - The node will auto-detect CUDA and install TensorRT automatically +# CUDA 13 specific TensorRT packages (RTX 50 series, CUDA 13.x) # -# Use this file ONLY if auto-installation fails or for manual setup +# NOTE: cuda-toolkit is NOT installed via pip. Install the NVIDIA CUDA Toolkit separately if needed. +# The node will auto-detect CUDA 13 and install these packages automatically. # +# Use this file ONLY if auto-installation fails or for manual setup. # Installation order for MANUAL setup only: # 1. pip install -r requirements.txt (base dependencies) # 2. pip install -r requirements_cu13.txt (CUDA 13 specific TensorRT) @@ -14,4 +11,3 @@ tensorrt_cu13==10.15.1.29 tensorrt_cu13_bindings==10.15.1.29 tensorrt_cu13_libs==10.15.1.29 -cuda-toolkit>=13.0.0,<13.1.0