diff --git a/setup-venv-local-build.sh b/setup-venv-local-build.sh index d86aa92..1c9f772 100755 --- a/setup-venv-local-build.sh +++ b/setup-venv-local-build.sh @@ -1,11 +1,33 @@ #!/usr/bin/env bash +# +# setup-venv-local-build.sh — builds ctranslate2 from source and installs faster-whisper. +# +# USE THIS SCRIPT when the PyPI ctranslate2 wheel does not match your CUDA version. +# The PyPI wheel targets a specific CUDA major version (e.g. CUDA 12). If your system +# has a newer version (e.g. CUDA 13), the wheel will fail at runtime because it tries +# to dlopen libcublas.so.12 which does not exist. Building from source compiles against +# your actual installed CUDA and links correctly. +# +# For systems where the PyPI wheel works (CUDA version matches), use setup-venv.sh +# instead — it is much faster and simpler. +# +# Environment overrides: +# PYTHON_ENV path to venv (default: ./venv) +# HF_TOKEN_FILE path to HuggingFace token file (default: ~/.secrets/hugging-face.token) +# HF_HUB_CACHE path to HuggingFace hub cache (default: ~/.cache/huggingface/hub) +# CUDA_HOME path to CUDA toolkit (auto-detected if not set) +# +# Arch Linux packages needed before running this script: +# sudo pacman -S cuda cmake git python +# (cuda is in the extra repo; if not found: yay -S cuda or check community/AUR) +# set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -VENV="${SCRIPT_DIR}/venv" +VENV="${PYTHON_ENV:-${SCRIPT_DIR}/venv}" BUILD_DIR="${SCRIPT_DIR}/build/ctranslate2" MODEL="${1:-base.en}" -TOKEN_FILE="${HOME}/.secrets/hugging-face.token" +TOKEN_FILE="${HF_TOKEN_FILE:-${HOME}/.secrets/hugging-face.token}" # Locate CUDA if [ -z "${CUDA_HOME:-}" ]; then @@ -18,14 +40,14 @@ if [ -z "${CUDA_HOME:-}" ]; then fi if [ -z "${CUDA_HOME:-}" ]; then - echo "ERROR: CUDA not found. Set CUDA_HOME manually." >&2 + echo "ERROR: CUDA not found. Set CUDA_HOME manually or install: sudo pacman -S cuda" >&2 exit 1 fi echo "==> CUDA: ${CUDA_HOME}" "${CUDA_HOME}/bin/nvcc" --version | head -1 -for tool in cmake git; do +for tool in cmake git python3; do if ! command -v "${tool}" &>/dev/null; then echo "ERROR: ${tool} not found — install with: sudo pacman -S ${tool}" >&2 exit 1 @@ -79,7 +101,8 @@ ls "${VENV}/lib/libctranslate2"* 2>/dev/null || { echo "ERROR: libctranslate2 no grep "WITH_CUDA" "${BUILD_DIR}/cmake-build/CMakeCache.txt" | grep -v "^#" || true # --- Python bindings --- -# Always reinstall from source to ensure we use our CUDA 13 build, not a PyPI wheel +# Always reinstall from source to ensure we use our locally built library, +# not a PyPI wheel that may have been pulled in as a dependency. echo "==> removing any existing ctranslate2 install..." "${VENV}/bin/pip" uninstall -y ctranslate2 2>/dev/null || true @@ -97,6 +120,7 @@ else echo "==> faster-whisper already installed, skipping" fi +# --- model download --- if [ -f "${TOKEN_FILE}" ]; then export HF_TOKEN="$(cat "${TOKEN_FILE}")" echo "==> HuggingFace token loaded from ${TOKEN_FILE}" @@ -104,6 +128,10 @@ else echo "==> no token found at ${TOKEN_FILE} — unauthenticated download" fi +if [ -n "${HF_HUB_CACHE:-}" ]; then + echo "==> HuggingFace cache: ${HF_HUB_CACHE}" +fi + echo "==> pre-downloading model: ${MODEL}" "${VENV}/bin/python3" - < done. Run with: node query-demo.mjs --stt faster-whisper" +echo "==> done. Venv ready at ${VENV}" diff --git a/setup-venv.sh b/setup-venv.sh new file mode 100755 index 0000000..b041654 --- /dev/null +++ b/setup-venv.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# setup-venv.sh — installs faster-whisper from PyPI into a venv. +# +# USE THIS SCRIPT when the PyPI ctranslate2 wheel matches your CUDA version. +# PyPI wheels target a specific CUDA major version; if your system matches, +# this is the fastest way to get started — no compilation required. +# +# If you see errors like "libcublas.so.12: cannot open shared object file" at +# runtime, your CUDA version does not match the wheel. Use setup-venv-local-build.sh +# instead, which compiles ctranslate2 against your actual CUDA installation. +# +# Environment overrides: +# PYTHON_ENV path to venv (default: ./venv) +# +# Arch Linux packages needed before running this script: +# sudo pacman -S python cuda +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +VENV="${PYTHON_ENV:-${SCRIPT_DIR}/venv}" + +if [ ! -d "${VENV}" ]; then + echo "==> creating venv at ${VENV}" + python3 -m venv "${VENV}" +fi + +echo "==> installing faster-whisper" +"${VENV}/bin/pip" install --upgrade pip --quiet +"${VENV}/bin/pip" install faster-whisper + +echo "" +echo "==> done. Venv ready at ${VENV}"