#!/usr/bin/env bash # ~/.local/bin/updateai # updateai — CachyOS dual ComfyUI + llama.cpp + OneTrainer # rocm : ComfyUI ROCm → ${HOME}/ai/rocm # vulkan : llama.cpp Vulkan (AMD or Intel) → ${HOME}/ai/vulkan # xpu : ComfyUI XPU + llama.cpp SYCL → ${HOME}/ai/xpu # onetrainer : OneTrainer XPU (PR 1413) → ${HOME}/ai/onetrainer # Runtime: CachyOS, uv, no containers. # Requires: bash ccache git cmake curl git makepkg shaderc # intel-compute-runtime sudo uv spirv-header vulkan-headers # Local oneAPI toolkit: ${HOME}/intel/oneapi (installed separately). set -euo pipefail readonly BASEDIR="${HOME}/ai" readonly CACHE_DIR="${BASEDIR}/cache" readonly PYTHON_VER="3.13" readonly UV_INSTALL_URL="https://astral.sh/uv/install.sh" # Updated 2026-11-16: ROCm tarball and PyTorch index migrated to nightly.repo.amd.com (ROCm 10.x alignment for gfx120X) readonly ROCM_PATH="/opt/rocm" readonly ROCM_NIGHTLY_INDEX="https://nightly.repo.amd.com/rocm/whl-next/" readonly ROCM_TARBALL_BASE="https://nightly.repo.amd.com/rocm/core/tarball" readonly PYTORCH_XPU_INDEX="https://download.pytorch.org/whl/nightly/xpu" readonly PYTORCH_XPU_STABLE_INDEX="https://download.pytorch.org/whl/xpu" readonly ONETRAINER_REPO="https://github.com/Nerogar/OneTrainer.git" readonly ONETRAINER_DIR="${BASEDIR}/onetrainer" readonly ONETRAINER_PR="1413" readonly ONETRAINER_DIFFUSERS_REF="1ffa423" readonly ONETRAINER_MGDS_REF="3a6994a" readonly ONETRAINER_MUON_REF="f90a42b" readonly LLAMA_CPP_REPO="https://github.com/ggml-org/llama.cpp.git" readonly LLAMA_SRC_DIR="${BASEDIR}/src/ggml-org/llama.cpp" readonly XPU_DIR="${BASEDIR}/xpu" readonly XPU_OPENCL_VENDOR_DIR="${XPU_DIR}/opencl-vendors" readonly INTEL_OPENCL_ICD_FILE="/etc/OpenCL/vendors/intel.icd" readonly ONEAPI_DIR="${HOME}/intel/oneapi" readonly ONEAPI_SETVARS="${ONEAPI_DIR}/setvars.sh" readonly UNIT_DIR="${HOME}/.config/systemd/user" readonly APP_DIR="${HOME}/.local/share/applications" readonly LLM_MODELS_DIR="${BASEDIR}/models/llm" readonly LLM_AUX_DIR="${BASEDIR}/models/llm_aux" readonly LLM_PRESETS_DIR="${BASEDIR}/models/llm_presets" readonly LLM_PRESET_FILE_16GB="${LLM_PRESETS_DIR}/16gb.ini" readonly LLM_PRESET_FILE_32GB="${LLM_PRESETS_DIR}/32gb.ini" readonly LLM_PRESET_FILE_SYSTEM_PROMPT_EN="${LLM_PRESETS_DIR}/system_prompt_en.txt" readonly LLM_PRESET_FILE_SYSTEM_PROMPT_FI="${LLM_PRESETS_DIR}/system_prompt_fi.txt" readonly LLM_PRESET_FILE_ONETRAINER_APP="${APP_DIR}/OneTrainer.desktop" readonly VULKAN_DIR="${BASEDIR}/vulkan" readonly RADEON_ICD="/usr/share/vulkan/icd.d/radeon_icd.x86_64.json" readonly INTEL_ICD="/usr/share/vulkan/icd.d/intel_icd.x86_64.json" VULKAN_ICD="${VULKAN_ICD:-${RADEON_ICD}}" VULKAN_PRESET="${VULKAN_PRESET:-${LLM_PRESET_FILE_16GB}}" readonly REPOS=( "https://github.com/Acly/comfyui-inpaint-nodes comfyui_inpaint_nodes" "https://github.com/Acly/comfyui-tooling-nodes comfyui_tooling_nodes" "https://github.com/AIToldMeTo/comfyui-cache-cleaner comfyui_cache_cleaner" "https://github.com/alexopus/ComfyUI-Image-Saver comfyui_image_saver" "https://github.com/Azornes/Comfyui-Resolution-Master comfyui_resolution_master" "https://github.com/BadCafeCode/masquerade-nodes-comfyui masquerade_nodes_comfyui" "https://github.com/bbaudio-2025/Comfyui-MMH3-UltimateUpscale comfyui_mmh3_ultimateupscale" "https://github.com/Billy024/comfyui-aspect-ratio-crop-node comfyui_aspect_ratio_crop_node" "https://github.com/chflame163/ComfyUI_LayerStyle comfyui_layerstyle" "https://github.com/chrisgoringe/cg-use-everywhere cg_use_everywhere" "https://github.com/city96/ComfyUI-GGUF comfyui_gguf" "https://github.com/ClownsharkBatwing/RES4LYF res4lyf" "https://github.com/crystian/ComfyUI-Crystools comfyui_crystools" "https://github.com/cubiq/ComfyUI_essentials comfyui_essentials" "https://github.com/cubiq/ComfyUI_IPAdapter_plus comfyui_ipadapter_plus" "https://github.com/darksidewalker/ComfyUI-DaSiWa-Nodes comfyui_dasiwa_nodes" "https://github.com/DoctorDiffusion/ComfyUI-MediaMixer comfyui_mediamixer" "https://github.com/Fannovel16/comfyui_controlnet_aux comfyui_controlnet_aux" "https://github.com/Fannovel16/ComfyUI-Frame-Interpolation comfyui_frame_interpolation" "https://github.com/JPS-GER/ComfyUI_JPS-Nodes comfyui_jps_nodes" "https://github.com/kijai/ComfyUI-KJNodes comfyui_kjnodes" "https://github.com/kijai/ComfyUI-MelBandRoFormer comfyui_melbandroformer" "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite comfyui_videohelpersuite" "https://github.com/LAOGOU-666/Comfyui-Memory_Cleanup comfyui_memory_cleanup" "https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui_impact_pack" "https://github.com/ltdrdata/ComfyUI-Impact-Subpack comfyui_impact_subpack" "https://github.com/ltdrdata/ComfyUI-Manager comfyui_manager" "https://github.com/orssorbit/ComfyUI-wanBlockswap comfyui_wanblockswap" "https://github.com/PlagueKind/ComfyUI-PlagueKind-Nodes comfyui_plaguekind_nodes" "https://github.com/pythongosssss/ComfyUI-Custom-Scripts comfyui_custom_scripts" "https://github.com/rgthree/rgthree-comfy rgthree_comfy" "https://github.com/SeanScripts/ComfyUI-Unload-Model comfyui_unload_model" "https://github.com/Smirnov75/ComfyUI-mxToolkit comfyui_mxtoolkit" "https://github.com/tritant/ComfyUI_Custom_Switch comfyui_custom_switch" "https://github.com/WASasquatch/was-node-suite-comfyui was_node_suite_comfyui" "https://github.com/yolain/ComfyUI-Easy-Use comfyui_easy_use" ) start_time=${SECONDS} CMAKE_GENERATOR_ARGS=() NOTES=() log() { printf '\n=== %s ===\n\n' "$*"; } die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } note() { NOTES+=("$1"); } print_notes() { local n for n in "${NOTES[@]}"; do printf '\n%s\n' "$n" done } ensure_uv() { export PATH="${HOME}/.local/bin:${PATH}" if command -v uv >/dev/null 2>&1; then log "uv already installed ($(uv --version 2>/dev/null || echo unknown))" return 0 fi log "Installing uv" curl -LsSf "${UV_INSTALL_URL}" | sh export PATH="${HOME}/.local/bin:${PATH}" } stop_service() { systemctl --user daemon-reload >/dev/null 2>&1 || true systemctl --user stop "$1" >/dev/null 2>&1 || true } enable_units() { mkdir -p "${UNIT_DIR}" systemctl --user daemon-reload } clean_base() { log "Completely reinstalling $1" rm -rf "$1" mkdir -p "$1" } clean_xpu_base() { local basedir_xpu=$1 log "Completely reinstalling ${basedir_xpu} (preserving ${ONEAPI_DIR})" mkdir -p "${basedir_xpu}" find "${basedir_xpu}" -mindepth 1 -maxdepth 1 \ ! -name "$(basename "${ONEAPI_DIR}")" \ -exec rm -rf -- {} + } ensure_shared_dirs() { local -a dirs=( "${BASEDIR}/input" "${BASEDIR}/output" "${BASEDIR}/user" "${BASEDIR}/models" "${LLM_MODELS_DIR}" "${LLM_AUX_DIR}" "${LLM_PRESETS_DIR}" "${CACHE_DIR}/tunableop" "${CACHE_DIR}/miopen" "${CACHE_DIR}/triton" "${CACHE_DIR}/sycl" "${CACHE_DIR}/torchinductor" "${UNIT_DIR}" "${APP_DIR}" ) local d for d in "${dirs[@]}"; do mkdir -p "${d}" done } git_rev() { git -C "$1" rev-parse --short HEAD 2>/dev/null || echo unknown } write_manifest() { local dest=$1 shift { printf 'updated=%s\n' "$(date -Iseconds)" printf 'llama_src=%s\n' "$(git_rev "${LLAMA_SRC_DIR}")" printf '%s\n' "$@" } > "${dest}" } # --------------------------------------------------------------------------- # ComfyUI + venv # --------------------------------------------------------------------------- setup_venv_and_comfy() { local basedir=$1 cd "${basedir}" log "Creating Python ${PYTHON_VER} venv and cloning ComfyUI" uv venv --python "${PYTHON_VER}" venv # shellcheck source=/dev/null source venv/bin/activate git clone --quiet --no-tags --depth 1 https://github.com/comfyanonymous/ComfyUI comfy cd comfy } install_custom_nodes() { log "Installing ComfyUI custom nodes (parallel)" mkdir -p custom_nodes cd custom_nodes printf '%s\n' "${REPOS[@]}" | xargs -P "$(nproc)" -L 1 sh -c ' git clone --quiet --no-tags --depth 1 "$0" "$1" || { echo "FAIL $0" >&2; exit 1; } ' cd .. } update_pip_and_requirements() { log "Upgrading pip and installing requirements" uv pip install --upgrade pip wheel wheel_stub local -a req_args=("-r" "requirements.txt") local req_file while IFS= read -r -d '' req_file; do [[ -s "${req_file}" ]] && req_args+=("-r" "${req_file}") done < <(find custom_nodes -name "requirements.txt" -type f -print0) uv pip install --upgrade "${req_args[@]}" } setup_extra_model_paths() { log "Configuring extra_model_paths.yaml" local -a modeldirs=( audio_encoders background_removal checkpoints clip clip_vision configs controlnet detection diffusers diffusion_models embeddings frame_interpolation geometry_estimation gligen hypernetworks inpaint ipadapter latent_upscale_models loras model_patches optical_flow photomaker sams style_models text_encoders llm llm_aux llm_presets ultralytics unet upscale_models vae vae_approx ) { printf 'my_models:\n base_path: %s\n' "${BASEDIR}/models" local dir for dir in "${modeldirs[@]}"; do mkdir -p "${BASEDIR}/models/${dir}" printf ' %s: %s\n' "${dir}" "${dir}" done } > extra_model_paths.yaml } # --------------------------------------------------------------------------- # llama.cpp # --------------------------------------------------------------------------- ensure_llm_preset() { log "Writing LLM preset: ${LLM_PRESET_FILE_16GB}" cat > "${LLM_PRESET_FILE_16GB}" < "${LLM_PRESET_FILE_32GB}" < "${LLM_PRESET_FILE_SYSTEM_PROMPT_EN}" <<'PRESET_EOF' Role: Software engineer. Treat the user as a peer. No tutoring. Language: Everything in English, unless requested otherwise. Style: Direct, technically precise, concise. No pleasantries, flattery, or filler. Constraints: No emojis. Do not end responses with a question. Stay on task; no unsolicited expansions. Code and comments: Prefer simple, fast, compact, readable code. Do not overcomplicate. Comment only non-obvious logic. Python: Google Python Style Guide, Black, reST function docstrings. Bash 5+ on Linux only. Google Shell Style Guide, ShellCheck, shfmt. Use set -euo pipefail. No POSIX or cross-platform compatibility. PRESET_EOF log "Writing system prompt: ${LLM_PRESET_FILE_SYSTEM_PROMPT_FI}" cat > "${LLM_PRESET_FILE_SYSTEM_PROMPT_FI}" <<'PRESET_EOF' Role: Software engineer. Treat the user as a peer. No tutoring. Language: Base text in Finnish. No colloquial speak (sä, sun, sulla, mä, mun, mulla), do not address formally, use regular Finnish (sinä, sinun, sinulla, minä, minun, minulla). Style: Direct, technically precise, concise. No pleasantries, flattery, or filler. Constraints: No emojis. Do not end responses with a question. Stay on task; no unsolicited expansions. Code and comments in English. Prefer simple, fast, compact, readable code. Do not overcomplicate. Comment only non-obvious logic. Python: Google Python Style Guide, Black, reST function docstrings. Bash 5+ on Linux only. Google Shell Style Guide, ShellCheck, shfmt. Use set -euo pipefail. No POSIX or cross-platform compatibility. PRESET_EOF log "Writing system prompt: ${LLM_PRESET_FILE_ONETRAINER_APP}" cat > "${LLM_PRESET_FILE_ONETRAINER_APP}" <log.txt' Icon=${ONETRAINER_DIR}/resources/icons/icon.png Name=OneTrainer NoDisplay=false Path= PrefersNonDefaultGPU=false StartupNotify=true Terminal=false TerminalOptions= Type=Application X-KDE-SubstituteUID=false X-KDE-Username= PRESET_EOF } ensure_llama_src() { mkdir -p "$(dirname "${LLAMA_SRC_DIR}")" if [[ -d "${LLAMA_SRC_DIR}/.git" ]]; then log "Updating llama.cpp source" git -C "${LLAMA_SRC_DIR}" fetch --depth 1 origin git -C "${LLAMA_SRC_DIR}" reset --hard origin/HEAD else log "Cloning llama.cpp → ${LLAMA_SRC_DIR}" rm -rf "${LLAMA_SRC_DIR}" git clone --quiet --no-tags --depth 1 "${LLAMA_CPP_REPO}" "${LLAMA_SRC_DIR}" fi } setup_build_env() { if command -v ccache >/dev/null 2>&1; then export CMAKE_C_COMPILER_LAUNCHER=ccache export CMAKE_CXX_COMPILER_LAUNCHER=ccache export CCACHE_COMPILERCHECK=content log "ccache enabled" fi if command -v ninja >/dev/null 2>&1; then CMAKE_GENERATOR_ARGS=(-G Ninja) log "Ninja generator enabled" else CMAKE_GENERATOR_ARGS=() fi } install_llama_artifacts() { local build_bin=$1 dest=$2 mkdir -p "${dest}" cp -a "${build_bin}"/llama-* "${dest}/" if compgen -G "${build_bin}/*.so*" >/dev/null; then cp -a "${build_bin}"/*.so* "${dest}/" fi chmod +x "${dest}"/llama-* } build_llama_vulkan() { local dest_bin=$1 local build_dir="${LLAMA_SRC_DIR}/build-vulkan" ensure_llama_src setup_build_env log "Building llama.cpp (Vulkan)" cd "${LLAMA_SRC_DIR}" # llama.cpp master changes quickly. Never reuse a CMake/Ninja tree across # source revisions: stale backend objects/shared libraries can otherwise # leave the executable and libggml-* backends out of sync. ccache keeps # clean rebuilds reasonably fast. rm -rf "${build_dir}" cmake -S "${LLAMA_SRC_DIR}" -B "${build_dir}" \ "${CMAKE_GENERATOR_ARGS[@]}" \ -DGGML_VULKAN=ON \ -DCMAKE_BUILD_TYPE=Release cmake --build "${build_dir}" --config Release -j"$(nproc)" install_llama_artifacts "${build_dir}/bin" "${dest_bin}" } source_oneapi() { [[ -f "${ONEAPI_SETVARS}" ]] || die "oneAPI not found at ${ONEAPI_SETVARS}" set +u set -- # Always select updateai's private toolkit, even if another oneAPI was # sourced in the parent shell. SETVARS_ARGS avoids positional-argument # pollution while forcing setvars.sh to reinitialize the environment. SETVARS_ARGS="--force" source "${ONEAPI_SETVARS}" unset SETVARS_ARGS set -u command -v icpx >/dev/null 2>&1 || die "icpx not found after sourcing ${ONEAPI_SETVARS}" local icpx_path icpx_path="$(readlink -f "$(command -v icpx)")" [[ "${icpx_path}" == "${ONEAPI_DIR}/"* ]] || \ die "Unexpected oneAPI compiler: ${icpx_path}" } build_llama_sycl() ( local basedir=$1 local build_dir="${LLAMA_SRC_DIR}/build-sycl" log "Sourcing oneAPI environment" source_oneapi ensure_llama_src setup_build_env log "Building llama.cpp (SYCL + F16 + oneDNN graphs)" cd "${LLAMA_SRC_DIR}" # Do not reuse a CMake tree created with another oneAPI compiler/runtime. rm -rf "${build_dir}" cmake -S "${LLAMA_SRC_DIR}" -B "${build_dir}" \ "${CMAKE_GENERATOR_ARGS[@]}" \ -DGGML_SYCL=ON \ -DGGML_SYCL_F16=ON \ -DGGML_SYCL_DNN=ON \ -DGGML_SYCL_TARGET=INTEL \ -DGGML_SYCL_DEVICE_ARCH=bmg_g21 \ -DCMAKE_C_COMPILER=icx \ -DCMAKE_CXX_COMPILER=icpx \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG" \ -DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG" cmake --build "${build_dir}" --config Release -j"$(nproc)" install_llama_artifacts "${build_dir}/bin" "${basedir}/venv/bin" ) # --------------------------------------------------------------------------- # ROCm + Vulkan # --------------------------------------------------------------------------- create_comfy_rocm_service() { local basedir_rocm=$1 log "Writing comfy-rocm.service" cat > "${UNIT_DIR}/comfy-rocm.service" < "${UNIT_DIR}/llama-vulkan.service" </dev/null | awk '{print $2}' || true) if [[ "${installed}" == "${latest_pkgver}-"* ]]; then log "ROCm nightly ${latest_pkgver} already installed, skipping makepkg" return 0 fi log "Building ROCm nightly ${latest_pkgver}" local rocm_dir="${basedir_rocm}/rocm-nightly" mkdir -p "${rocm_dir}" cd "${rocm_dir}" cat > PKGBUILD </dev/null fi } install_torch_rocm() { log "Installing ROCm PyTorch stack (ROCm 10.x nightly, gfx1201)" uv pip install --upgrade --force-reinstall \ --extra-index-url "${ROCM_NIGHTLY_INDEX}" \ "torch[device-gfx1201]" "torchvision[device-gfx1201]" torchaudio \ triton apex \ filelock fsspec jinja2 markupsafe mpmath networkx numpy pillow \ setuptools sympy typing-extensions cxxfilt sageattention soundfile uv pip install "kornia>=0.7.0,<0.8.0" --no-deps --force-reinstall purge_cuda_pypi } smoke_rocm() { local basedir_rocm=$1 log "ROCm smoke test" # shellcheck source=/dev/null source "${basedir_rocm}/venv/bin/activate" export ROCM_PATH export HIP_PATH="${ROCM_PATH}" export HIP_PLATFORM=amd export PATH="${ROCM_PATH}/bin:${PATH}" export LD_LIBRARY_PATH="${ROCM_PATH}/lib:${basedir_rocm}/venv/lib:${LD_LIBRARY_PATH:-}" python - <<'PY' import torch print("torch", torch.__version__, "hip", getattr(torch.version, "hip", None)) if not torch.cuda.is_available(): raise SystemExit("ROCm HIP device not available") print("device", torch.cuda.get_device_name(0)) PY deactivate } setup_rocm() { local basedir_rocm="${BASEDIR}/rocm" stop_service comfy-rocm ensure_shared_dirs clean_base "${basedir_rocm}" setup_venv_and_comfy "${basedir_rocm}" create_comfy_rocm_service "${basedir_rocm}" install_custom_nodes update_pip_and_requirements install_rocm_nightly "${basedir_rocm}" cd "${basedir_rocm}/comfy" install_torch_rocm setup_extra_model_paths write_manifest "${basedir_rocm}/.updateai-manifest" \ "comfy=$(git_rev "${basedir_rocm}/comfy")" \ "torch=$(python -c 'import torch; print(torch.__version__)')" \ "rocm=$(pacman -Q rocm-nightly 2>/dev/null || echo missing)" deactivate smoke_rocm "${basedir_rocm}" enable_units comfy-rocm.service note "ROCm stack: ${basedir_rocm} comfy-rocm.service http://127.0.0.1:8189/ Restart: systemctl --user restart comfy-rocm" } smoke_vulkan() { local basedir_vk=$1 local -a env_args=( "VK_ICD_FILENAMES=${VULKAN_ICD}" "LD_LIBRARY_PATH=${basedir_vk}/bin:${LD_LIBRARY_PATH:-}" ) if [[ "${VULKAN_ICD}" == "${RADEON_ICD}" ]]; then env_args+=("RADV_PERFTEST=transfer_queue") fi log "Vulkan smoke test" [[ -x "${basedir_vk}/bin/llama-server" ]] || die "llama-server missing in ${basedir_vk}/bin" ( cd "${basedir_vk}" env "${env_args[@]}" "${basedir_vk}/bin/llama-server" --list-devices ) } setup_vulkan() { local basedir_vk="${VULKAN_DIR}" stop_service llama-vulkan ensure_shared_dirs #ensure_llm_preset clean_base "${basedir_vk}" mkdir -p "${basedir_vk}/bin" create_vulkan_service "${basedir_vk}" build_llama_vulkan "${basedir_vk}/bin" write_manifest "${basedir_vk}/.updateai-manifest" \ "llama_src=$(git_rev "${LLAMA_SRC_DIR}")" \ "icd=${VULKAN_ICD}" \ "preset=${VULKAN_PRESET}" smoke_vulkan "${basedir_vk}" enable_units llama-vulkan.service note "Vulkan stack: ${basedir_vk} llama-vulkan.service http://127.0.0.1:9932/ ICD ${VULKAN_ICD} Preset ${VULKAN_PRESET} B70: set VULKAN_ICD=${INTEL_ICD} and VULKAN_PRESET=${LLM_PRESET_FILE_32GB} Restart: systemctl --user restart llama-vulkan" } # --------------------------------------------------------------------------- # XPU + SYCL # --------------------------------------------------------------------------- # XPU/OpenCL isolation note (2026-10): # Intel oneDNN/SYCL still needs the Intel OpenCL ICD for some XPU primitives, # even when the selected XPU backend is Level Zero. Do not expose AMD ROCm or # Rusticl ICDs to XPU processes: loading ROCm LLVM/Clang and the system Intel # compiler stack into the same process caused duplicate LLVM analysis # registration (PointerFlowAnalysisResult) after the system LLVM 23 update. setup_xpu_opencl_icd() { log "Configuring Intel-only OpenCL ICD for XPU" [[ -f "${INTEL_OPENCL_ICD_FILE}" ]] || \ die "Intel OpenCL ICD file not found: ${INTEL_OPENCL_ICD_FILE}" rm -rf "${XPU_OPENCL_VENDOR_DIR}" mkdir -p "${XPU_OPENCL_VENDOR_DIR}" install -m 0644 "${INTEL_OPENCL_ICD_FILE}" \ "${XPU_OPENCL_VENDOR_DIR}/intel.icd" } purge_plain_triton_xpu() { if python - <<'PY' >/dev/null 2>&1 import importlib.metadata as m try: m.version("triton") except m.PackageNotFoundError: raise SystemExit(1) PY then log "Removing generic Triton before installing the XPU PyTorch stack" uv pip uninstall triton >/dev/null fi } create_comfy_xpu_service() { local basedir_xpu=$1 log "Writing comfy-xpu.service" cat > "${UNIT_DIR}/comfy-xpu.service" < "${UNIT_DIR}/llama-sycl.service" < XPU hijacking active") """) print("import_util.py: ipex hook added") else: print("import_util.py: ipex hook already present") tu = root / "modules/util/torch_util.py" kept = [] removed = 0 for line in tu.read_text().splitlines(keepends=True): if 'print ("true")' in line or 'print("true")' in line: removed += 1 continue kept.append(line) if removed: tu.write_text("".join(kept)) print(f"torch_util.py: removed {removed} debug print(s)") else: print("torch_util.py: no debug print") zluda = root / "modules/zluda/ZLUDA.py" ztext = zluda.read_text() new_fn = '''def is_zluda(device): try: if isinstance(device, str): if device.lower() == "cpu": return False if device.lower().startswith("cuda"): parts = device.split(":") device = int(parts[1]) if len(parts) > 1 else 0 return str(torch.cuda.get_device_name(device)).endswith("[ZLUDA]") except Exception: return False ''' ztext2, n = re.subn( r"def is_zluda\([\s\S]*?(?=\ndef |\Z)", new_fn + "\n", ztext, count=1, ) if n != 1: raise SystemExit(f"ZLUDA is_zluda replace count={n}") zluda.write_text(ztext2) print("ZLUDA.py: is_zluda patched") PY python -m py_compile \ "${ot}/scripts/util/import_util.py" \ "${ot}/modules/util/torch_util.py" \ "${ot}/modules/zluda/ZLUDA.py" } install_onetrainer_python() { local ot=$1 log "Creating OneTrainer Python ${PYTHON_VER} venv" rm -rf "${ot}/venv" onetrainer_uv venv "${ot}/venv" --python "${PYTHON_VER}" # shellcheck source=/dev/null source "${ot}/venv/bin/activate" log "Installing torch XPU nightly + ipex_to_cuda" onetrainer_uv pip install --pre torch torchvision torchaudio \ --index-url "${PYTORCH_XPU_INDEX}" onetrainer_uv pip install "git+https://github.com/Disty0/ipex_to_cuda.git" onetrainer_uv pip install \ "git+https://github.com/huggingface/diffusers.git@${ONETRAINER_DIFFUSERS_REF}" \ "git+https://github.com/Nerogar/mgds.git@${ONETRAINER_MGDS_REF}" \ "git+https://github.com/KellerJordan/Muon.git@${ONETRAINER_MUON_REF}" grep -vE '^\-e |^numpy==' "${ot}/requirements-global.txt" \ | onetrainer_uv pip install -r - onetrainer_uv pip install onnxruntime # Keep OneTrainer on the same Intel-only OpenCL view as ComfyUI XPU. # Without this, the system OpenCL loader can also load the ROCm ICD, which # brings a second LLVM/Clang runtime into the process and can trigger # duplicate PointerFlowAnalysisResult registration after LLVM 23 updates. export LD_LIBRARY_PATH="${ot}/venv/lib:${LD_LIBRARY_PATH:-}" export ONEAPI_DEVICE_SELECTOR=level_zero:0 export OCL_ICD_VENDORS="${XPU_OPENCL_VENDOR_DIR}" python - <<'PY' import torch import torch.nn.functional as F print(torch.__version__) print("xpu", torch.xpu.is_available(), torch.xpu.device_count()) if not torch.xpu.is_available(): raise SystemExit("XPU not available in OneTrainer venv") print("device", torch.xpu.get_device_name(0)) x = torch.randn((128, 512), device="xpu", dtype=torch.float16) w = torch.randn((512, 512), device="xpu", dtype=torch.float16) y = F.linear(x, w) torch.xpu.synchronize() print("linear", tuple(y.shape), y.dtype, "ok") PY deactivate } setup_onetrainer() { local ot="${ONETRAINER_DIR}" log "Installing OneTrainer XPU stack → ${ot}" ensure_shared_dirs sync_onetrainer_src "${ot}" patch_onetrainer_xpu "${ot}" install_onetrainer_python "${ot}" write_manifest "${ot}/.updateai-manifest" \ "onetrainer=$(git_rev "${ot}")" note "OneTrainer XPU: ${ot} Launch: source ${ot}/venv/bin/activate && python ${ot}/scripts/train_ui_qt.py Device: xpu Kept: ${ot}/training_concepts ${ot}/training_configs ${ot}/training_samples ${ot}/workspace ${ot}/workspace-cache" } # --------------------------------------------------------------------------- # Main # --------------------------------------------------------------------------- preflight_xpu_prereqs() { # oneAPI is intentionally managed outside updateai and preserved by # clean_xpu_base(). Check it before rebuilding the other stacks so a # missing toolkit fails fast instead of after ROCm/Vulkan have finished. [[ -f "${ONEAPI_SETVARS}" ]] || die "oneAPI not found at ${ONEAPI_SETVARS}. Reinstall the standalone oneAPI toolkit under ${ONEAPI_DIR} before running updateai." # ComfyUI XPU must see only Intel's OpenCL ICD. Loading AMD ROCm's ICD in # the same process can load a second LLVM/Clang runtime and trigger duplicate # compiler-analysis registration failures during oneDNN/SYCL execution. [[ -f /etc/OpenCL/vendors/intel.icd ]] || die "Intel OpenCL ICD not found at /etc/OpenCL/vendors/intel.icd" } main() { log "Starting updateai" ensure_uv ensure_shared_dirs preflight_xpu_prereqs setup_rocm setup_vulkan setup_xpu setup_onetrainer print_notes local elapsed=$((SECONDS - start_time)) if (( elapsed >= 60 )); then printf '\n=== READY (%d minutes %d seconds) ===\n\n' \ "$((elapsed / 60))" "$((elapsed % 60))" else printf '\n=== READY (%d seconds) ===\n\n' "${elapsed}" fi } main "$@"