Fix Colab dep install: relax == pins to >= to avoid breaking transformers

studio.txt pins huggingface-hub==0.36.2 and datasets==4.3.0 which
overwrite Colab's pre-installed versions and break its bundled
transformers (is_offline_mode was removed in newer huggingface-hub).

Relax == to >= in both colab.py and setup.sh Colab paths so pip keeps
existing compatible versions instead of force-upgrading.
This commit is contained in:
Daniel Han 2026-03-25 16:13:30 +00:00
commit 1c608e8ff7
2 changed files with 23 additions and 3 deletions

View file

@ -30,15 +30,32 @@ def _pip_install_backend_deps() -> None:
Used on Colab when the Studio venv does not exist (install.sh was not
run). Reads the requirements from studio.txt next to this file.
Strict ``==`` version pins are relaxed to ``>=`` so we do not clobber
Colab's pre-installed packages (e.g. huggingface-hub, datasets) with
versions that are incompatible with its bundled transformers.
"""
import re
import subprocess
req_file = Path(__file__).parent / "requirements" / "studio.txt"
if not req_file.exists():
return
packages = []
for line in req_file.read_text().splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
# Relax exact pins (==) to >= so pip keeps existing compatible versions
line = re.sub(r"==", ">=", line)
packages.append(line)
if not packages:
return
print("Installing Studio backend dependencies ...")
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "-q", "-r", str(req_file)],
[sys.executable, "-m", "pip", "install", "-q"] + packages,
)

View file

@ -295,9 +295,12 @@ VENV_T5_DIR="$STUDIO_HOME/.venv_t5"
_COLAB_NO_VENV=false
if [ ! -x "$VENV_DIR/bin/python" ]; then
if [ "$IS_COLAB" = true ]; then
# On Colab there is no Studio venv -- install backend deps into system Python
# On Colab there is no Studio venv -- install backend deps into system Python.
# Relax strict == pins to >= so we don't clobber Colab's pre-installed
# packages (huggingface-hub, datasets) with incompatible versions.
echo " Colab detected, installing Studio backend dependencies..."
pip install -q -r "$SCRIPT_DIR/backend/requirements/studio.txt" 2>/dev/null || true
sed 's/==/>=/' "$SCRIPT_DIR/backend/requirements/studio.txt" \
| pip install -q -r /dev/stdin 2>/dev/null || true
_COLAB_NO_VENV=true
else
echo "❌ ERROR: Virtual environment not found at $VENV_DIR"