fix: use venv_t5_root() so .venv_t5 respects UNSLOTH_STUDIO_HOME

This commit is contained in:
Roland Tannous 2026-03-17 18:38:55 +00:00
commit 4e69c0e415
8 changed files with 83 additions and 12 deletions

View file

@ -49,9 +49,30 @@ def _activate_transformers_version(model_name: str) -> None:
resolved = _resolve_base_model(model_name)
if needs_transformers_5(resolved):
if not _ensure_venv_t5_exists():
raise RuntimeError(
f"Cannot activate transformers 5.x: .venv_t5 missing at {_VENV_T5_DIR}"
from utils.paths.storage_roots import venv_t5_root
venv_t5 = str(venv_t5_root())
if os.path.isdir(venv_t5):
sys.path.insert(0, venv_t5)
logger.info("Activated transformers 5.x from %s", venv_t5)
else:
# Fallback: pip install at runtime (slower, ~10-15s)
logger.warning(".venv_t5 not found at %s — installing at runtime", venv_t5)
import subprocess as sp
os.makedirs(venv_t5, exist_ok = True)
r1 = sp.run(
[
sys.executable,
"-m",
"pip",
"install",
"--target",
venv_t5,
"--no-deps",
"transformers==5.3.0",
],
stdout = sp.PIPE,
stderr = sp.STDOUT,
)
if _VENV_T5_DIR not in sys.path:
sys.path.insert(0, _VENV_T5_DIR)

View file

@ -51,9 +51,30 @@ def _activate_transformers_version(model_name: str) -> None:
resolved = _resolve_base_model(model_name)
if needs_transformers_5(resolved):
if not _ensure_venv_t5_exists():
raise RuntimeError(
f"Cannot activate transformers 5.x: .venv_t5 missing at {_VENV_T5_DIR}"
from utils.paths.storage_roots import venv_t5_root
venv_t5 = str(venv_t5_root())
if os.path.isdir(venv_t5):
sys.path.insert(0, venv_t5)
logger.info("Activated transformers 5.x from %s", venv_t5)
else:
# Fallback: pip install at runtime (slower, ~10-15s)
logger.warning(".venv_t5 not found at %s — installing at runtime", venv_t5)
import subprocess as sp
os.makedirs(venv_t5, exist_ok = True)
r1 = sp.run(
[
sys.executable,
"-m",
"pip",
"install",
"--target",
venv_t5,
"--no-deps",
"transformers==5.3.0",
],
stdout = sp.PIPE,
stderr = sp.STDOUT,
)
if _VENV_T5_DIR not in sys.path:
sys.path.insert(0, _VENV_T5_DIR)

View file

@ -45,9 +45,30 @@ def _activate_transformers_version(model_name: str) -> None:
resolved = _resolve_base_model(model_name)
if needs_transformers_5(resolved):
if not _ensure_venv_t5_exists():
raise RuntimeError(
f"Cannot activate transformers 5.x: .venv_t5 missing at {_VENV_T5_DIR}"
from utils.paths.storage_roots import venv_t5_root
venv_t5 = str(venv_t5_root())
if os.path.isdir(venv_t5):
sys.path.insert(0, venv_t5)
logger.info("Activated transformers 5.x from %s", venv_t5)
else:
# Fallback: pip install at runtime (slower, ~10-15s)
logger.warning(".venv_t5 not found at %s — installing at runtime", venv_t5)
import subprocess as sp
os.makedirs(venv_t5, exist_ok = True)
r1 = sp.run(
[
sys.executable,
"-m",
"pip",
"install",
"--target",
venv_t5,
"--no-deps",
"transformers==5.3.0",
],
stdout = sp.PIPE,
stderr = sp.STDOUT,
)
if _VENV_T5_DIR not in sys.path:
sys.path.insert(0, _VENV_T5_DIR)

View file

@ -427,7 +427,8 @@ _VLM_MODEL_TYPES = {
}
# Pre-computed .venv_t5 path and backend dir for subprocess version switching.
_VENV_T5_DIR = str(Path.home() / ".unsloth" / "studio" / ".venv_t5")
from utils.paths.storage_roots import venv_t5_root
_VENV_T5_DIR = str(venv_t5_root())
_BACKEND_DIR = str(Path(__file__).resolve().parent.parent.parent)
# Inline script executed in a subprocess with transformers 5.x activated.

View file

@ -8,6 +8,7 @@ Path utilities for model and dataset handling
from .path_utils import normalize_path, is_local_path, is_model_cached, get_cache_path
from .storage_roots import (
studio_root,
venv_t5_root,
assets_root,
datasets_root,
dataset_uploads_root,
@ -36,6 +37,7 @@ __all__ = [
"is_model_cached",
"get_cache_path",
"studio_root",
"venv_t5_root",
"assets_root",
"datasets_root",
"dataset_uploads_root",

View file

@ -15,6 +15,11 @@ def studio_root() -> Path:
return Path.home() / ".unsloth" / "studio"
def venv_t5_root() -> Path:
"""Pre-installed transformers 5.x directory, respects UNSLOTH_STUDIO_HOME."""
return studio_root() / ".venv_t5"
def cache_root() -> Path:
"""Central cache directory for all studio downloads (models, datasets, etc.)."""
return studio_root() / "cache"

View file

@ -62,7 +62,8 @@ TRANSFORMERS_5_VERSION = "5.3.0"
TRANSFORMERS_DEFAULT_VERSION = "4.57.6"
# Pre-installed directory for transformers 5.x — created by setup.sh / setup.ps1
_VENV_T5_DIR = str(Path.home() / ".unsloth" / "studio" / ".venv_t5")
from utils.paths.storage_roots import venv_t5_root
_VENV_T5_DIR = str(venv_t5_root())
def _resolve_base_model(model_name: str) -> str:

View file

@ -251,7 +251,6 @@ install_python_stack() {
python "$SCRIPT_DIR/install_python_stack.py"
}
<<<<<<< HEAD
# Create venv under ~/.unsloth/studio/ (shared location, not in repo).
# All platforms (including Colab) use the same isolated venv so that
# studio dependencies are never installed into the system Python.