-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy
More file actions
executable file
·31 lines (26 loc) · 1.13 KB
/
py
File metadata and controls
executable file
·31 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PY="$ROOT/.venv/bin/python"
if [[ ! -x "$PY" ]]; then
echo "Missing venv interpreter: $PY" >&2
echo "Create it with: python3 -m venv .venv && .venv/bin/pip install -U pip && .venv/bin/pip install -r requirements.txt" >&2
echo "If venv creation fails on Debian/Ubuntu, install: sudo apt-get install -y python3-venv" >&2
exit 1
fi
export XDG_CACHE_HOME="$ROOT/.cache"
export HF_HOME="$ROOT/.cache/huggingface"
mkdir -p "$XDG_CACHE_HOME" "$HF_HOME" 2>/dev/null || true
# Some systems export CUDA libs globally (e.g., /usr/local/cuda/lib64) which can
# shadow PyTorch's bundled CUDA dependencies and break imports. Prefer the
# venv's `nvidia/*/lib` directories when present.
shopt -s nullglob
NVIDIA_DIRS=("$ROOT"/.venv/lib/python*/site-packages/nvidia)
if (( ${#NVIDIA_DIRS[@]} )); then
NVIDIA_LIBS="$(find "${NVIDIA_DIRS[@]}" -maxdepth 2 -type d -name lib 2>/dev/null | sort | paste -sd: -)"
if [[ -n "$NVIDIA_LIBS" ]]; then
export LD_LIBRARY_PATH="$NVIDIA_LIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
fi
shopt -u nullglob
exec "$PY" "$@"