diff --git a/README.md b/README.md index c473096..df27be4 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ CUDA **12.8** is recommended. git clone https://github.com/tensorforger/FluxRT cd FluxRT "scripts/install.bat" + +# PyTorch with Intel (XPU) support — use this instead of the line above +# "scripts/install_xpu.bat" ``` GUI reqires [OBS](https://obsproject.com/download) to be installed to access virtual webcam. @@ -74,6 +77,9 @@ GUI reqires [OBS](https://obsproject.com/download) to be installed to access vir git clone https://github.com/tensorforger/FluxRT cd FluxRT sh scripts/install.sh + +# PyTorch with Intel (XPU) support — use this instead of the line above +# ./scripts/install_xpu.sh ``` GUI reqires **v4l2loopback** to be installed and loaded to access virtual webcam. @@ -96,9 +102,12 @@ cd FluxRT conda create -n fluxrt python=3.12 pip -y conda activate fluxrt -# Install PyTorch with CUDA support (adjust if needed) +# PyTorch with CUDA support pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128 +# PyTorch with Intel (XPU) support — use this instead of the line above +# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/xpu + # Install project dependencies pip install -r requirements.txt pip install -e . @@ -110,10 +119,15 @@ pip install -e . # Install uv if you don't have it pip install uv -# Create environment and install PyTorch with CUDA support +# Create environment uv venv --python 3.12 + +# PyTorch with CUDA support uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128 +# PyTorch with Intel (XPU) support — use this instead of the line above +# uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/xpu + # Install project dependencies uv pip install -r requirements.txt uv pip install -e . @@ -225,7 +239,14 @@ FluxRT/ ## 4. Run -To enable `int8` quantization you can either add falg `--int8` when running any script or set `enable_int8_quantization` to `true` in the corresponding config. +To enable `int8` quantization you can either add flag `--int8` when running any script or set `enable_int8_quantization` to `true` in the corresponding config. + +To select the compute device, set `"device"` in the config JSON: + +```json +"device": "cuda" // NVIDIA GPU (default) +"device": "xpu" // Intel GPU +``` Run any script with conda environment activated: diff --git a/configs/benchmark_config.json b/configs/benchmark_config.json index 56b44dc..648f4ab 100644 --- a/configs/benchmark_config.json +++ b/configs/benchmark_config.json @@ -9,6 +9,7 @@ "width" : 576 }, "compile_models": true, + "device": "cuda", "enable_spatial_cache": true, "enable_int8_quantization": false, "target_fps":null, diff --git a/configs/config_with_reference.json b/configs/config_with_reference.json index a79691e..c56d61b 100644 --- a/configs/config_with_reference.json +++ b/configs/config_with_reference.json @@ -9,6 +9,7 @@ "width" : 576 }, "compile_models": true, + "device": "cuda", "enable_spatial_cache": true, "enable_int8_quantization": false, "target_fps":null, diff --git a/configs/paint_config.json b/configs/paint_config.json index 082ca5f..4bb3dad 100644 --- a/configs/paint_config.json +++ b/configs/paint_config.json @@ -9,6 +9,7 @@ "width" : 576 }, "compile_models": false, + "device": "cuda", "enable_spatial_cache": true, "enable_int8_quantization": false, "target_fps":null, diff --git a/configs/stream_processor_config.json b/configs/stream_processor_config.json index 1384d6f..463a8b9 100644 --- a/configs/stream_processor_config.json +++ b/configs/stream_processor_config.json @@ -9,6 +9,7 @@ "width" : 576 }, "compile_models": true, + "device": "cuda", "enable_spatial_cache": true, "enable_int8_quantization": false, "target_fps":null, diff --git a/scripts/install_xpu.bat b/scripts/install_xpu.bat new file mode 100644 index 0000000..da62e0d --- /dev/null +++ b/scripts/install_xpu.bat @@ -0,0 +1,211 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +:: FluxRT installation script for Windows. +:: Run from the repository root: scripts\install.bat + +:: ── sanity-check: running from repo root ────────────────────────────────────── +IF NOT EXIST "pyproject.toml" ( + echo [ERROR] This script must be run from the FluxRT repository root. + exit /b 1 +) + +:: ── prerequisites ───────────────────────────────────────────────────────────── +echo [+] Checking prerequisites... + +where git >nul 2>&1 +IF ERRORLEVEL 1 ( + echo [ERROR] 'git' is not installed. Install it from https://git-scm.com/download/win + exit /b 1 +) + +SET UV_DIR=thirdparty +SET UV=%UV_DIR%\uv.exe + +IF EXIST "%UV%" ( + echo [+] uv already present at '%UV%'. +) ELSE ( + echo [!] uv not found. Downloading to '%UV_DIR%'... + IF NOT EXIST "%UV_DIR%" mkdir "%UV_DIR%" + powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "$zip = [System.IO.Path]::GetTempFileName() + '.zip';" ^ + "Invoke-WebRequest -Uri 'https://github.com/astral-sh/uv/releases/latest/download/uv-x86_64-pc-windows-msvc.zip' -OutFile $zip;" ^ + "Expand-Archive $zip -DestinationPath '%UV_DIR%' -Force;" ^ + "Remove-Item $zip" + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to download uv. Check your internet connection and re-run. + exit /b 1 + ) + IF NOT EXIST "%UV%" ( + echo [ERROR] uv.exe not found after extraction. Re-run the script. + exit /b 1 + ) + echo [+] uv installed successfully to '%UV_DIR%'. +) + +git lfs version >nul 2>&1 +IF ERRORLEVEL 1 ( + echo [ERROR] 'git-lfs' is not installed. + echo Install with: winget install GitHub.GitLFS + echo Or download from https://git-lfs.com + exit /b 1 +) + +echo [+] All prerequisites found. + +:: ── uv virtual environment ─────────────────────────────────────────────────── +SET VENV_DIR=fluxrt + +IF EXIST "%VENV_DIR%" ( + echo [+] Virtual environment '%VENV_DIR%' already exists. +) ELSE ( + echo [+] Creating virtual environment '%VENV_DIR%' with python=3.12 via uv... + "%UV%" venv "%VENV_DIR%" --python 3.12 + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to create virtual environment via uv. + exit /b 1 + ) +) + +CALL "%VENV_DIR%\Scripts\activate.bat" +IF ERRORLEVEL 1 ( + echo [ERROR] Failed to activate virtual environment '%VENV_DIR%'. + exit /b 1 +) + +:: ── PyTorch ─────────────────────────────────────────────────────────────────── +python -c "import torch" >nul 2>&1 +IF ERRORLEVEL 1 ( + echo [+] Installing PyTorch with XPU support... + "%UV%" pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/xpu + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to install PyTorch. + exit /b 1 + ) +) ELSE ( + echo [+] PyTorch is already installed. +) + +:: ── Python requirements ─────────────────────────────────────────────────────── +:: Use 'diffusers' as a proxy — it's the heaviest transitive dependency. +python -c "import diffusers" >nul 2>&1 +IF ERRORLEVEL 1 ( + echo [+] Installing Python requirements from requirements.txt... + "%UV%" pip install -r requirements.txt + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to install requirements. + exit /b 1 + ) +) ELSE ( + echo [+] Python requirements already installed. +) + +:: ── triton (Intel XPU backend) ─────────────────────────────────────────────── +:: Intel® XPU Backend for Triton* support for Windows is currently experimental and requires compiling PyTorch and Intel® XPU Backend for Triton* from source. +:: Follow the Windows build guide: +:: https://github.com/intel/intel-xpu-backend-for-triton/blob/main/.github/WINDOWS.md +echo. +echo ============================================================ +echo WARNING: Triton is required for model compilation +echo ============================================================ +echo. +echo Intel XPU Backend for Triton support on Windows is +echo currently experimental and requires compiling PyTorch +echo and Intel XPU Backend for Triton from source. +echo. +echo Windows build guide: +echo https://github.com/intel/intel-xpu-backend-for-triton/blob/main/.github/WINDOWS.md +echo. +echo ============================================================ +echo. + +:: ── fluxrt package ──────────────────────────────────────────────────────────── +python -c "from fluxrt import StreamProcessor" >nul 2>&1 +IF ERRORLEVEL 1 ( + echo [+] Installing fluxrt package in editable mode... + "%UV%" pip install -e . + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to install fluxrt package. + exit /b 1 + ) +) ELSE ( + echo [+] fluxrt package already installed. +) + +:: ── model downloads ─────────────────────────────────────────────────────────── +:: Register LFS hooks for the current user (idempotent). +git lfs install + +:: ── RIFE frame-interpolation model ─────────────────────────────────────────── +SET RIFE_DIR=RIFE-safetensors +SET RIFE_SENTINEL=RIFE-safetensors\flownet.safetensors +IF EXIST "%RIFE_SENTINEL%" ( + echo [+] RIFE frame-interpolation model: already downloaded. +) ELSE IF EXIST "%RIFE_DIR%\.git" ( + echo [!] RIFE: directory exists but looks incomplete — resuming LFS download... + git -C "%RIFE_DIR%" pull --ff-only + git -C "%RIFE_DIR%" lfs pull +) ELSE IF EXIST "%RIFE_DIR%" ( + echo [!] RIFE: '%RIFE_DIR%' exists but is not a git repository. + echo [!] Remove it and re-run to download the model. +) ELSE ( + echo [+] Downloading RIFE frame-interpolation model... + git clone https://huggingface.co/TensorForger/RIFE-safetensors + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to clone RIFE model. + exit /b 1 + ) +) + +:: ── FLUX.2-klein-4B base model ──────────────────────────────────────────────── +SET FLUX_DIR=FLUX.2-klein-4B +SET FLUX_SENTINEL=FLUX.2-klein-4B\transformer\diffusion_pytorch_model.safetensors +IF EXIST "%FLUX_SENTINEL%" ( + echo [+] FLUX.2-klein-4B base model: already downloaded. +) ELSE IF EXIST "%FLUX_DIR%\.git" ( + echo [!] FLUX.2-klein-4B: directory exists but looks incomplete — resuming LFS download... + git -C "%FLUX_DIR%" pull --ff-only + git -C "%FLUX_DIR%" lfs pull +) ELSE IF EXIST "%FLUX_DIR%" ( + echo [!] FLUX.2-klein-4B: '%FLUX_DIR%' exists but is not a git repository. + echo [!] Remove it and re-run to download the model. +) ELSE ( + echo [+] Downloading FLUX.2-klein-4B base model... + git clone https://huggingface.co/black-forest-labs/FLUX.2-klein-4B + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to clone FLUX.2-klein-4B model. + exit /b 1 + ) +) + +:: ── FLUX.2-klein-4B-int8 model ──────────────────────────────────────────────── +SET INT8_DIR=FLUX.2-klein-4B-int8 +SET INT8_SENTINEL=FLUX.2-klein-4B-int8\diffusion_pytorch_model.safetensors +IF EXIST "%INT8_SENTINEL%" ( + echo [+] FLUX.2-klein-4B int8 model: already downloaded. +) ELSE IF EXIST "%INT8_DIR%\.git" ( + echo [!] FLUX.2-klein-4B-int8: directory exists but looks incomplete — resuming LFS download... + git -C "%INT8_DIR%" pull --ff-only + git -C "%INT8_DIR%" lfs pull +) ELSE IF EXIST "%INT8_DIR%" ( + echo [!] FLUX.2-klein-4B-int8: '%INT8_DIR%' exists but is not a git repository. + echo [!] Remove it and re-run to download the model. +) ELSE ( + echo [+] Downloading FLUX.2-klein-4B int8 model... + git clone https://huggingface.co/aydin99/FLUX.2-klein-4B-int8 + IF ERRORLEVEL 1 ( + echo [ERROR] Failed to clone FLUX.2-klein-4B-int8 model. + exit /b 1 + ) +) + +:: ── done ────────────────────────────────────────────────────────────────────── +echo. +echo [+] Installation complete. +echo [!] Note: the GUI requires OBS to be installed for virtual webcam output. +echo [!] Download from https://obsproject.com/download +echo. +echo [+] Activate the environment and start: .\%VENV_DIR%\Scripts\activate +echo [+] Then run, for example: python scripts\run_gradio_demo.py + +ENDLOCAL diff --git a/scripts/install_xpu.sh b/scripts/install_xpu.sh new file mode 100755 index 0000000..9b0adc6 --- /dev/null +++ b/scripts/install_xpu.sh @@ -0,0 +1,135 @@ +#!/bin/bash +# FluxRT installation script. +# Run from the repository root: bash scripts/install.sh +set -euo pipefail + +# ── colours ─────────────────────────────────────────────────────────────────── +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +BOLD='\033[1m' +NC='\033[0m' + +log() { echo -e "${GREEN}[+]${NC} $*"; } +warn() { echo -e "${YELLOW}[!]${NC} $*"; } +die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; } + +# ── sanity-check: running from repo root ────────────────────────────────────── +[ -f "pyproject.toml" ] || die "This script must be run from the FluxRT repository root." + +# ── prerequisites ───────────────────────────────────────────────────────────── +log "Checking prerequisites..." + +command -v git &>/dev/null || die "'git' is not installed. Install with: sudo apt install git" +if ! command -v uv &>/dev/null; then + warn "'uv' not found. Installing automatically..." + if command -v curl &>/dev/null; then + curl -LsSf https://astral.sh/uv/install.sh | sh + elif command -v wget &>/dev/null; then + wget -qO- https://astral.sh/uv/install.sh | sh + else + die "Neither 'curl' nor 'wget' is installed. Install one of them to bootstrap uv." + fi + + # uv is typically installed under ~/.local/bin by the official installer. + export PATH="$HOME/.local/bin:$PATH" + command -v uv &>/dev/null || die "uv installation failed or uv is not on PATH. Add ~/.local/bin to PATH and re-run." + log "uv installed successfully." +fi +git lfs version &>/dev/null || die "'git-lfs' is not installed. Install with: sudo apt install git-lfs" + +log "All prerequisites found." + +# ── uv virtual environment ───────────────────────────────────────────────────────── +VENV_DIR="fluxrt" + +if [ -d "${VENV_DIR}" ]; then + log "Virtual environment '${VENV_DIR}' already exists." +else + log "Creating virtual environment '${VENV_DIR}' (python=3.12) via uv..." + uv venv "${VENV_DIR}" --python 3.12 +fi + +source "${VENV_DIR}/bin/activate" + +# ── PyTorch ─────────────────────────────────────────────────────────────────── +if python -c "import torch" 2>/dev/null; then + log "PyTorch is already installed." +else + log "Installing PyTorch with XPU support..." + uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/xpu +fi + +# ── Python requirements ─────────────────────────────────────────────────────── +# Use 'diffusers' as a proxy — it's the heaviest transitive dependency. +if python -c "import diffusers" 2>/dev/null; then + log "Python requirements already installed." +else + log "Installing Python requirements from requirements.txt..." + uv pip install -r requirements.txt +fi + +# ── fluxrt package ──────────────────────────────────────────────────────────── +if python -c "from fluxrt import StreamProcessor" 2>/dev/null; then + log "fluxrt package already installed." +else + log "Installing fluxrt package in editable mode..." + uv pip install -e . +fi + +# ── model downloads ─────────────────────────────────────────────────────────── +# Register LFS hooks for the current user (idempotent). +git lfs install + +# clone_or_resume